;; default input is '()
(define-syntax-parameter *input* (syntax-rules () ((_) '())))
(define-syntax aux
(syntax-rules ()
((_ body ...)
(let ((user-input (*input*)))
;; do what you need to do
body ...))))
(define-syntax foo
(syntax-rules (*input*)
((_ (*input* alist) body ...)
(syntax-parameterize ((*input* (syntax-rules () ((_) 'alist))))
(foo body ...)))
((_ body ...) (aux body ...))))
(foo (*input* ((a b) (c d))) 'ok)
;; *input* is '()
I would expect that in this case *input* should return ((a b) (c d)). And, indeed, Racket returns ((a b) (c d)) as I expected.The problem is simple. My implementation of
syntax-parameterize is expanded to letrec-syntax with bound keyword. However since the above case crosses macro boundaries, *input* always refers to globally bound identifier. Now, my question is; can it be implemented portable way? If I read "Keeping it Clean with Syntax Parameters", then it says it's implemented in a Racket specific way. (If I read it properly, then syntax parameter is really a parameter object which can work on macro.)Hmmm, I need to think how I can implement it.
No comments:
Post a Comment