| ||
Tutorial: Transparency and Coercion (cont'd) |
Some non-object contextsThere are cases where the category of entity we want is not an object. In these cases, various syntactic "tails" are available to tell the language processing system that we want e.g. a pattern. Note that there is still transparency of the declared category of entity, since we are specifying what we want, not how we get it or what we have.Object reference wanted!When we want to obtain an object reference from a given entity, we must annotate the entity with the "box" suffix:
i[]->ir[] , ir refers to the object which
i (invariably) denotes.
Not executing
Note that the request for an object reference does not imply
that the object should be executed. Consequently, the
For example, assume that Pattern reference wanted!It is possible to compare the types of entities directly, and to do this we must be able to obtain a pattern reference from any entity, e.g. an object or an object reference. We also need to obtain a pattern reference in order to assign a new value to a pattern reference attribute. For these purposes we use the suffix:
if -imperative compares the type of
ro (it is the pattern from which the actual, run-time
object denoted by ro were originally instantiated) with
p as a pattern (implying the "empty" coercion),
and iff ro is actually an instance of a specialization of
p , the body ro[]->rp[] will be executed,
otherwise NONE->rp[] is executed, making rp
void. Afterwards, rp refers to the same object as
referred by ro iff that is a type-correct thing to do.
The second imperative, A super-pattern is a pattern context, tooSpecialization is expressed in its most basic form by a super-pattern and a main part. The super-pattern is the basis on which a new pattern is created, and the main part specifies the differences and additions. Whatever occurs in the position of a super-pattern will be coerced into a pattern. The following example contains a named and an anonymous pattern created with the aid of a super-pattern:
boolean(# .. #) contains
super-pattern syntax, boolean , and is itself
used as an imperative. As a consequence, there is both the coercion
(in this case a no-op) from pattern to pattern for
boolean , and the coercion from pattern to object
(instantiation), followed by execution, for the syntax
boolean(# .. #) .
Example 2
Here is an example which is ever so slightly less artificial (one does
rather easily get tired of The example looks like this:
Next, we'll present some more details about evaluations. |