Compound Variable Commentary

General:A compound variable is created in a very natural fashion as illustrated in the first example. But a compound variable is a pretty complicated object. Internally it is a Russian egg where each egg is a namespace. If you assign past the depth of the egg (as is always the case in initially forming a compound variable) a new egg (namespace) is automatically created and named. Initially this namespace may only contain a deeper namespace. But it may contain any Glee object as well.

A Compound Variable: This example creates an account compound variable. At the first level is the account number and the account name. The account name is further subdivided into current and previous name objects.

Using Compound Variables: You can use compound variables in a very natural way.

Using Aliases: Alias is an ugly word in most languages. But in Glee when using Compound Variables, it can save some typing and give programming flexibility for deeply nested objects. This example shows how you can create a variable at depth and use that "Compound Variable" to go to greater depth. What you are actually doing is addressing a namespace within the compound variable and assigning it to another variable (which is implicitly a compound variable as well). Later examples will show how this is an important method of using compound variables within blocks and controlling scope of its internal objects.

Referencing Inside of Blocks: Compound variables behave just as do other variables. In the first case, Glee is referencing the " x.c " CV outside the insulating (i.e. {{ ... }} )block. The CV, like any other variable is read only when not local (i.e. scope > 1). In the second case, the CV is being passed into the block as a reference argument. References passed as arguments become local variables. Changing the local copy changes the global referenced. Thus, the variable outside the block can be changed from inside the block. The mechanism Glee uses is as follows. Any attempt to assign to a variable in Glee is tested for scope. If local, the assignment takes place. When assignment is to references, the assignment is to the referenced object. If not local, creation takes place. This keeps Glee from changing objects outside the block which are actually references to other objects unless they are passed as arguments.

Modifying CVs from inside blocks: This example and the next one work together to illustrate some of the scoping of CVs when used with insulated blocks. A block becomes insulated by creating it with double braces (i.e. {{ code }} ). This is really a block within a block. To the outside block, caller objects are at scope 1 and can be changed. To the inner block we have a caller of a caller, which is at scope 2 and not changable from within the block. I set up a CV named acct and then reference it and attempt assignment from inside the insulated block. Once I attempt assignment to the CV from inside the block, I create a new CV inside the block. This kills my view of the CV outside the block from that point on.

Selective exposer of CV to block: Here using careful naming of my namespaces within the CV and then taking an alias, I am able to present a public portion (as reference) of the CV to the block and protect a private portion. But notice that I am able to not only assign to existing objects in the public portion, I am able to add to the public portion. Here I may have thought I was changing the password but I was just adding a password to the public section of the acct CV. The private section has its own version of password and it was not affected.