6.3 Veneers
definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
When a value has a veneer’s static information—
A veneer affects only static resolution of operations. To help avoid confusing behavior when dynamic resolution is chosen in a dynamic-mode context, a veneer can be used as an expression or annotation only in a static-mode context (see use_static). Using a veneer annotation in a dynamic-mode context is a syntax error.
The veneer’s id_name is bound in several spaces:
in the expr space, a constructor function or form, which by default is a function that takes one argument and returns it, but with the static information of id_name;
in the annot space, an annotation that is satisfied by any value that satisfies the annot specified for this;
in the namespace space, a namespace to access exported bindings as well as a function id_name.method, a function id_name.property, and a syntactic form id_name.dot for each non-private/protected method, property, and dot syntax in the veneer (including inherited methods, properties, and dot syntax), respectively; and
in the class space, a representation of the veneer for reference as a superveneer.
When the annot declared for this is checked, the check occurs whenever the veneer is used as an annotation, by the default veneer constructor, when a method or property of the veneer is called. In the case of a method or property, the check applies when using . after an expression that has the veneer’s static information or when using a function like id_name.method. An annot can be a converter annotation only if the converter veneer clause is specified, in which case the veneer is also a converter annotation.
Analogous to class, the body of a veneer form consists of definitions, exports, and veneer clauses.
When a veneer_clause is an extends form, the new veneer is created as a subveneer of the extended veneer. If both the superveneer and subveneer have checked annots, then both checks apply for any use of the subveneer. If a superveneer’s annot is a converter annotation, then the converter veneer clause is implicit. In the case of a converter subveneer, the subveneer’s conversion applies before the superveneer’s conversion (or predicate). In the case of a predicate annotation subveneer, the superveneer’s predicate is tried first.
A veneer can implement only specific interfaces that serve as bridges to static dispatch: Indexable, MutableIndexable, Appendable, and Comparable. Note that is_a is a dynamic operation, not a static operation. So, for example, a value with a veneer that implements Indexable is not an instance in the sense of is_a (unless the underlying representation is an instance). Instead, having a veneer implement Indexable only makes static #%index references (usually written with […]) use the veneer’s get method. A veneer cannot implement Sequenceable, but it can implement static sequence conversion with sequence.
> p.x
10
> p[1]
20
> p.first
first: no such field or method (based on static information)
> block:
p.first
10
x: no such field or method (based on static information)
veneer clause | |
| |
| |
veneer clause | |
|
veneer clause | |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
veneer clause | |
| |
| |
veneer clause | |
| |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
veneer clause | |
| |
veneer clause | |
| |
| |
veneer clause | |
| |
veneer clause | |
| |
veneer clause | |
veneer clause | |||
| |||
veneer clause | |||
| |||
| |||
veneer clause | |||
| |||
| |||
veneer clause | |||