On this page:
namespace
namespace.interleave
namespace_  meta.Exports
namespace_  meta.Exports
namespace_  meta.Exports
namespace_  meta.Exports
9.0

3.1 Namespace Macros🔗ℹ

The space for bindings of namespace names, such as the identifier immediate after the namespace definition form.

definition

namespace.interleave:

  option

  ...

  body

  ...

 

option

 = 

~is_clause expr

 | 

~is_clause: body; ...

 | 

~parse_clause expr

 | 

~parse_clause: body; ...

 | 

~complete expr

 | 

~complete: body; ...

 | 

~init 'term ...; ...'

 | 

~init: 'term ...; ...'

 | 

~name id_name

 | 

~name: id_name

 | 

~defer_tail

 | 

~no_exports

Intended as an expansion step for a macro that implements a new namespace-like form, where procedures provided via ~is_clause, ~parse_clause, and ~complete interpose on steps of expansion so that form-specific clauses can be interleaved with definitions and expressions—similar to the way class allows class clauses to be interleaved with definitions and expressions in its body. The namespace.interleave form does not necessarily define a namespace; a compile-time function provided by ~complete clause determines definitions, if any.

Each option keyword must appear at most once. The ~is_clause, ~parse_clause, ~complete, and ~init option forms are required.

  • ~is_clause: Followed by a compile-time expr or body sequence to produce a is_clause function satisfying

    (Group, Map.of(Symbol, Any)) -> Any.to_boolean

    The Group argument is a form among the overall body forms (or a partially expanded form of some body). The Map argument serves as additional arguments to is_clause, where the set of keys in the map can be extended in the future; the map is always empty.

    The is_clause function should return a true if value if the form should be passed to the ~parse_clause function for expansion, #false otherwise.

  • ~parse_clause: Followed by a compile-time expr or body sequence to produce a parse_clause function satisfying

    (Group, Syntax, Map.of(Symbol, Any)) -> values(Syntax, Syntax)

    The Group argument is one for which the is_parse function just produced a true value. The Syntax argument is the current state of expansion as initialized by the ~init form. The Map argument serves as additional arguments to is_clause, where the set of keys in the map can be extended in the future.

    The parse_clause function must return two values: a multi-group syntax object to splice in place of the clause to continue expansion, and a syntax object representing the new state of the expansion to be passed back to future calls to parse_clause or to the ~complete function.

    The Map argument maps two keys (but may be extended with new keys in the future):

    • #'close_expr: A function that accepts a Group for an expression and produces an opaque expression that preserves syntax parameters in effect for the current body form.

    • #'close_defn: A function that accepts a Syntax for a definition sequence and produces an opaque definition form that preserves syntax parameters in effect for the current body form.

  • ~complete: Followed by a compile-time expr or body sequence to produce a complete function satisfying

    (Syntax, Map.of(Symbol, Any)) -> Syntax

    The Syntax argument is the current state of expansion as initialized by the ~init form and updated by calls to parse_clause. The Map argument serves as additional arguments to complete, where the set of keys in the map can be extended in the future.

    The complete function must return a multi-group syntax object to splice after the namespace.interleave form in its enclosing context.

    The Map argument potentially maps the following keys (but may be extended with new keys in the future):

    • #'exports: An namespace_meta.Exports object that encapsulates export declarations among the expanded body forms. The object includes a namespace_meta.Exports.declaration method for generating a namespace declaration with the recorded exports. The #'exports key is not present if ~no_exports is present as a option.

    • #'tail: A multi-group syntax object holding body forms that follow the last body form that is a nestable declaration or a clause a recognized by is_clause. This key is present only when ~defer_tail is present as a option.

  • ~init: Followed by a quoted literal syntax object that represents the state of expansion. This value is updated by each parse_clause call and delivered in the end to complete.

  • ~defer_tail: Causes body expansion to stop at a point where only definitions and expressions remain. See ~complete for more information.

  • ~no_exports: Disallows the use of export (or, more generally, a nestable declaration) as a body form.

Provided as meta.

Encapsulates exports in the body of a namespace.interleave form. See ~complete in namespace.interleave for more information.

Provided as meta.

Returns an opaque namespace name definition with exports encapsulated by ex. Note that namespace_meta.Exports.add can add to the set of exports.

Provided as meta.

Reports information about the exports that are encapsulated by ex. The results for each method are parallel to results from the other methods; for example, the first element of the result of namespace_meta.Exports.include_spaces applies to the first identifier in the result of namespace_meta.Exports.external_names.

Each external name from namespace_meta.Exports.external_names corresponds to a distinct symbol.

Each result from namespace_meta.Exports.include_spaces describes which spaces are included by the export, where #'all means all spaces except as excluded in the corresponding list from namespace_meta.Exports.exclude_spaces.

Each result from namespace_meta.Exports.exclude_spaces describes which spaces are not included by the export when the corresponding result from namespace_meta.Exports.include_spaces is #'all.

method

method (ex :: namespace_meta.Exports).add(

  external_name :: Identifier,

  internal_name :: Identifier,

  include_spaces :: Any.of(#'all) || List.of(False || Symbol),

  exclude_spaces :: List.of(Symbol)

) :: namespace_meta.Exports

Provided as meta.

Returns an updated namespace_meta.Exports that extends the encapsulated exports with the supplied identifier.