[plt-scheme] enclosing-module-name

From: support at taxupdate.com (support at taxupdate.com)
Date: Wed Apr 4 14:13:26 EDT 2007

On Thu, Apr 05, 2007 at 05:05:26AM +0800, Matthew Flatt wrote:
> 
> It's possible that either `syntax-identifier-binding' or
> `syntax-source-module' will do what you want, but I'm not sure.

I tried both of these, and they don't seem to provide what's needed in
my situation.  Here's what I'd like to be able to do:

The application will interpret user files written in what I'll call
a "template language":

(template x "description of x"
    (image "image1.xpm"
	(text first "First Name")
	(fixed-2 wages "Wages")
	(fixed-2 agi "AGI" (+ wages 100))))
	
which gets transformed to (roughly):

(module x sandbox-language
    (register 'x 'first "")
    (register 'x 'wages 0)
    (register 'x 'agi (+ wages 100))      ; this field has a "formula"
    (reqister-image "image1.xpm")
    ...)

(define *field-hash* (make-hash-table))
(define (register module var)
    (hash-table-put! *field-hash* (string->symbol (format "~a.~a" module var))))
    
The hash table gives me a simple namespace simulation which I can control
easily.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Here's the problem I'd like to solve.  The "formula", such as (+ wages 100),
can be any scheme expression.  It gets transformed by a #%top which does a
hash-table-get on *field-hash* for any top-level symbol which isn't defined.
So %#top needs to know the enclosing module name (in this case "x") in order
to do the lookup.  I'd like to avoid requiring (+ x.wages 100) if possible
when the reference is to another field in the same template.  When the formula
refers to another template, then it must use the form (+ y.wages 200).

I attempted this using parameters, but this didn't work correctly because
the parameter doesn't get evaluated until run time.  That caused problems
when more than one template was evaluated. 

#%module-begin looks promising, since it includes the enclosing-module-name
syntax property.  However, it seems hazy to me how I can get #%top to see
the property that's only available to #%module-begin.

define-syntax-parameters might work, but I also want to avoid using any plt libs
like stxparam.ss, as the app will be distributed to users who don't have mzscheme
installed (only libmzscheme/libgc, mzscheme will be embedded in the app).

Any ideas on how to define #%top to be able to get the module name at compile time?
If you've made it this far, thanks for your patience on this long post!

Wayne


Posted on the users mailing list.