This is an old revision of the document!
~~DISCUSSION~~ <- CRPL reference <- Comparators
Arguments | Result | Notation |
---|---|---|
Two Values | true or false (1 or 0) | n1 n2 – n3 |
Top two items are popped from the stack and 'Equal' comparison is performed. 0 or 1 is pushed back to the stack where 1 indicates true.
When trying to do a comparison where one argument is a string and the other is an int, the string gets coerced into an int. If the string is something like “42” that coerces into 42. If it is “abc” that coerces into 0.
The 'eq' (and other comparators) look at both arguments and their intrinsic types. The rules are:
# Compares numbers to 100. # Pointless, in programming, but here to illustrate a point. 100 50 gt # True, 100 is greater than 50 45 50 gt # False, 45 is not greater than 50 50 50 gt # False, 50 is not greater than 50
Examples of comparing with unlike types
"string" ->string 0 ->zero 1 ->one Trace(<-string eq(<-one)) # returns 0/FALSE Trace(<-string eq(<-zero)) # returns 1/TRUE "1" ->OneAsString Trace(<-OneAsString eq(<-one)) # returns 1/TRUE Trace(<-OneAsString eq(<-zero)) # returns 0/FALSE