| ||
Tutorial: Repetitions |
Repetitions are really not that interesting. They are just the concept in BETA which corresponds to arrays in other languages, defining several entities in one go in stead of just one. Nevertheless, repetitions are one of the very few topics where gbeta has been designed to do something which is not backward compatible with BETA. This is because I thought the semantics was messy in BETA.. The basic idea is that a repetition implies "repeated." Whatever you can do with a single item of any kind should have a "repeated" parallel when applied to a repetition. Assignments can be described in the following way. Assume the following declarations:
"->" ) gets adjusted to have the same length as the one
being evaluated. Secondly, assignments distribute over the elements,
i.e. assigning one repetition to another means assigning the first
element of the repetition to the first element of the second, then the
second etc. Thirdly, the object reference marker
"[]" distributes over the elements. Summing up we get
the following equivalences:
"rep1[2:2*b]" evaluates to a repetition
containing the elements from rep1 starting with
rep1[2] and ending with rep1[2*b] . Note that
there are some known bugs in repetition slice handling.
Unfortunately it is rather easy to provoke internal errors
(i.e. detection of internal inconsistencies) or outright run-time
errors in the interpreter with repetition slices, but this will be
fixed.
Example 11
As an example, the following defines a repetition of 10 character
objects, puts
"'****'->crefs" truncates crefs
such that its length becomes 4. This just means that we have
references to the first 4 elements of chars , and
chars is not itself affected by this length adjustment.
As usual, coercion ensures that the value assignment
The next topic is even more trivial, it's about explicit object instantiation. |