Next: , Previous: , Up: interfaces   [Contents][Index]


10.2 Defining interfaces

The following syntactic bindings are exported by the library (vicare language-extensions interfaces).

Syntax: define-interface-type ?name ?clause
Auxiliary Syntax: nongenerative
Auxiliary Syntax: parent
Auxiliary Syntax: implements
Auxiliary Syntax: method-prototype
Auxiliary Syntax: method

Define a new interface–type bound to the syntactic identifier ?name. The syntactic bindings nongenerative, parent, implements, method are the same ones exported by (vicare) and are reexported by the library (vicare language-extensions interfaces).

Interfaces cannot be instantiated: attempting to do it will raise an expand–time exception.

A use of the clause nongenerative must have one of the formats:

(nongenerative)
(nongenerative ?uid)

when used it causes the interface–type to be non–generative. This concept is the same as for record–types, so usually we do want to define non–generative interface–types.

A use of the clause parent must have the format:

(parent ?parent-name)

and causes the new interface–type to become a sub–type of ?parent-name, which must be a syntactic identifier representing the name of an already defined interface–type. An object–type implementing the interface ?name must also implement all the methods required by the interface ?parent-name.

A use of the clause implements must have format:

(implements ?iface-name ...)

and declares that an object–type implementing the interface–type ?name also implements all the methods in the interface–types ?iface-name. The definition of ?name must include a method-prototype clause for each method required by the interfaces ?iface-name, with matching type signatures.

A use of the clause method-prototype must have format:

(method-prototype ?method-name ?signature)

where ?method-name is an identifier representing the name of the method and ?signature is a lambda or case-lambda type annotation representing the type signature of the method. Any object–type that implements an interface, must implement all the methods with signatures that are sub–types of the method prototypes.

A use of the clause method must have format:

(method (?who . ?typed-formals)
  . ?body)

(method ((brace ?who . ?rv-types) . ?typed-formals)
  . ?body)

which is the same syntax for define-record-type. The clause method defines a required method prototype which also has a default implementation. An object–type implementing the interface ?name is allowed not to implement a method matching an interface prototype with default implementation.


Next: , Previous: , Up: interfaces   [Contents][Index]