On this page:
repet
repet_  meta.space
repet.macro
repet_  meta.pack_  generator
repet_  meta.unpack_  generator
repet_  meta.pack_  list
repet_  meta.unpack_  list
repet_  meta.Parsed
repet_  meta.After  Prefix  Parsed
repet_  meta.After  Infix  Parsed
repet_  meta.Name  Start
repet_  meta.parse_  dot
8.15.0.12

17.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, [0, 1, 2], 1, 0, ())')

> [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 the repetition is described in terms of for clauses and a body.

The syntax object stx must have the following shape:

'(

   source_form,

   ((((id, ...), seq_expr),

     ...),

    ...),

   body_expr,

   use_depth,

   ((static_key, static_value), ...)

 )'

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

Each (id, ...) sequence names values of elements drawn from the corresponding seq_expr. Each inner sequence of seq_exprs corresponds to sequences traversed in parallel, while the outermost sequence corresponds to sets of sequences that are nested. The length of the outermost sequence determines the depth of the repetition.

The body_expr expression produces elements of the repetition, usually referring to the ids that are bound to input sequence elements, and only the ids that are in the last parallel group.

The use_depth integer specifies how much additional depth has already been extracted from an original repetition; 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 individual elements of the repetition. This information is automatically packed via statinfo_meta.pack.

Provided as meta.

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

Any repetition can be unpacked both this way and by using repet_meta.unpack_list, but the output repet_meta.unpack_generator is more flexible for most purposes.

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

  ~all_stx stx

  let '($_, ($binds, ..., ($inner_bind, ...)), $body, $use_depth, $_)':

    repet_meta.unpack_generator(sub)

  let (_, si):

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

    annot_meta.unpack_predicate(p)

  repet_meta.pack_generator(

    '($stx,

      ($binds, ..., ($inner_bind, ..., ((i), $from ..))),

      [i, $body],

      $use_depth,

      $si)'

  )

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

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

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

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. See repet_meta.pack_generator for an alternative representation.

The syntax object stx must have the following shape:

'(

   source_form,

   list_expr,

   depth,

   use_depth,

   ((static_key, static_value), ...)

 )'

The source_form group is used for error reporting to show the repetition, such as when the repetition 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 list_expr expression produces a List that contains the elements of the repetition. Lists must be nested according to the repetition’s depth: a list of elements for depth 1, a list of element lists for depth 2, and so on.

The depth integer specifies the depth of the repetition. The use_depth specifies how much additional depth has already been extracted from an original repetition; 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 individual elements of the repetition. This information is automatically packed via statinfo_meta.pack.

Provided as meta.

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

Any repetition can be unpacked both this way and by using repet_meta.unpack_generator. The result of repet_meta.unpack_list can be convenient, but its use can be less efficient if a refied list is simply fed into another for-like traversal.

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

  ~all_stx stx

  let '($_, $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(

    '($stx,

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

      $depth,

      $use_depth,

      $si)'

  )

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

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

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

syntax class

syntax_class repet_meta.Parsed:

  kind: ~group

  fields:

    group

 

syntax class

syntax_class repet_meta.AfterPrefixParsed(op_name):

  kind: ~group

  fields:

    group

    [tail, ...]

 

syntax class

syntax_class repet_meta.AfterInfixParsed(op_name):

  kind: ~group

  fields:

    group

    [tail, ...]

 

syntax class

syntax_class repet_meta.NameStart:

  kind: ~group

  fields:

    name

    [head, ...]

    [tail, ...]

Provided as meta.

Analogous to expr_meta.Parsed, etc., but for repetition forms.

function

fun repet_meta.parse_dot(left :: Syntax, op_and_tail :: Group,

                         ~as_static: as_static = #false,

                         ~disable_generic: disable_generic = #false)

  :: (maybe(Syntax), maybe(Syntax))

Provided as meta.

Analogous to expr_meta.parse_dot, but for repetitions.

To select a specific dot provider, use repet_meta.unpack_list plus repet_meta.pack_list to adjust the static information of left, where statinfo_meta.dot_provider_key is the relevant static-information key.