Instead of using the true: and false: messages, which will cause their actions to be executed when they are parsed, the user can specify true_actions and false_actions which would be appropriately executed when the logic instance is sent a do! or tick! message, not when they are parsed.
The tests work with both strings and numeric data. Any numeric argument can be a floating point number or a string. If a string is given, it must parse as a floating point number using C floating point syntax.
Note: When creating instances of the logic class, particularly in scripts, it is safest to enclose the names in quotes. Logics return their value when an instance is referenced, not the name of the instance.
true_actions[=+?] LYMB statement Sets, appends, or queries the true_actions. Useful for compiled logics.
false: LYMB statement If the value of logic is zero (i.e., false), execute the LYMB statement given.
false_actions[=+?] LYMB statement Sets, appends, or queries the false_actions. Useful for compiled logics.
compile_[on|off]! Forwards appropriate message to the true_actions and false_actions
assume_static_objects_[on|off]! Forwards appropriate message to the true_actions and false_actions
do! Executes either the true_actions or the false_actions depending on whether the value of logic is non-zero or zero, respectively.
tick! Synonym for "do!"
defined: object Set the value of logic to true is the named object exists.
responds_to: (object,msg) Set the value of logic to true if the named object responds to the given message.
subclass_of: (object,super) Set the value of logic to true if object is a subclass of super.
equal: (val1, val2) Set the value of logic to true if the parameter val1 equals the parameter val2. If both arguments are strings, they are compared as strings. If only one argument is a string, it is assumed to represent a number and the comparison is performed using the numeric value of both arguments. If both arguments are object pointers, they are compared as pointers.
less: (val1, val2) Set the value of logic to true if the parameter val1 is less than the parameter val2. Otherwise, the value of logic is set to false. If both arguments are strings, they are compared as strings, otherwise string arguments are assumed to represent numbers.
greater: (val1, val2) Set the value of logic to true if the parameter val1 is greater than the parameter val2. If both arguments are strings, they are compared as strings, otherwise string arguments are assumed to represent numbers.
or: (val1, val2, ..., valn) Set the value of logic to true if any of the n parameters val1, val2, or valn are true. String arguments are assumed to represent numbers.
and: (val1, val2) Set the value of logic to true if all of the n
parameters val1, val2, through valn are true. String arguments are assumed to represent numbers.
not! If the current value of logic is true, set it to false. If the current value of logic is false, set it to true.
lesseq: (val1, val2) Set the value of logic to true if the parameter val1 is less than or equal to the parameter val2. If both arguments are strings, they are compared as strings, otherwise string arguments are assumed to represent numbers.
nogreater: (val1, val2) Synonym for lesseq.
lessequal: (val1, val2) Synonym for lesseq.
greatereq: (val1, val2) Set the value of logic to true if the parameter val1 is greater than or equal to the parameter val2. If both arguments are strings, they are compared as strings, otherwise string arguments are assumed to represent numbers.
noless: (val1, val2) Synonym for greatereq.
greaterequal: (val1, val2) Synonym for greatereq.
notequal: (val1, val2) Set the value of logic to true if the parameter val1 is not equal to the parameter val2. If both arguments are strings, they are compared as strings. If only one argument is a string, it is assumed to represent a number and the comparison is performed using the numeric value of both arguments. If both arguments are object pointers, they are compared as pointers.
ordered: (val1, val2, val3) Set the value of logic to true if val1 is less than or equal to val2 and val2 is less than or equal to val3 If all arguments are strings, they are compared as strings.
null: ptr Set the value of logic to true if the parameter is a null data pointer.
scalar new: a; logic new: test; test defined: "a" true: "# a is defined" false: "# a is not defined" ;
Compare two numerical values. Make them equal if not equal.
scalar new: s1 = 5; scalar new: s2 = 7; logic new: test; test equal: (s1,s2) true: "#Both are equal" false: "s1 = s2;" ;
Compare two numerical values. Make them equal if not equal.
scalar new: s1 = 5; scalar new: s2 = 7; logic new: test; test
compile_on!
true_actions= "#Both are equal"
false_actions= "parser parse: `# not equal'; s1 = s2;"
equal: (s1,s2)
tick! ;
Compare two strings. Find the alphabetical order.
string new: s1 = "aardvark"; scalar new: s2 = "zebra"; s_vector new: ordered_strings; logic new: test; test nogreater: (s1,s2) true: "ordered_strings = (s1,s2);" false: "ordered_strings = (s2,s1);" ;