sigildocs

(sigil syntax)

Syntax object utilities for advanced macro authors

This module provides low-level operations for inspecting and manipulating syntax objects. These are primarily useful for writing procedural macros with syntax-case or for implementing macro systems.

For most macro authoring, syntax-rules and syntax-case (from (sigil core)) are sufficient. Use this module when you need fine-grained control over syntax object metadata, identifier comparison, or programmatic syntax construction.

Exports

syntax?procedure

Test if a value is a syntax object.

Syntax objects wrap datums with source location, lexical context, and hygiene information. Created by the reader (for source code) and by datum->syntax / make-syntax.

(syntax? #'foo)  ; => #t
(syntax? 'foo)   ; => #f
syntax-datumprocedure

Extract the datum from a syntax object.

Returns the underlying datum (symbol, list, etc.) without recursively unwrapping nested syntax objects. For deep unwrapping, use syntax->datum.

(syntax-datum #'foo)     ; => foo
(syntax-datum #'(a b))  ; => (#<syntax a> #<syntax b>)
syntax-srclocprocedure

Get the source location of a syntax object.

Returns a srcloc record if the syntax was read from source, or #f if it was constructed programmatically.

syntax-substsprocedure

Get the substitution environment of a syntax object.

Returns the list of lexical substitutions attached to the syntax object. Used internally by the expander for name resolution.

syntax->datumprocedure

Recursively strip all syntax wrappers from a syntax object.

Converts a syntax object and all nested syntax objects back to plain datums (symbols, lists, etc.).

(syntax->datum #'(+ 1 2))  ; => (+ 1 2)
make-syntaxprocedure

Create a syntax object from a datum and source location.

Wraps DATUM in a fresh syntax object with SRCLOC as its source location. The result has no lexical context—use datum->syntax with a template identifier to inherit context.

(make-syntax 'my-var #f)  ; syntax with no source location

Generate a list of fresh temporary identifiers.

Takes a list (or syntax wrapping a list) and returns a list of unique syntax-wrapped gensyms, one per element. Used in macros to create hygienic temporary bindings.

(generate-temporaries '(a b c))
; => (#<syntax tmp42> #<syntax tmp43> #<syntax tmp44>)

Look up the transformer bound to an identifier in the current expansion environment.

Returns the transformer value if id is bound to a macro at expansion time. If id is not bound to a transformer, invokes failure-thunk (if provided) or raises a runtime error.

Only meaningful when called from within a macro transformer during expansion. Use this to build macros that introspect other macros (e.g., macro dispatch tables, syntax-class lookup, metadata-style macro registration).

(define-syntax my-macro (syntax-rules () ((_) 'hello)))
(syntax-local-value #'my-macro)              ; => <transformer>
(syntax-local-value #'nope (lambda () 'fb))  ; => 'fb
(syntax-local-value #'nope)                  ; => error
identifier?variable

(No description)

syntax-marksvariable

(No description)

(No description)

(No description)

(No description)

(No description)