[racket] Understanding local-expand with definition contexts

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Jan 7 20:58:48 EST 2015

At Mon, 5 Jan 2015 18:53:57 -0500, Ryan Culpepper wrote:
> Here’s an alternative solution as a trampolining* macro.

Thanks! That's definitely a better and more general approach.


> The key is to cooperates with the unit macro’s definition-context
> handling rather than trying to duplicate that effort.

Just to be clear for everyone else, Ryan's solution is independent of
units. It "cooperates" with any other macro that has the usual
expansion protocol, such as an internal-definition context.

For example, `capture-lifts` can be used in an internal-definition
context, and it's splicing in that context:

 (define (f)
   (capture-lifts
    (begin
      (define-syntax (lifted stx)
        (syntax-parse stx
          [(_ e)
           (syntax-local-lift-expression #'e)]))
      (define a (for/list ([i 2]) (lifted (gensym))))
      (define b (gensym))))
   (printf "~s ~s\n" a b))



Posted on the users mailing list.