> On Jan 21, 2017, at 6:27 PM, Dupéron Georges
> wrote:
>
> I was going to suggest `dynamic-require-for-syntax`, but it seems to do
> exactly the same thing as `dynamic-require`, i.e. give the value of a phase-0
> provided identifier. Is this normal?
>
> The `eval` trick is a good idea, I would say. From the couple of times I have
> used dynamic-require, I have felt that it was pretty limited concerning
> shifting phases.
>
> The thing I found to be the most difficult is to extract the phase 1 value
> bound to a macro via define-syntax. Following your `eval` idea, I managed to
> do that using 3D syntax. I suppose it's safe, as the 3D syntax object is
> created on the fly during `eval` and promptly discarded, therefore it should
> never need to be marshalled into a compiled file.
>
> (eval #'(begin
> (module m racket/base
> (require (for-syntax racket/base) "x.rkt")
> (provide (for-syntax x-val))
> (define-syntax (get-val stx)
> (syntax-case stx ()
> [(_ name)
> #`(define-for-syntax name #,(syntax-local-value #'x))]))
> (get-val x-val))
> (require (for-meta -1 'm))
> x-val))
If `eval` is inevitable I want to minimize it as much as possible, and I don't
want to rely on 3d syntax. I think I use eval to define a module that shifts
the phase by that amount, then dynamic-require from that module instead:
(define (dynamic-require-for-meta mod phase sym)
(define mod* (resolve-module-path mod))
(parameterize ([current-namespace (make-base-namespace)])
(eval `(module mod-for-phase reprovide
(#%module-begin (only-meta-in 0 (for-meta ,phase ,mod*)
(dynamic-require ''mod-for-phase sym)))
(dynamic-require-for-meta "x.rkt" -1 'x)
This isn't meant to require macro transformers; it's only meant to require
things that were provided for-syntax.
Thanks,
Alex Knauth
--
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.