[plt-scheme] local special syntax confusion

From: Psy-Kosh (psykosh at earthlink.net)
Date: Wed Jan 2 18:45:45 EST 2008

A bit confused about locally redefining special syntax like #%app

What I mean is this:

(let-syntax ((#%app
               (syntax-rules ()
                 ((_ a b) (+ a b)))))
   (3 5))

Produces 8 no problem.

on the other hand,

(define-syntax (blah stx)
   (syntax-case stx ()
     ((_ exp)
      (with-syntax
          ((#%app (datum->syntax-object #'exp '#%app)))
        #'(let-syntax ((#%app
                        (syntax-rules ()
                          ((_ a b) (+ a b)))))
            exp)))))

(blah (3 5))

produces the error "compile: identifier used out of context in: #%app"
*blinks* huh?

On the other other hand,

(define-syntax (blah stx)
   (syntax-case stx ()
     ((_ exp)
      (with-syntax
          ((app (datum->syntax-object #'exp '#%app)))
        #'(let-syntax ((app
                        (syntax-rules ()
                          ((_ a b) (+ a b)))))
            exp)))))

(blah (3 5))

produces 8 again.

I'm probably missing something really basic and obvious here, but no clue  
what. So why does #2 fail while both #1 and #3 work?

Thanks

Psy-Kosh


Posted on the users mailing list.