[racket-dev] local-transformer-expand behavior

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jun 25 05:02:37 EDT 2013

At Tue, 25 Jun 2013 01:11:45 -0400, Asumu Takikawa wrote:
> Hi all,
> 
> Does anyone know what the behavior of
> 
>   (local-transformer-expand #'(define x 3) 'top-level null)
> 
> should be? I'm not sure, but I expected something like what
> `local-expand` would do. Instead, I get an error like this:
> 
>   > (define-syntax (m stx)
>       (local-transformer-expand
>        #'(define x 3) 'top-level null))
>   > (m)
>   ; readline-input:14:51: define: not allowed in an expression context
>   ;   in: (define x 3)
>   ; [,bt for context]
> 
> Am I just misuing the function? 

That error is due to a bug in handling the 'top-level context, and I've
pushed a repair.

> I also tried to wrap the quoted
> definition with a `let`, but then got errors saying `let-values` is
> unbound (which seems odd since it's a core form).

That's actually the right error. The `let' successfully expands to
`let-values' in phase 1. The `let-values' identifier in the expansion
has a phase-1 binding, but not a phase-0 binding. When the `let-values'
form is returned as the result of expanding `(m)', then it ends up in a
phase-0 context, and that triggers the error you.


Posted on the dev mailing list.