On this page:
9.1 Untyped versions of ids

9 Generating identifiers

Suzanne Soy <racket@suzanne.soy>


(define-temp-ids maybe-concise simple-format base+ellipses
  maybe-first-base maybe-prefix)
base+ellipses = base
  | (base+ellipses ooo)
maybe-concise = 
  | #:concise
maybe-first-base = 
  | #:first-base first-base
maybe-prefix = 
  | #:prefix prefix
  simple-format : 
 (and/c string?
        (or/c (regexp-match/c #rx"^[^~]*~a[^~]*$")
              (regexp-match/c #rx"^[^~]*$"))))
  base : identifier?
  first-base : identifier?
  prefix : (or/c string? identifier?)
  ooo : (id/c ...)
Defines new-name as a syntax attribute, with the same nested structure as base. The new-name is obtained by applying the base to the given simple-format string. The generated syntax contains identifiers derived using the base and simple-format in the same way. Each of the generated identifiers is unique, in the sense that there are not two generated identifiers which are free-identifier=? to each other.

If the #:first-base option is specified, then new-first is also defined to be the first generated identifier in the whole tree. In other words, new-first will be bound to the same identifier as new-name if there are no ellipses, to the value of (stx-car new-name) if there is one level of ellipses, to the value of (stx-car (stx-car new-name)) if there are two levels, and so on. The identifier new-first is generated by applying first-base to the simple-format.

If the #:prefix option is specified, then the generated identifiers are prefixed with prefix, followed by a colon ":". This does not impact the new-name and new-first identifiers, so it can be useful when succinct identifiers are desired for the syntax attributes within the macro which uses define-temp-ids, but the generated identifiers should contain more context, to improve the readability of error messages which involve the generated temporary identifiers.

If the #:concise option is specified, then the generated identifiers are more concise, which makes them easier to read when debugging macros, but also means that two distinct identifiers can look the same (but have distinct scopes). If the #:concise option is omitted, the generated identifiers may contain extra characters do help visually disambiguate similar identifiers (those extra characters are obtained using generate-temporary).

Changed in version 1.1 of package phc-toolkit: The lexical context for the defined identifier new-name is now taken from the format, instead of being taken from the base name. Previously, the lexical context was taken from the base name, except when the simple format did not contain any "~a", in which case it was taken from the whole base+ellipses (this was a bug, which is fixed now that both cases use the lexical context of format). The same applies to the lexical context for new-first

9.1 Untyped versions of ids

 (require phc-toolkit/untyped/ids) package: phc-toolkit