[plt-scheme] macro-generating macros and the bizarre properties of syntax-local-get-shadower
Dimitris Vyzovitis skrev:
> Can someone explain this:
> (module bar mzscheme
> (begin-for-syntax
> (define (make-foos)
> (let ((lst (generate-temporaries (list 'foo 'foocheck 'foov))))
> (printf "temps:~a~n" (map syntax-object->datum lst))
> lst)))
>
> (define-syntax (define-foo1 stx)
> (syntax-case stx ()
> ((_ val)
> (let-values (((foo foocheck foov) (apply values (make-foos))))
> (syntax-local-introduce
> #`(begin (define-syntax #,foo val)
> (define-syntax (#,foocheck stx)
> (let ((#,foov (syntax-local-value (quote-syntax #,foo))))
> (quasisyntax #,#,foov)))
> (provide #,foo #,foocheck)))))))
I got confused about all the unquote-syntax-es so there is a version
without. Note that I'm only introducing marks on the
generated indentifiers.
(module bar mzscheme
(begin-for-syntax
(define (make-foos)
(let ((lst (generate-temporaries (list 'foo 'foocheck 'foov))))
(printf "temps:~a~n" (map syntax-object->datum lst))
lst)))
(define-syntax (define-foo1 stx)
(syntax-case stx ()
((_ val)
(with-syntax (((foo foocheck foov)
(map syntax-local-introduce (make-foos))))
(syntax
(begin
(define-syntax foo val)
(define-syntax (foocheck stx)
(with-syntax ((foov (syntax-local-value
(quote-syntax foo))))
(quasisyntax foov)))
(provide foo foocheck)))))))
(define-foo1 2)
)
(require bar)
(foocheck2)
; evaluates to 2
--
Jens Axel Søgaard