On this page:
symbolic-identifier=?
make-id
syntax-location-string
begin-for-syntax/ any-order
dotted-identifier?
simple-dotted-identifier?
dotted-identifier-count
dotted-identifier-split

28 Syntax utilities

 (require (planet untyped/unlib/syntax))
Utilities for creating macros and working with syntax.

(symbolic-identifier=? stx1 stx2)  boolean?
  stx1 : syntax?
  stx2 : syntax?
Compares two identifiers based on their symbolic representation.

(make-id stx arg ...)  syntax?
  stx : (U syntax? #f)
  arg : (U syntax? string? symbol? number?)
Creates an identifier by appending args. Equivalent to:

  (datum->syntax stx (string->symbol (apply string-append (map arg->string args))))
where arg->string converts an argument to a string.

(syntax-location-string stx)  string?
  stx : syntax?
Returns a string describing the source location of stx (for example "myfile.ss:123:45").

(begin-for-syntax/any-order definition ...)
 
definition = (define (id arg ...) expr ...)
  | (define id expr)
Like begin-for-syntax except that definitions can refer to previous definitions in the manner of a letrec statement. Only definitions are allowed within the body of the form.

(dotted-identifier? stx [min-parts max-parts])  boolean?
  stx : syntax?
  min-parts : (U natural? #f) = 2
  max-parts : (U natural? #f) = #f
Returns #f if stx represents an identifier comprised of one or more parts joined by dots. Parts can be zero-length.

The min-parts and max-parts arguments can be used limit the number of allowed parts (both limits are inclusive).

Examples:

  > (dotted-identifier? #'a)

  #f

  > (dotted-identifier? #'.a)

  #t

  > (dotted-identifier? #'a.b)

  #t

  > (dotted-identifier? #'a.)

  #t

  > (dotted-identifier? #'a.b.c 3 3)

  #t

  > (dotted-identifier? #'a 1)

  #t

(simple-dotted-identifier? stx    
  [min-parts    
  max-parts])  boolean?
  stx : syntax?
  min-parts : (U natural? #f) = 2
  max-parts : (U natural? #f) = #f
Like dotted-identifier? except all parts must be a minimum length of 1.

Examples:

  > (simple-dotted-identifier? #'a)

  #f

  > (simple-dotted-identifier? #'a.b)

  #t

  > (simple-dotted-identifier? #'.a)

  #f

  > (simple-dotted-identifier? #'a.)

  #f

(dotted-identifier-count dotted-id-stx)  natural?
  dotted-id-stx : identifier?
Returns the number of parts in dotted-id-stx.

Examples:

  > (dotted-identifier-count #'a)

  1

  > (dotted-identifier-count #'a.b)

  2

  > (dotted-identifier-count #'a.b.c)

  3

  > (dotted-identifier-count #'.a)

  2

(dotted-identifier-split dotted-id-stx)  (listof identifier?)
  dotted-id-stx : identifier?
Splits dotted-id-stx into its constituent parts.

Examples:

  > (map syntax->datum (dotted-identifier-split #'a))

  (a)

  > (map syntax->datum (dotted-identifier-split #'a.b))

  (a b)

  > (map syntax->datum (dotted-identifier-split #'a.b.c))

  (a b c)

  > (map syntax->datum (dotted-identifier-split #'.a))

  (|| a)