On this page:
entry_  point
entry_  point.macro
entry_  point_  meta.Adjustment
entry_  point_  meta.pack
entry_  point_  meta.Parsed
entry_  point_  meta.Arity
8.12
7.13.10 Entry Point Macros🔗ℹ

The space for bindings of identifiers that can be used in entry point positions, such as within method.

definition

entry_point.macro prefix_macro_patterns

 

option

 = 

~op_stx: id

 | 

~op_stx id

 | 

~mode: mode_id

 | 

~mode mode_id

 | 

~adjustment: adj_id

 | 

~adjustment adj_id

Like defn.macro, but defines an identifier as an entry point form in the entry_point space. Also, in addition to the ~op_stx option, the ~mode and/or ~adjustment “options” can be specified—and they are effectively required to detect the mode mode of expansion and receive potential adjustments to the expansion.

An entry-point macro works in two modes, where the symbol provided as mode_id indicates the mode:

The result of expansion in #'arity mode must be either #false, an integer, or a list of three elements. A #false means that the arity is not statically known. An integer value is an arity mask; for every bit set in the mask, the function can receives that many by-position arguments. A list value starts with an arity for by-position arguments, but also has a list of keywords that are allowed and a list of keywords that are required; the list of allowed keywords can be #false to indicate athat any keyword is allowed. The context of an entry point may constrain the acceptable arities or use arity information for a more efficient expansion.

When the rule of expansion in #'function mode is packed via entry_point_meta.pack, the generated function shuld accept extra initial by-position arguments as listed in entry_point_meta.Adjustment.prefix_arguments(adj_id), and each result body (where the function may have multiple bodies in multiple cases) should be wrapped with entry_point_meta.Adjustment.wrap_body(adj_id). The wrapping function expects an arity encoding that is like the result for #'arity mode expansion, but specific to the body’s case within a multi-case function.

entry_point.macro 'identity':

  ~mode mode

  ~adjustment adj

  match mode

  | #'arity:

      [2, [], []]

  | #'function:

      let [arg, ...] = adj.prefix_arguments

      entry_point_meta.pack(

        'fun ($arg, ..., x):

           $(adj.wrap_body(2, 'x'))'

      )

> class C():

    method m: identity

> C().m("ok")

"ok"

class

class entry_point_meta.Adjustment(

  prefix_arguments :: Listable.to_list && List.of(Identifier),

  wrap_body :: Function.of_arity(2),

  is_method :: Boolean

)

Provided as meta.

Represents an adjustment to an entry point to add extra arguments and wrap the generated function’s body. The wrap_body function expects an arity encoding (see entry_point.macro) and a syntax object, and it produces a syntax object. The is_method field indicates whether the existence of a leading argument should be hidden in error messages.

Provided as meta.

Packs an expression for a function as a result for a entry_point.macro expansion, distinguishing it from an unpacked syntax objects that represents expansion to another entry point form.

syntax class

syntax_class entry_point_meta.Parsed(adj):

  kind: ~group

  fields:

    group

 

syntax class

syntax_class entry_point_meta.Arity:

  kind: ~group

  fields:

    group

Provided as meta.

Analogous to expr_meta.Parsed, but for entry points to run in either #'function mode with entry_point_meta.Parsed or #'arity mode via entry_point_meta.Arity.