On this page:
veneer
extends
implements
converter
final
method
property
override
private
expression
8.12

6.9 Veneers🔗ℹ

definition

veneer id_name(this_decl)

 

definition

veneer id_name(this_decl):

  veneer_clause_or_body_or_export

  ...

 

this_decl

 = 

this :: annot

 | 

this :~ annot

 

veneer_clause_or_body_or_export

 = 

veneer_clause

 | 

body

 | 

export

 

veneer_clause

 = 

method method_impl

 | 

override method_impl

 | 

final method_impl

 | 

private method_impl

 | 

property property_impl

 | 

extends id_name

 | 

implements implements_decl

 | 

private implements implements_decl

 | 

expression expression_decl

 | 

dot dot_decl

 | 

static_info static_info_decl

 | 

converter

 | 

other_veneer_clause

Similar to class, but binds id_name as a static class veneer over an existing representation, instead of creating a new representation like class does. The existing reprsentation is indicated by the annot written after the this pseudo-field (in parentheses after id_name); this representation is checked only when using ::, and not when using :~.

When a value has a veneer’s static information—typically because the veneer name is used as an annotationthen static lookup of methods, indexing operations, etc., use the veneer instead of the underlying representation. Within the veneer body, however, this has the static information of annot.

The veneer’s id_name is bound in several spaces:

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.

use_static

veneer Posn(this :: Pair):

  property x:

    this.first

  property y:

    this.rest

  private implements Indexable

  private override get(i):

    match i

    | 0: x

    | 1: y

  expression 'Posn($x, $y)':

    'Pair($x, $y) :~ Posn'

> def p = Posn(10, 20)

> p.x

10

> p[1]

20

> p.first

first: no such field or method (based on static information)

> block:

    use_dynamic

    p.first

10

> dynamic(p).x

x: no such field or method (based on static information)

veneer clause

extends id_name

 

veneer clause

extends: id_name

A veneer clause recognized by veneer to define a veneer that is a subveneer of the one named by id_name. See veneer.

veneer clause

implements id_name ...

 

veneer clause

implements: id_name ...; ...

A veneer clause recognized by veneer to define a class that implements subclasses named by id_names. See veneer.

veneer clause

converter

A veneer clause that is recognized by veneer so that the new veneer is a converter annotation. See veneer.

veneer clause

final method_impl

 

veneer clause

final method method_impl

 

veneer clause

final override method_impl

 

veneer clause

final override method method_impl

 

veneer clause

final property property_impl

 

veneer clause

final override property property_impl

Like final, but as a veneer clause to be followed by a method or property declaration. In that case, the method or property is final, and a final method or property cannot be overridden in subveneers.

veneer clause

method method_impl

 

veneer clause

property property_impl

 

veneer clause

override method_impl

 

veneer clause

override method method_impl

 

veneer clause

override property property_impl

Like method and other class clauses, but as veneer clauses. See veneer.

veneer clause

private implements id_name ...

 

veneer clause

private implements: id_name ...; ...

 

veneer clause

private method_impl

 

veneer clause

private method method_impl

 

veneer clause

private property property_impl

 

veneer clause

private override method_impl

 

veneer clause

private override method method_impl

 

veneer clause

private override property property_impl

Like private as a class clause, but as a veneer clause. See veneer.

veneer clause

expression: entry_point

 

veneer clause

expression 'id pattern ...': 'template ...'

 

veneer clause

expression

| 'id pattern ...': 'template ...'

| ...

A veneer clauses as recognized by veneer to replace the default expression form, analogous to expression for class.