Re: [racket-dev] cross-phase syntax constants

2012-07-06 Thread Matthew Flatt
I find the example too abstract to understand why the computation
happens at the wrong phase when you adjust the code with
`begin-for-syntax'. Can you explain a little more, maybe with a more
concrete example?

Just in case, here's the code that I think you have in mind for wrong
phase:

 #lang racket/load

 (module m1 racket
   (define l (list #'l))
   (provide l))

 (module m2 racket
   (require (for-syntax 'm1))
   (define-syntax (mac stx)
 #`(begin-for-syntax
(module* sub #f
  (length (list #,(car l))
   (provide mac))

 (module m3 racket
   (require 'm2)
   (mac))

 (require (submod 'm3 sub))


At Thu, 5 Jul 2012 17:17:08 -0400, Sam Tobin-Hochstadt wrote:
 I'd like to write a program basically like this:
 
 #lang racket/load
 
 (module m1 racket
   (define l (list #'l))
   (provide l))
 
 (module m2 racket
   (require (for-syntax 'm1))
   (define-syntax (mac stx)
 #`(module* sub #f
 (length (list #,(car l)
   (provide mac))
 
 (module m3 racket
   (require 'm2)
   (mac))
 
 But I can't come up with any way to `require` m1 appropriately so that
 `l` is bound in the generated submodule.  If I wrap the body of the
 submodule in `begin-for-syntax`, then it works, but then loading the
 submodule does the computation at the wrong phase.  So another
 solution would be `dynamic-require-for-template`, if that's feasible.
 -- 
 sam th
 sa...@ccs.neu.edu
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] cross-phase syntax constants

2012-07-06 Thread Sam Tobin-Hochstadt
On Fri, Jul 6, 2012 at 11:00 AM, Matthew Flatt mfl...@cs.utah.edu wrote:
 I find the example too abstract to understand why the computation
 happens at the wrong phase when you adjust the code with
 `begin-for-syntax'. Can you explain a little more, maybe with a more
 concrete example?

 Just in case, here's the code that I think you have in mind for wrong
 phase:

I had not realized that I could sensibly wrap a module in a
`begin-for-syntax`.  What is the semantic difference between that and
a plain submodule (other than my example working)?  I will try that,
and see if it works for my purposes.

 At Thu, 5 Jul 2012 17:17:08 -0400, Sam Tobin-Hochstadt wrote:
 I'd like to write a program basically like this:

 #lang racket/load

 (module m1 racket
   (define l (list #'l))
   (provide l))

 (module m2 racket
   (require (for-syntax 'm1))
   (define-syntax (mac stx)
 #`(module* sub #f
 (length (list #,(car l)
   (provide mac))

 (module m3 racket
   (require 'm2)
   (mac))

 But I can't come up with any way to `require` m1 appropriately so that
 `l` is bound in the generated submodule.  If I wrap the body of the
 submodule in `begin-for-syntax`, then it works, but then loading the
 submodule does the computation at the wrong phase.  So another
 solution would be `dynamic-require-for-template`, if that's feasible.
 --
 sam th
 sa...@ccs.neu.edu



-- 
sam th
sa...@ccs.neu.edu
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] cross-phase syntax constants

2012-07-06 Thread Matthew Flatt
At Fri, 6 Jul 2012 11:13:44 -0400, Sam Tobin-Hochstadt wrote:
 I had not realized that I could sensibly wrap a module in a
 `begin-for-syntax`.  What is the semantic difference between that and
 a plain submodule (other than my example working)?

For `(module* _name #f )', `begin-for-syntax' shifts the phase
level of the enclosing module's bindings relative to the submodule. An
enclosing `begin-for-syntax' has no effect on a `module' submodule or
`module*' with a module path instead of `#f', though.

(This is documented with `module*'.)

_
  Racket Developers list:
  http://lists.racket-lang.org/dev


[racket-dev] cross-phase syntax constants

2012-07-05 Thread Sam Tobin-Hochstadt
I'd like to write a program basically like this:

#lang racket/load

(module m1 racket
  (define l (list #'l))
  (provide l))

(module m2 racket
  (require (for-syntax 'm1))
  (define-syntax (mac stx)
#`(module* sub #f
(length (list #,(car l)
  (provide mac))

(module m3 racket
  (require 'm2)
  (mac))

But I can't come up with any way to `require` m1 appropriately so that
`l` is bound in the generated submodule.  If I wrap the body of the
submodule in `begin-for-syntax`, then it works, but then loading the
submodule does the computation at the wrong phase.  So another
solution would be `dynamic-require-for-template`, if that's feasible.
-- 
sam th
sa...@ccs.neu.edu
_
  Racket Developers list:
  http://lists.racket-lang.org/dev