On this page:
explode-module-path-index
phase-of-enclosing-module
format-unique-id
syntax-within?
syntax-map
26.1 Syntax Object Source Locations
syntax-source-directory
syntax-source-file-name
Version: 5.3

26 Syntax

Ryan Culpepper <ryanc@racket-lang.org>

This library is unstable; compatibility will not be maintained. See Unstable: May Change Without Warning for more information.

 (require unstable/syntax)

Unfolds mpi using module-path-index-split, returning a list of the relative module paths together with the terminal resolved module path or #f for the “self” module.

Examples:

> (explode-module-path-index (car (identifier-binding #'lambda)))

'("kw.rkt" racket/private/pre-base #f)

> (explode-module-path-index (caddr (identifier-binding #'lambda)))

'(racket/base #f)

> (explode-module-path-index (car (identifier-binding #'define-values)))

'('#%kernel #f)

Returns the phase level of the module in which the form occurs (and for the instantiation of the module in which the form is executed). For example, if a module is required directly by the “main” module (or the top level), its phase level is 0. If a module is required for-syntax by the “main” module (or the top level), its phase level is 1.

Examples:

> (module helper racket
    (require unstable/syntax)
    (displayln (phase-of-enclosing-module)))
> (require 'helper)

0

> (require (for-meta 1 'helper))

1

The subsequent bindings were added by Vincent St-Amour <stamourv@racket-lang.org>.

procedure

(format-unique-id lctx    
  fmt    
  v ...    
  [#:source src    
  #:props props    
  #:cert cert])  identifier?
  lctx : (or/c syntax? #f)
  fmt : string?
  v : (or/c string? symbol? identifier? keyword? char? number?)
  src : (or/c syntax? #f) = #f
  props : (or/c syntax? #f) = #f
  cert : (or/c syntax? #f) = #f
Like format-id, but returned identifiers are guaranteed to be unique.

procedure

(syntax-within? a b)  boolean?

  a : syntax?
  b : syntax?
Returns true is syntax a is within syntax b in the source. Bounds are inclusive.

The subsequent bindings were added by Sam Tobin-Hochstadt <samth@racket-lang.org>.

procedure

(syntax-map f stxl ...)  (listof A)

  f : (-> syntax? A)
  stxl : syntax?
Performs (map f (syntax->list stxl) ...).

Example:

> (syntax-map syntax-e #'(a b c))

'(a b c)

The subsequent bindings were added by Carl Eastlund <cce@racket-lang.org>.

26.1 Syntax Object Source Locations

procedure

(syntax-source-directory stx)  (or/c path? #f)

  stx : syntax?

procedure

(syntax-source-file-name stx)  (or/c path? #f)

  stx : syntax?
These produce the directory and file name, respectively, of the path with which stx is associated, or #f if stx is not associated with a path.

Examples:

(define loc
  (list (build-path "/tmp" "dir" "somewhere.rkt")
        #f #f #f #f))
(define stx1 (datum->syntax #f 'somewhere loc))
> (syntax-source-directory stx1)

#<path:/tmp/dir/>

> (syntax-source-file-name stx1)

#<path:somewhere.rkt>

(define stx2 (datum->syntax #f 'nowhere #f))
> (syntax-source-directory stx2)

#f

> (syntax-source-directory stx2)

#f