Commentary: Operators, Boolean (Logical)

General:Boolean (also called Logical) operators are used for marking elements. They are also used for testing marked elements. A marked element is true or 1; an unmarked element is false or 0. Most of these operations are very familiar. For these examples, I have used Glee's shorthand for boolean values. This is a character string containing just characters '1' and '0'. For example, the 4 character string (vector) "0101" is interpreted by the boolean operators as a bit vector with values (false,true,false,true). In writing Glee programs you will likely find no use for this style of boolean input. Your boolean values will originate by making tests. I included this facility in Glee so I could easily present examples and as a sculpting aid.





Logical operators:The logical operators AND (&), OR (|), NOT (~), NAND (~&), NOR (~), and XOR (^) assume boolean left arguments. All are dyadic except for NOT which is monadic. These examples give the truth tables for these operations. As in other cases, Glee does right takes on numeric arguments for length conformity and left takes for other objects. In Glee, boolean values are stored in characters, eight per character. This version of Glee does not take advantage of the computer's ability to operate on these bits directly. Glee actually indexes each bit to perform these operations. When I get Glee up, stable, and doing real work, I'll go back and optimize these boolean operators. There is a 100 times speed improvement potential there.




Mark All (*&):Mark where all the elements in the right argument are found in the left argument (in the order presented)




Mark Any (*|):Mark where any of the elements in the right argument are found in the left argument




Contains All (^&):True if left argument contains all of the right argument (in the order presented)




Contains Any (^|):True if left argument contains any of the right argument




Mark Contains All (*^&):Mark where elements in the left argument contain all the elements in the right argument (in the order presented) testing element by element. This operator is only meaningful for complex arguments like sequences where you want to do an element by element test (e.g. each string in a sequence). The same thing can be accomplished with ALeft @& ^& ARight < . However, this is less efficient since it first creates a sequence of bit singletons and then exposes it into a bit vector. The *^& operator returns the bit vector directly so runs faster and uses less space.




Mark Contains Any (*^|):Mark where elements in the left argument contain any of the elements in the right argument, testing element by element.This operator is only meaningful for complex arguments like sequences where you want to do an element by element test (e.g. each string in a sequence). The same thing can be accomplished with ALeft @& ^| ARight < . However, this is less efficient since it first creates a sequence of bit singletons and then exposes it into a bit vector. The *^| operator returns the bit vector directly so runs faster and uses less space.




Marking:The relational operators: Less Than (<); Less Than or Equal To (<=); Equal to(=); Not Equal to(~=); Greater Than or Equal To (>=); and Greater Than (>) perform comparisons of their arguments element by element and return the results of these tests as boolean vectors. As is characteristic of Glee, length conformity is forced with right take for numerics and left take for other objects. Caution: don't use (=>) as Equal To or Greater Than. This is Glee's assignment operator.




Not example:You might have noticed I deviated in the example style in the case of NOT. I would have liked to use the example ("01"~) remaining consistent with the other examples. However, the tilde symbol (~)denotes the without operation in non-boolean cases. In regard to character vectors, it removes redundant white space. So in this case, it would have just returned itself, "01". So I have performed a relational test (10 20=10) which gives me a boolean vector result ("10"). I then apply the NOT (~) operator to this result yielding ("01").




Greater Than or Equal To:Caution:You may be tempted to use the symbol (=>) for Equal To or Greater Than. Don't. That is the symbol for assignment in Glee.




Manifest constants: As I describe in the Glossary, Glee does not have manifest constants. However, it does have niladic functions #TRUE and #false (as with all Glee, case is not significant). These can be assigned to variables with names of your choice which then behave as manifest constants.




To Index and Indexing with: After you have completed boolean tests you usually want to do something with the result. Glee allows you to use the result directly as an index into a Glee vector. Or you can convert the bit vector to a vector of indices where bits are set. You can then use this for indexing. Boolean indexing is more efficient than numeric indexing.