| ||
Tutorial: The Concept of a |
How it looksA main part is a piece of syntax, so you can just look it up in the grammar (the file gbeta-meta.gram in the distribution). Roughly, it looks like this:
<attributes> section is a list of declarations.
The enter-part, enter <evaluation> ,
specifies input properties, i.e. arguments accepted for assignment or
procedure call usage. The do-part, do
<imperatives> , is a list of imperatives (in
many languages imperatives are called "statements") which defines the
behavior associated with this main part. Finally, the
exit-part, exit <evaluation> , specifies the
output properties, i.e. values delivered when evaluating the main
part.
All the elements are optional, so the list of declarations may be empty, and any selection of the enter-, do-, and exit-parts may be absent. This means that the main part is both a light-weight construct when only few of the basic elements are present, and it is a very rich construct when everything is there.
Main parts are the building bricks used to construct substance in
gbeta programs. Either something is predefined (like the
basic pattern Related syntax in other languagesMain parts are related to declaration blocks in other languages, such as e.g. the brace-enclosed blocks used to derive a new class from an existing one in C++,
Main parts can do it all!Main parts are very versatile, supporting both the description of substance (attributes) and behavior (do-part), and specifying input/output properties (enter-/exit-parts), and this allows them to support the unification of classes, methods, co-routines, control structures, exceptions, and a lot more. Since input/output properties are specified inside the main part, there is no need to declare a name for a main part. With more traditional syntax, the grammar wouldn't easily allow the declaration of a nameless function, for example. This enables gbeta to support anonymous entities of many kinds, and they make a lot of things simpler, more convenient, and more concise. The trade-off is that it is a matter of convention how a given main part is used in a program. It may be constructed in such a way that usage as a method is the only reasonable one, and it may be designed specifically to support a class-like usage. In practice, however, it is rarely a problem to understand the intended use, and often the generality allows a natural and valuable usage which was nevertheless unforeseen. Example 1
The first example is a program which is similar to the
Declarations are associated with a colon and possibly some other characters, with the declared names to the left of the colon, and the value or type contraint to the right.
hello and print are declared as attributes,
and there is a do-part which uses these attributes.
The pattern
The pattern Finally, the imperative in the do-part,
print . As mentioned in the
"Getting Started" section, the arrow:
Think of it as an instruction to "extract a value"
from whatever is on the left hand side of the arrow, and an
instruction to impress a value upon whatever is on the right hand side
of the arrow. The value may be arbitrarily complex, expressed by
nested, parenthesized lists, and the recursive "take-over" semantics
which ensures that impressing a value upon Next, we'll look at different kinds of declarations. |