On this page:
class
class_  clause
interface_  clause
class_  clause.macro
interface_  clause.macro
class_  and_  interface_  clause.macro
class_  meta.describe
interface_  meta.describe
class_  meta.Info
class_  meta.Info.lookup
interface_  meta.Info
interface_  meta.Info.lookup
8.12
7.13.6 Class and Interface Clause Macros🔗ℹ

space

class

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

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

definition

class_clause.macro 'defined_name pattern ...':

  option; ...

  body

  ...

 

definition

class_clause.macro

| 'defined_name pattern ...':

    option; ...

    body

    ...

| ...

 

option

 = 

~op_stx: 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 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 defintion, or an export.

In addition to an ~op_stx option 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

    ...

| ...

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

    ...

| ...

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.

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 or as an interface name or internal interface name for interface_meta.describe. Use class_meta.Info.lookup or interface_meta.Info.lookup to extract details from the information object.

annotation

class_meta.Info

 

function

fun class_meta.Info.lookup(

  info :: class_meta.Info,

  key :: Symbol

) :: Any

 

annotation

interface_meta.Info

 

function

fun interface_meta.Info.lookup(

  info :: interface_meta.Info,

  key :: Symbol

) :: Any

Provided as meta.

A value satisfying class_meta.Info can be obtained from class_meta.describe or recieved by a class-clause macro through an ~info declaration. Similarly, a value satisfying interface_meta.Info can be obtained by interface_meta.describe or recieved by a interface-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 . operator can be used on a class information expression as equivalent to calling class_meta.Info functions:

info.lookup(key)

 is 

class_meta.Info.lookup(info, key)

The . operator can be used on a interface information expression as equivalent to calling interface_meta.Info functions:

info.lookup(key)

 is 

interface_meta.Info.lookup(info, key)

The class_meta.Info.lookup and interface_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 receieved within a class-clause or interface-clause macro, the information reported for a key covers only class and interface 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 or interface being extended is reported as it appears, and has not yet been checked to be a valid class or interface 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 or interface_meta.describe, the information covers the whole body of the referenced class or interface 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 inteface-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.

Reocgnized keys for classes:

Reocgnized keys for interfaces: