Simple Numeric Indexing Comments

General:This frame introduces you to simple indexing principals in Glee.A general rule to remember regarding indexing: If the element does not exist, Glee. returns nil.





Simple Indexing: From the vector (10 20 30) the elements (4 3 2 1 0) are extracted in that order yielding (Nil 30 20 10 Nil). The 4th element and the 0th element don't exist so Nil results.




Insert Indexing: When you index with a fractional index, this tells Glee you want to insert elements into the result. The integer indices you already understand from the previous example. But decimal indices tell Glee to open a space for the value and use the value from the integer part of the index. In this example, 1.1 leaves a space in the result and fills it with the value at vector position 1. Notice there is nothing at vector position 0 or 4 or 4.1 so those indices yield Nil.

Here I also illustrate saving a value into a variable (10 20 30=>n). "=>" is the assignment operator in Glee. It is formed by the equal symbol ("=") followed with no intervening white space by the greater than (">") symbol (it does not mean "equal to or greater than"). The value to the left of the operator is saved in the namespace under the name to the right in the spirit of Glee's left to right operation. This is alien to virtually everyone, but is consistent to Glee's left to right parsing. I will use variables in this tutorial to break examples into steps.

I can then reference the variable (in this case "n") in the indexing operation as n[0 0.1 1 1.1 2 2.1 3 3.1 4 4.1] yielding Nil Nil 10 10 20 20 30 30 Nil Nil



Index Generation Operator:The "left single quote" ("`" is on the key with the "~" symbol and to the left of the "1 and ! " key on my keyboards) tells Glee to create an index vector. This is a numeric integer vector with the numbers 1 to n where n is the value preceeding the symbol. In this example "3`" produces the index vector 1 2 3. The "`" operator is called the index generator.




Indexing with index generator: This example creates the numbers from 1 to 7 ("7`"). It then takes that result and indexes it with the result of ("4`+2") which yields 3 4 5 6 as the index. Indexing into 1 2 3 4 5 6 7 with 3 4 5 6 yields 3 4 5 6.
Note: The parenthesis in the expression "(7`)" are not required. Working left to right there is no ambiguity related to what I have on the left. I include the parenthesis for readability here. It makes your eyes see 7` as an object being indexed.




Indexing with the range operator: The range operator ("..") is formed by two consecutive periods (".."). It is a more direct way to generate arbitrary index ranges.

The "$" in this example tells Glee to display intermediate results. In this case it displays (1 2 3 4 5 6 7). This is followed by the semicolon (";") which is Glee's instruction separator. If Glee finishes without seeing a semicolon, it displays the result of its last operation. However, if it does see a semicolon, it displays nothing. Using the "$" as a debugging aid allows us to see the contents of "n" for this example before we index into it.




Indexed Assignment: You can use indexed assignment to change the contents of variables. This example shows three statements.
Statement 1: (7` => n;) creates a variable n containing the integers 1 thru 7
Statement 2:( 44 33 99=>[4 3 9 2]n;) works like this. First, it does an implicit left take 4 (the length of the index vector 4 3 9 2) on the value vector (44 33 99). This yields 44 33 99 99 which it assigns to elements 4 3 9 2 of the object n. Since there is no element 9, the value at that respective position (33) is discarded. The result is 1 99 44 33 5 6 7. I expect you'll find the syntax a little unpleasant at first and favor ( 44 33 99=>n[4 3 9 2];). There's a problem with that. Left to right parsing would reassign the three element vector 44 33 99 to n. It would then index 44 33 99 at elements 4 3 9 2 giving Nil 99 Nil 33. This having no place to go as the result, would display. The contents of n get clobbered in the process. The syntax was a little funny to me at first too but I have no trouble with it now.
Statement 3: Giving a variable name as a lone statement not followed by a semicolon displays the contents of the variable. In this case we display the contents of the variable "n".

The indexed assignment proceeds from left to right through the indices and associated values. Thus, if an index value appears more than once, it is the last assignment that takes effect.

This example demonstrates an important characteristic of Glee. It trys to do the best it can with the materials it is given. The rules it uses are defined and logical. Most other programming languages would squawk at you and quit when things don't match up. I think they're being too finicky for human use, but of course with their style, they have to be.




Sneak preview of right and left take: In the previous example I said Glee does an implicit left take 4. Here we do an explicit right take 4 using the "->" right take operator in the statement ( 44 33 99 -> 4 ) yielding 44 44 33 99. Just for orientation, a left take would be (44 33 99 <- 4 ) and yields 44 33 99 99.




Boolean indexing (or selection):Here I begin to give you a taste of innate power of Glee. In one simple statement I mark all elements of n which are greater than or equal to ("*>=") 2 and less than ("*<") 6, and you knew what it did before I told you. But you probably didn't know the mechanism Glee used. It is called selection and it has to do with boolean objects (vectors of values of 1 and 0 or true and false called bits). In the space taken to store a single floating point number (like 1.1), Glee can store 64 bits of boolean (sometimes called logical) data. Within the index of operator ("[  ]") I perform three logical operations. I test for >=2; I test for < 6; and I logical and bit by bit("&") the results of the two tests. This gives me my boolean selection vector ("0111100"). I display this using the "$" debugging display operator. If I use a boolean as an index, I get a value from the indexed object everywhere there is a 1 or true. I don't get a value where there is a 0 or false. As we will see later, this capability is very powerful for performing numeric analysis. It is also powerful in string search and compare operations.
Note: You may be tempted to say equal to or greater than and use the => operator for this logical operation. Don't!!! That is assignment!



Literal Boolean Indexing: Glee has a special facility for entering literal boolean values to be used in indexing. A string containing only 1's and 0's is taken as a bit vector when supplied as in index. Glee selects the element corresponding to each 1 and discards the element corresponding to each 0. When the index implied is outside the range of elements, Nil is returned.




Empty index:
As with all Glee objects, presenting an empty index causes Glee to return a copy of the object's contents. In this case, 1 2 3.



:




: