Compound References Commentary

General:. The example, 1000 => us.west.vol; us.west.vol * 1.98 =>us.west.ext$; is intuitive to Cobol programmers and maybe some accountants. Assign 1000 units to a bucket, multiply by $1.98 and save the extended amount in another bucket. Compiled languages set up these buckets at compile time and use of them is very rigid. In most other languages, such compound names are just names accepting the period (.) as a valid character for names. Glee doesn't view them that way. In Glee, everything down to the last "field" is a namespace. The last field is then any Glee object that can be stored in a namespace (i.e. virtually any Glee object.). Most programming languages require something like a data division or structure to define these compound names before you use them. Glee creates them on the fly as if they were simple variables. If you know how Glee creates and handles these compound references you have a powerful programming construct at your disposal.





Simple compound assignment: In Glee, a compound reference is one with mnemonic symbols separated by periods. In Glee's spirit, we must understand what is happening in a left to right fashion. First, a numeric object (10) is created. It is assigned (=>) to a variable (p.q). Since we began with a (#ns =>@) clearing the local namespace, (p) doesn't exist. Glee implicitly creates it as a reference (@) to the local namespace. Glee looking to the right notices a field (.q) follows the (p). It then decides what (q) should be. If (q) was followed by another field, it would create a namespace (q) in the referenced namespace (p@) and move on to the next field. In this example, there is no other field so it creates the object (q) in the referenced namespace (p@) as an association to the numeric object (10). This can all be neatly viewed by displaying, as a verbose string ([] %**) display of the most local namespace. Viewing the display we see a namespace with two associations. One is a reference to a namespace (p@). The other is a numeric object (q).




Multiple assignments to same namespace: This example expands on concepts from the first example. I clear the local namespace (#ns =>@). I assign two objects to (p.q): A string ('abc'=>str), and a numeric (1..5=>num). I then display the local namespace (%**). I see two objects: (p@[NS]:NS[2]), a reference to the anonymous local namespace containing two elements; and (q:NS[2]), a namespace containing two elements. Next, ((p.q ^@) %** $;) reveals (p.q) and displays it as a verbose string. Now, I create a reference (p.q@=>pq) which I use to address (p.q's) objects (str) and (num). Note: You can't assign a reference to (p.q) again without first deleting it with (@~.pq=>@) as described in the general discussion of references. However, you can use this reference as a shorthand in manipulating the (p.q) objects as shown in the next example (pq.num*10=>pq.num $;). You can treat these references just like other Glee variables as in the example (1000 => [3] pq.num; pq.num $;).




:




:




:




: