(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?procedureTest 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) ; => #fsyntax-datumprocedureExtract 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-srclocprocedureGet 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-substsprocedureGet 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->datumprocedureRecursively 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-syntaxprocedureCreate 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 locationgenerate-temporariesprocedureGenerate 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>)identifier?procedureTest if value is an identifier
Re-exported from (sigil core)
syntax-marksprocedureGet marks list from syntax object
Re-exported from (sigil core)
datum->syntaxprocedureCreate syntax with context from template
Re-exported from (sigil core)
syntax-with-metadataprocedureCreate syntax with updated metadata
Re-exported from (sigil core)
bound-identifier=?procedureTest if binding would capture reference
Re-exported from (sigil core)
free-identifier=?procedureTest if identifiers resolve to same binding
Re-exported from (sigil core)