Re: [racket-users] Dynamic-require a compile-time identifier?

2017-01-21 Thread Alex Knauth

> 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.


[racket-users] Dynamic-require a compile-time identifier?

2017-01-18 Thread Alex Knauth
Is there a way to dynamic-require an identifier provided at phase 1?

#file x.rkt
#lang racket
(provide (for-syntax x)) ; x is provided at phase 1
(define-for-syntax x 3)

#file use.rkt
#lang racket
(dynamic-require-from-phase-1 "x.rkt" 'x)
;=> 3

I could do it by defining another module that did the phase shift:

#file x.rkt
#lang racket
(provide (for-syntax x))
(define-for-syntax x 3)

(module* ct racket/base
  (provide (for-meta -1 (all-from-out (submod ".."
  (require (for-meta -1 (submod ".."

#file use.rkt
#lang racket
(dynamic-require '(submod "x.rkt" ct) 'x)

But that requires an extra module to be defined already. I could also do it 
with eval, but that feels wrong and shouldn't be necessary. There should be a 
way to do this without needing eval.

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.