Yazoo ---> Online Help Docs ---> Yazoo scripting

Sets

One of the more robotic aspects of programming languages is the top-down, hierarchical and bureaucratic way in which they like to organize their memories. Classes contain variables containing fields pointing to more variables, etc.: every item has a sort of postal address which needs to be spelt out in full whenever the user wants to communicate with it. Contrast this to the web-like memory of our brains, where information about some given thing can usually be accessed via any number of lateral associations between it and other memories. Human brains have a lot to teach us: the relational web is more versatile and often faster to navigate than the hierarchical tree.

The set in Yazoo exists partly to give the language a more natural memory structure. A set is a bag of objects that were defined elsewhere. Those objects can be variables, functions, classes, even data types and other sets. Defining a set doesn't affect those objects at all---they will still be in the same place as before, except that they can also be found, magically, by reaching into the bag. The syntax for defining a set basically the same as that for defining a composite type: we give a name, a `::' and curly braces enclosing the objects inside, as shown below. The difference is that those objects are only listed between commas (or end-of-lines); no define operator needs appear within the braces.


    Alice :: Bob :: Christine :: Daniel :: Elan :: friend_of_mine
   
    men :: { Daniel, Elan, Bob }
    neighbors :: { Christine, Bob }
    cleaning_schedule :: { Bob, Alice, Bob, Alice, Elan, Elan, Daniel }
   

After we have run the above code, Bob, men[3], neighbors[2], cleaning_schedule[1] and cleaning_schedule[3] are all the same thing. Notice how the same object can appear in several places in a set. In this case Bob is the shortest name, but sets really come into their own when the alternative path name is long and inconvenient.


    to_buy :: {
       food.produce.fruits.apples
       clothes.shoes.black
       clothes.socks.black
    }
   

Here to_buy[1] is definitely quicker than food.produce.fruits.apples.

Sets in Yazoo are pretty flexible. Along with variables, we can throw constants, other sets (including ones that we define on the fly), and even the void into the bag.


    collections :: { men, neighbors, { Patty, Don }, "Herbert", 3.3, this[3], this, nothing }
   

A few of these tricks require some explanation. The third item in collections is some nameless inlined set which can be thought of as a subset of collections. The fourth and fifth items are inlined constants. The sixth item is also the third item, that unnamed subset, and it obviously had to be listed after the third item because otherwise this[3] would not have existed yet. The seventh member of collections is the whole of collections itself.

To access the objects within any of these sets, we must use the square-bracket indexing operators (described in the section on arrays). The reason is that the set's members have no names, so if after our first example we were to request collection.men then Yazoo would draw a blank. As subsequent examples showed, it is not even clear how Yazoo could sensibly assign a unique name to each member. We actually can give names to the elements of a set ourselves, by manually aliasing the objects (for variables), or using define commands (for inlined composite objects) or define-equates (for inlined constants). Below is an alternative definition of collections which assigns names to members 2, 3, 4, 7 and 8.


    collections :: {
       men
       neighbors := @neighbors     | use same name for convenience
       parents :: { Patty, Don }
       Herby := "Herbert"
       3.3, this[3]
       self := @this
       zilch := @nothing
    }
   

With this more verbose second definition we can write collections.Herby in place of the more abstract collections[4] (although collections[4] is still perfectly legal).

Sets are not immutable. New items can be added to them and existing members can be removed, in the same way we can add or remove variables or members of composite types and variables. The following code rearranges the members of the last example so that "Herbert'' goes at the end.


    collections[9] := @collections.Herby
    remove collections.Herby
   

One last trick is also reminiscent of composite variables: we can use one set to define another. The following is legal:


    men :: { Daniel, Elan, Bob }
    males :: men
   

but, it can be simplified even further:


    males :: men :: { Daniel, Elan, Bob }
   


Prev: break   Next: Functions


Last update: July 28, 2013

Get Yazoo scripting language at SourceForge.net. Fast, secure and Free Open Source software downloads