[plt-scheme] datum->syntax rules
The "_" in "(_ test then else)" is a special pattern that match's
anything. So the #'_ given to datum->syntax is not binding to "if-it".
This is a PLT v4 change. I think you want:
(define-syntax (if-it stx)
(syntax-case stx ()
((if-it test then else)
(with-syntax ((it
(datum->syntax #'if-it
'it)))
#'(let ((it test))
(if it then else)
)))))
Chongkai
YC wrote:
> Hi -
>
> are there specific rules that governs the choice of context to
> datum->syntax? I'm finding that the choices of the context impacts
> whether the name can be captured, and are not seeing what the issues
> are...
>
> Below are two versions of `if-it` - the first version works with #'_,
> but the second version cannot work with it (it works with #'test).
>
> Any pointers are appreciated, thanks.
> yc
>
> (define-syntax (if-it stx)
> (syntax-case stx ()
> ((_ test then else)
> (with-syntax ((it
> (datum->syntax #'_
> 'it)))
> #'(let ((it test))
> (if it test else))))))
>
> (if-it '(abc def) it 'nil) ;; works
>
> (define-syntax (if-it1 stx)
> (syntax-case stx ()
> ((_ test then else)
> (with-syntax ((it
> (datum->syntax #'_ ;; doesn't work... works if
> replaced with #'test
> 'it)))
> #'(let ((it test))
> (if it then else)
> )))))
>
> (if-it1 '(abc def) it 'nil) ;; => reference to undefined identifier: it
>
> ------------------------------------------------------------------------
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>