On this page:
class
class_  clause
interface_  clause
veneer_  clause
class_  clause.macro
class_  clause.macro
interface_  clause.macro
interface_  clause.macro
class_  and_  interface_  clause.macro
class_  and_  interface_  clause.macro
class_  and_  interface_  clause.macro
veneer_  clause.macro
veneer_  clause.macro
class_  meta.describe
interface_  meta.describe
veneer_  meta.describe
class_  meta.Info
class_  meta.Info
interface_  meta.Info
interface_  meta.Info
veneer_  meta.Info
veneer_  meta.Info
8.17.0.6

4.6 Class, Interface, and Veneer Clause Macros🔗ℹ

space

class

The space for class, interface, and veneer names as bound by class, interface, and veneer.

The spaces for bindings of identifiers that implement class, interface, and veneer clauses, respectively.

definition

class_clause.macro 'defined_name pattern ...':

  option; ...

  body

  ...

 

definition

class_clause.macro

| 'defined_name pattern ...':

    option; ...

    body

    ...

| ...

 

class clause

class_clause.macro macro_decl

 

option

 = 

~op_stx: id

 | 

~op_stx id

 | 

~all_stx: id

 | 

~all_stx id

 | 

~info: id

 | 

~info id

Like defn.macro, but defines a name in the class_clause space as a clause form for use within a class body. The class_clause.macro is itself bound as a class clause so that it will take effect within a class body for later forms, even if no other clause or declaration follows it.

The compile-time body block returns the expansion result. The result must be a sequence of groups to be spliced in place of the macro use, where each group can be either a another class clause, an expression, a definition, or an export.

In addition to ~op_stx and ~all_stx options like defn.macro, the optional ~info body form binds an id to a class_meta.Info value. Use the class_meta.Info.lookup function to access information about the class declaration that appears before the use of the class-clause macro.

> class_clause.macro 'lazy_method $id(): $(body :: Block)':

    'private field result: #false

     method $id():

       result || (block:

                    def v $body

                    result := v

                    v)'

> class Person(name):

    lazy_method greeting():

      "Hello, " +& name

> def ming = Person("Ming")

> ming.greeting()

"Hello, Ming"

> ming.greeting() === ming.greeting()

#true

definition

interface_clause.macro 'defined_name pattern ...':

  option; ...

  body

  ...

 

definition

interface_clause.macro

| 'defined_name pattern ...':

    option; ...

    body

    ...

| ...

 

interface clause

interface_clause.macro macro_decl

Like class_clause.macro, but for interface clauses and binding in the interface_clause space.

definition

class_and_interface_clause.macro 'defined_name

                                    pattern ...':

  option; ...

  body

  ...

 

definition

class_and_interface_clause.macro

| 'defined_name pattern ...':

    option; ...

    body

    ...

| ...

 

class clause

class_and_interface_clause.macro macro_decl

 

interface clause

class_and_interface_clause.macro macro_decl

Like class_clause.macro, but defines for use both in class clauses and interface clauses by binding in both the the class_clause and interface_clause spaces.

definition

veneer_clause.macro 'defined_name pattern ...':

  option; ...

  body

  ...

 

definition

veneer_clause.macro

| 'defined_name pattern ...':

    option; ...

    body

    ...

| ...

 

veneer clause

veneer_clause.macro macro_decl

Like class_clause.macro, but for veneer clauses and binding in the veneer_clause space.

Provided as meta.

Returns an object containing information about name, which must be bound as a class name or internal class name for class_meta.describe, as an interface name or internal interface name for interface_meta.describe, or as a veneer name for veneer_meta.describe. Use class_meta.Info.lookup, interface_meta.Info.lookup, or veneer_meta.Info.lookup to extract details from the information object.

annotation

class_meta.Info

 

method

method (info :: class_meta.Info).lookup(

  key :: Symbol

) :: Any

 

annotation

interface_meta.Info

 

method

method (info :: interface_meta.Info).lookup(

  key :: Symbol

) :: Any

 

annotation

veneer_meta.Info

 

method

method (info :: veneer_meta.Info).lookup(

  key :: Symbol

) :: Any

Provided as meta.

A value satisfying class_meta.Info can be obtained from class_meta.describe or received by a class-clause macro through an ~info declaration. Similarly, a value satisfying interface_meta.Info or veneer_meta.Info can be obtained by interface_meta.describe or veneer_meta.describe, or received by an interface- or veneer-clause macro through an ~info declaration. In a macro declared with class_and_interface_clause.macro, a value received by ~info is an instance of either class_meta.Info or interface_meta.Info, which indicates the context where the macro is used.

The class_meta.Info.lookup, interface_meta.Info.lookup, and veneer_meta.Info.lookup functions access information via a key symbol. The currently recognized keys are described below, but more may be added in the future.

When received within a class-, interface-, or veneer-clause macro, the information reported for a key covers only class, interface, or veneer clauses before the macro use, so a use of the same key in the same class but in a later clause may report different information. Furthermore, the information has not been fully checked; for example, the name of a class, interface, or veneer being extended is reported as it appears, and has not yet been checked to be a valid class, interface, or veneer name, and multiple names may be reported if a class contains multiple extends clauses. Similarly, field- or method-name lists may include duplicates.

When obtained via class_meta.describe, interface_meta.describe, or veneer_meta.describe, the information covers the whole body of the referenced class, interface, or veneer form. When a class or interface name is used, then information about private fields and methods is omitted from queries; using an internal name for a class or interface includes information about private fields and methods. A class- or interface-clause macro, which directly receives only partial information, can expand to a use of an expression macro that uses class_meta.describe or interface_meta.describe to get more information based on a retained or newly declared internal name.

Recognized keys for classes:

  • #'name: An identifier for the defined class, including any dotted-name prefix in the class declaration.

  • #'extends: A list of indentifiers for classes declared as superclasses. Normally, the list will be empty or have one element, but a multi-identifier list can be reported for a clause macro if a class form has multiple extends clauses (even though an error will be reported later).

  • #'implements: A list of indentifiers for interfaces declared to be implemented by the class. The list does not include interfaces that are implied by superclasses and implemented interfaces. For a clause macro or starting from class_meta.describe with a class internal name, the list includes privately implemented interfaces.

  • #'implements_visibilities: A list of symbols in parallel to a #'implements list that categorizes each implementation’s visibility: #'public or #'private.

  • #'internal_names: A list of identifiers declared as internal names for this class. This list will be non-empty only in the information provided to a clause macro.

  • #'field_names: A list of identifiers for fields declared for the class in the order of the field declarations. For a clause macro, the list does not include fields that will be inherited from a superclass, while inherited public fields are included in information obtained via class_meta.describe.

  • #'field_mutabilities: A list of symbols in parallel to a #'field_names list that categorizes each field’s mutability: #'immutable or #'immutable.

  • #'field_visibilities: A list of symbols in parallel to a #'field_names list that categorizes each field’s visibility: #'public or #'private.

  • #'field_constructives: A list of symbols in parallel to a #'field_names list that categorizes each field’s use in the default constructor: #'required, #'optional, or #'absent. All private fields are classified as #'absent.

  • #'field_keywords: A list of keywords and #falses in parallel to a #'field_names, where a keyword indicates that the field uses that keyword as an argument for the default constructor.

  • #'method_names: A list of identifiers for methods declared for the class in the order of the method declarations. The list does not include methods that will be inherited from a superclass or implemented interface, while inherited public methods are included in information obtained via class_meta.describe.

  • #'method_visibilities: A list of symbols in parallel to a #'methods_names list that categorizes each methods’s visibility: #'public or #'private.

  • #'method_arities: A list of arity representations in parallel to a #'methods_names list. An arity representation can be an integer, in which case each bit set in the integer represents a number of arguments accepted by the method, and no keyword argument are accepted. An arity representation can be a list, in which case the first element is an integer (like an integer by itself), the second element is a list of required keywords for arguments, and the last element is either a list of allowed keywords or #false if all keywords are accepted. An arity representation can be #false if no information about accepted arguments is available. Keep in mind that when a subclass overrides a method, it is not limited to the existing method’s arity.

  • #'property_names: A list of identifiers for properties declared for the class in the order of the property declarations. The list does not include properties that will be inherited from a superclass or implemented interface, while inherited public properties are included in information obtained via class_meta.describe.

  • #'property_visibilities: A list of symbols in parallel to a #'property_names list that categorizes each property’s visibility: #'public or #'private.

  • #'property_arities: A list of arity representations in parallel to a #'property_names list. An arity representation is 1 if the property does not support assignment, 3 if it does support assignment, or #false if the property’s support for assignments is unknown.

  • #'uses_default_constructor: A boolean indicating whether the class name in an expression position refers to a default constructor function.

  • #'uses_default_binding: A boolean indicating whether the class name in a binding position refers to a default binding form.

  • #'uses_default_annotation: A boolean indicating whether the class name in an annotation position refers to a default annotation form.

Recognized keys for interfaces:

  • #'name: An identifier for the interface being defined, including any dotted-name prefix in the interface declaration.

  • #'extends: A list of indentifiers for interfaces declared as superinterfaces. The list does not include interfaces that are implied by superinterfaces.

  • #'internal_names: The same as for classes.

  • #'method_names: The same as for classes.

  • #'method_arities: The same as for classes.

  • #'method_visibilities: The same as for classes.

  • #'property_names: The same as for classes.

  • #'property_arities: The same as for classes.

  • #'property_visibilities: The same as for classes.

  • #'uses_default_annotation: A boolean indicating whether the interface name in an annotation position refers to a default annotation form.

Recognized keys for veneers:

  • #'name: An identifier for the veneer being defined, including any dotted-name prefix in the veneer declaration.

  • #'extends: A list of indentifiers for veneers declared as superveneers. Normally, the list will be empty or have one element, but a multi-identifier list can be reported for a clause macro if a veneer form has multiple extends clauses (even though an error will be reported later).

  • #'internal_names: The same as for classes.

  • #'method_names: The same as for classes.

  • #'method_arities: The same as for classes.

  • #'method_visibilities: The same as for classes.

  • #'property_names: The same as for classes.

  • #'property_arities: The same as for classes.

  • #'property_visibilities: The same as for classes.