[racket-dev] cross-phase syntax constants

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Thu Jul 5 17:17:08 EDT 2012

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)

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
samth at ccs.neu.edu

Posted on the dev mailing list.