On this page:
repet
repet_  meta.space
repet.macro
repet_  meta.pack_  list
repet_  meta.unpack_  list
8.12

7.12 Repetition Macros🔗ℹ

space

repet

The space for bindings of repetitions.

Provided as meta.

A compile-time value that identifies the same space as repet. See also SpaceMeta.

Like expr.macro, but defines an identifier or operator as a repetition form in the repet space. The result of the macro expansion can be a low-level binding description created with repet_meta.pack_list.

repet.macro 'nat3':

  ~op_stx self

  repet_meta.pack_list('($self, n, PairList[0, 1, 2], 1, 0, (), #true)')

> [nat3, ...]

[0, 1, 2]

Provided as meta.

Packs the implementation of a repetition form to serve as the result of expanding a repetition macro, where elements of the repetition are provided through a list.

The syntax object stx must have the following shape:

'(source_form,

  name_id,

  pair_list_expr,

  total_depth,

  use_depth,

  ((static_key, static_value), ...),

  is_immediate)'

The source_form group is used for error repoting to show the repetition, such as when the repeition is used at the wrong depth.

The name_id term is for error reporting and reflection in the sense that it is used as the inferred name for an element of the repetition, in case such a name is relevant.

The pair_list_expr expression produces a PairList that contains the elements of the repetition. Lists must be nested according to the repeition’s depth: a list of elements for depth 1, a list of element lists for depth 2, and so on.

The total_depth integer specifies the depth of the original repetition, while use_depth specifies how much of the original depth has already been extracted; that is, the difference total_depth minus use_depth indicates the depth of the list nesting that is produced by list_expr. A non-zero use_depth might be relevant to reporting the use of a repetition at the wrong depth in terms of the original form’s depth.

The static_keystatic_value pairs describe “upward” static information for inidvidual elements of the repeition. This information is automatically packed via statinfo_meta.pack.

The is_immediate component must be a literal boolean. A #true indicates that list_expr can be efficiently evaluated multiple times, while #false indicates that list_expr should be lifted out of enclosing repetitions to avoid evaluating it multiple times.

Provided as meta.

The inverse of repet_meta.pack_list, which is useful for unpacking information about the expansion of nested repetation forms.

repet.macro 'enum($from, $(sub :: repet_meta.Parsed))':

  ~op_stx self

  let '($_, $name, $expr, $depth, $use_depth, $_, $_)':

    repet_meta.unpack_list(sub)

  let (_, si):

    let '$(p :: annot_meta.Parsed)' = 'List'

    annot_meta.unpack_predicate(p)

  repet_meta.pack_list(

    '($self(),

      $name,

      for PairList (elem: $expr, i: $from ..): [i, elem],

      $depth,

      $use_depth,

      $si,

      #false)'

  )

> def [x, ...] = ["a", "b", "c"]

> [enum(1, x), ...]

[[1, "a"], [2, "b"], [3, "c"]]