General:This frame introduces
you to simple booleans in Glee. I just quickly display the truth
tables here in vector form. Notice Glee's use of character
strings of 0's and 1's to represent boolean values. This is used primarily just
in experimenting. In real life, Glee gets its boolean values by
making logical tests. In the vector section I expound more on the subject of
booleans in Glee.
Boolean truth tables:This is
just a simple illustration of the boolean truth tables. The examples are
vector, not scalar. By now you realize there is really no such thing as a
scalar in Glee. The operators are (&)And; (|)Or;
(^)Exclusive or; and (~)Not. There are compound operators
(~&)Nand and (~|)Nor. These are the direct boolean
(logical) operators. In the vector section I cover the comparison operators
that create boolean data like (>)Greater than; (<=)Less than
or equal, etc.
Not/#True/#False:As described in
Glee simulates manifest constants as niladic functions.
#TRUE, and #FALSE are just such functions. Notice,
Glee is not case sensitive. You can use #True,
#true, or even #TruE just as freely. Because these are
niladic functions and not variables or constants, it is recommended that you
assign them to the name of your choice before use.
No No/Gotcha:If you do try to use
#true or #false as manifest constants, this is the kind of rude behavior
Glee exhibits. In detailed explanation, the first #true
indeed produces a boolean vector containing the binary digit
"1". Moving along to the right, the parser sees the
"&" and looks to it's right for another argument. It
sees a niladic function, #true. This cuts off the parsing and invokes
the executor. It tries to invoke the monadic operator
"&" on the left argument. This fails because
"&" is not defined for that operation.
vectors can be indexed just like other Glee vectors. Now, in this
example, I can't use the convenient character vector technique of defining the
bit vector being indexed. This is because, if I did, I'd just be indexing into
the character vector and getting a character result. So for these examples I
create the bit vectors through a testing operation (is a number equal to 1).
The first example illustrates simple selection indexing. The second, simple
element number indexing. The third illustrates indexing returning results for
index out of range. As with other Glee indexing, if on the low
side of the range, the first element is returned. On the high side, the last
element is returned. The fourth example illustrates indexing with floats. The
float value is floored to an integer and then used as the index.
logical tests) is the more likely way bit vectors are used. This example
illustrates creating a bit vector using relational tests. That bit vector is
then used to index into the numeric vector on which the tests were made.
Selection:In this example, I
show the Mark Any (*|) operator being used to mark a set of
account IDs of interest among a list of all account IDs.
There is a corresponding set of amounts(Amt) which are then selected
using the results of this test. Notice that the ID = 30 occurs twice.
This would be typical of a stream of transaction data.
Indices:. A common requirement
is to test values in a vector and return elements meeting the test. Sometimes
this requires finding the indices where the test is met and using them to
return elements from several vectors. This example illustrates some of
Glee's capability for serving this need:
<1a> creates a boolean vector and uses the ( ` ) index of operator monadically to produce the index where the test is first met. <1b> is the same but uses the ( `` ) indices of operator monadically producing all the indices where the test is met. <2> creates 5 random numbers ranging from 1 to 5 beginning with a seed of 100 (so you will see the same result as this example). <3> tests the elements of "n" to be greater than 2 returning a bit vector. <4> shows the indices where the test is met. <5> uses the indices to select elements of "n" meeting the test. And <6> shows that the bit vector can be used directly as an indexing object.