[plt-scheme] datum->syntax rules
You have a typo - one version of the macro has (if it test else), the
other has (if it then else). The version with (if it test else) never
actually uses the "then" clause, which is where you refer to "it".
That's why it doesn't get a syntax error. It's not that "it" is bound
correctly, it's that you discard the reference.
--Carl
On Mon, Aug 4, 2008 at 9:54 PM, YC <yinso.chen at gmail.com> 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