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>)
identifier?procedure

Test if value is an identifier

Re-exported from (sigil core)

syntax-marksprocedure

Get marks list from syntax object

Re-exported from (sigil core)

datum->syntaxprocedure

Create syntax with context from template

Re-exported from (sigil core)

Create syntax with updated metadata

Re-exported from (sigil core)

Test if binding would capture reference

Re-exported from (sigil core)

Test if identifiers resolve to same binding

Re-exported from (sigil core)