At Fri, 25 Dec 2015 16:58:53 -0700, Leif Andersen wrote:
> That's what I thought initially too, but it didn't seem to make a
> difference when I used
> `expand-syntax-top-level-with-compile-time-evals`, although then I
> realized that perhaps a better function to use would be
> `eval-compile-time-part-of-top-level/compile`, and than evaling each
> of those expressions, giving:
> 
> (map eval (eval-compile-time-part-of-top-level/compile
> (expand-syntax-top-level-with-compile-time-evals prog)))
> 
> But then I get the same error:
> 
> racket/racket/collects/racket/private/map.rkt:21:13: x: undefined;
>  cannot reference undefined identifier

It looks like this problem is a weakness of
`expand-syntax-top-level-with-compile-time-evals` for handling
`require` forms that have scopes other than the current namespace's
scopes.

This variation works as you expect:

 (parameterize ([current-namespace (make-base-namespace)])
   (map eval (eval-compile-time-part-of-top-level/compile
              (expand-syntax-top-level-with-compile-time-evals
               (namespace-syntax-introduce (strip-context prog))))))


The problem with `require` handling is that it uses
`namespace-require/expansion-time`, which takes a `#%require` spec as a
datum, so there's no way to provide the scopes that `prog` gets from
your enclosing test module. Instead, the current namespace's copes are
used.

Using `expand-top...` instead of `expand-syntax-top...` works around
the problem, since that adds the namespace's scopes to `prog` so that
the bindings created by `namespace-require/expansion-time` will apply.

More generally, I can look into repairing
`expand-syntax-top-level-with-compile-time-evals`, but I think you'll
have less trouble in the long run if you don't mix up scopes from a
test environment with scopes from a compilation namespace.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to