[plt-scheme] datum->syntax rules

From: YC (yinso.chen at gmail.com)
Date: Mon Aug 4 21:54:46 EDT 2008

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.

(define-syntax (if-it stx)
  (syntax-case stx ()
    ((_ test then else)
     (with-syntax ((it
                    (datum->syntax #'_
       #'(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
       #'(let ((it test))
           (if it then else)

(if-it1 '(abc def) it 'nil) ;; => reference to undefined identifier: it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080804/01d2193f/attachment.html>

Posted on the users mailing list.