Given that `classes' in Yazoo are no more than glorified data types, the way we define them shouldn't come as any great surprise:
my_class :: {
datum_1 :: ulong
datum_2 :: string
init_data :: {
code
{ datum_1, datum_2 } = { 1, "blank" }
}
process_data :: { ... }
}
Of course we haven't really introduced anything new here, except to include methods (functions) as valid members of a data type.
We don't yet have a constructor in quite the traditional sense of the word, but we can easily make one. As far as Yazoo is concerned a `constructor' is just any code that does not follow a code marker, and its capabilities are completely general. So it is straightforward to adapt our existing class to automatically initialize its variables.
my_class :: {
datum_1 :: ulong
datum_2 :: string
init_data :: { ... }
process_data :: { ... }
{ datum_1, datum_2 } = { 1, "blank" }
}
Now each instance of my_class that is defined like so:
obj1 :: my_class
will begin initialized to { 1, "blank" } . But Yazoo is flexible. We can write constructor code in anywhere we want, so a simpler alternative may be:
my_class :: {
(datum_1 :: ulong) = 1
datum_2 := "blank"
process_data :: { ... }
}
One apparent disadvantage of this constructor is that it seems not to be contained in any explicit function. Due to the oddities of Yazoo that is actually not true: we can re-initialize an instance of a class either by writing:
obj1#0() | code #0 is the constructor
or, equivalently, by just redefining the object:
obj1 :: obj1 | reruns constructor
There is no destructor in Yazoo. If you think about it, there isn't even a direct way to delete an object such as an instance of a class, a variable or a function. What is possible is to irrevocably cut that thing off from the user: by removing all members that point to it, clipping any transiting fibrils, and if necessary returning the program counter from its code. Only after all these things have happened will Yazoo quietly delete the orphaned object so as to free its memory. The conditions sound complicated, but under the most basic circumstances (no aliases, etc.) simply removing an object's member will delete it. As it turns out, recognizing orphans is not always so straightforward, and as a result Yazoo is rather worse at automatically collecting the garbage than it maybe should be. Readers interested in the disposal of unused memory are referred to SpringCleaning() in the reference section.
Last update: July 28, 2013