[plt-scheme] How to dynamic-require a syntax?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Dec 21 08:23:41 EST 2008

`dynamic-require' gets a value, not an identifier. In this case, you
don't want to get a value for `p'; you want a `p' identifier that is
syntactically bound to an export of "t1.ss". That is, the macro needs
to expand to

  (open-package p)

which is syntactically valid, and not

  (open-package <some-value>)

which is not syntactically valid.


Are you trying to do this in the SML expander, where you discover while
compiling an expressions that it references another module, and so you
need to import a structure-as-package from another module? If so,
doesn't the old `#%module-begin' delimited-continuation trick work as
before?


At Sun, 21 Dec 2008 16:15:50 +0800, Chongkai Zhu wrote:
> File t1.ss:
> 
> #lang scheme
> 
> (require scheme/package)
> 
> (define-package p #:all-defined
>   (define x 1))
> 
> (provide p)
> 
> 
> File t2.ss:
> 
> #lang scheme
> 
> (require scheme/package)
> 
> (define-syntax (load-package stx)
>   (syntax-case stx ()
>     ((load-package p)
>      #`(open-package #,(dynamic-require '(file "t1.ss") (syntax->datum 
> #'p))))))
> 
> (load-package p)
> 
> -Chongkai
> 
> 
> Jon Rafkind wrote:
> > Chongkai Zhu wrote:
> >> I tried something like
> >>
> >> (define-syntax (my-macro stx)
> >>  (syntax-case stx ()
> >>    ((my-macro p)
> >>     #`(... #,(dynamic-require '(file "t1.ss") (syntax->datum #'p)) 
> >> ...))))
> >>
> > Works for me. Can you paste an entire example that segfaults?
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.