[racket-dev] error using local-expand

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Fri Dec 9 16:53:06 EST 2011

Say I have the following program:


#lang racket

(define-for-syntax (loc-expand stx) (local-expand stx 'expression '()))

(define-syntax (my-begin stx)
  (syntax-case stx ()
    [(_ e ...)
     (with-syntax ([(x ...) (map loc-expand (syntax->list #'(e ...)))])
       #'(begin x ...))]))

(define-syntax (my-lambda1 stx)
  (syntax-case stx ()
    [(_ args body ...)
     #'(lambda args (my-begin body ...))]))

(define-syntax (my-lambda2 stx)
  (syntax-case stx ()
    [(_ args body ...)
     (with-syntax ([(x ...) (map loc-expand (syntax->list #'(body ...)))])
     #'(lambda args (begin x ...)))]))


An expression (my-lambda1 (y) (+ y 1)) works fine but (my-lambda2 (y)
(+ y 1)) produces the error:

    expand: unbound identifier in module in: y


I can't figure out why this is the case. Anyone know?


Posted on the dev mailing list.