@raviqqe
September 30, 2023
(define x 42) (define-syntax foo (syntax-rules ((foo) x)))
(let ((x 13)) (foo)) ; -> x, 42 but not 13
(define-syntax foo (syntax-rules ((foo x) ((lambda (y) x) 13))))
(define y 42) (foo y) ; -> ((lambda (y) y) 13), 42 but not 13
environment
(define-record-type expansion-context (make-expansion-context environment) expansion-context? (environment expansion-context-environment expansion-context-set-environment!))
; (define-syntax foo (syntax-rules ...)) (define transformer (make-transformer definition-context macro-transformer-definition)) (define new-environment (environment-push environment name transformer))
; (foo ...) (transformer use-context expression)
(define (fill-template definition-context use-context matches template) (cond ((symbol? template) (let ((pair (assv template matches))) (if pair (cdr pair) (let ( (name (rename-variable use-context template)) (denotation (resolve-denotation definition-context template))) (when (denotation? denotation) (expansion-context-set! use-context name (denotation-value denotation))) name)))) ; ...
syntax-rules
define-syntax
let-syntax
letrec-syntax
read
write
apply
cond-expand