Hopefully I read your message correctly that you are trying to define custom 'require' extensions, which the following could be what you are looking for: <div><br></div><div><a href="http://docs.racket-lang.org/reference/define.html#(mod-path._racket/require-syntax)">http://docs.racket-lang.org/reference/define.html#(mod-path._racket/require-syntax)</a></div>
<div><br></div><div>Caveat - I've never used require-syntax so don't know for certain if that's what you need.</div><div><br></div><div>But you can also define your own "require" if you don't mind to use another name, such as require/env, and then you can export it as require so other modules can use it to replace the regular 'require' (of course if you want to use other regular require specs you must take the care to reexpose them with this approach. </div>
<div><br></div><div>Below is a sketch of what require/env looks like (you can replace #lang scheme with #lang racket) - it only handle a single require spec as written. </div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div><div><div>#lang scheme</div><div>(require (for-syntax scheme)) </div><div><br></div><div>(begin-for-syntax </div><div> ;; the environment database - extend through set-env!</div><div> (define env-db </div><div> (make-hash `((url . net/url) </div>
<div> (cookie . net/cookie))))</div><div> </div><div> ;; return the module name based on the key </div><div> (define (get-env key) </div><div> (datum->syntax </div><div> key </div><div> (hash-ref env-db (syntax->datum key) </div>
<div> (lambda () </div><div> (error 'require/env "module ~a not exist" (syntax->datum key))</div><div> ))))</div><div> </div><div> ;; sets a key for a particular module - even possible for require-specific specs </div>
<div> ;; such as prefix-in or only-in </div><div> (define (set-env! key mod) </div><div> (hash-set! env-db </div><div> (syntax->datum key) </div><div> (syntax->datum mod))</div><div>
#'(void)) </div><div> )</div><div><br></div><div>;; sets the alias for the require spec. </div><div>(define-syntax (define-require-env-alias! stx) </div><div> (syntax-case stx () </div><div> ((~ key mod) </div>
<div> (with-syntax ((result (set-env! #'key #'mod))) </div><div> #'result))</div><div> )) </div><div><br></div><div>;; require/env - use this to access the spec by alias. </div><div>(define-syntax (require/env stx) </div>
<div> (syntax-case stx () </div><div> ((~ key) </div><div> (with-syntax ((key (get-env #'key))) </div><div> #'(require key)))</div><div> )) </div><div><br></div><div>;; example usage - </div><div>
(require/env url) ;; (require net/url) </div><div>(require/env cookie) ;; (require net/cookie) </div><div><br></div><div>;; maps date to (planet bzlib/date/srfi) </div><div>(define-require-env-alias! date (planet bzlib/date/srfi)) </div>
<div><br></div><div>(require/env date) </div><div><br></div><div>(define-require-env-alias! xexpr-only (only-in xml xexpr? xexpr->string)) </div><div><br></div><div>(require/env xexpr-only) </div></div></div></blockquote>
<div><br></div><div>Hope this is what you are looking for. </div><div><br></div><div>Cheers,</div><div>yc</div><div><br></div><div><br></div><div><div class="gmail_quote">On Fri, Sep 10, 2010 at 10:51 PM, synx <span dir="ltr"><<a href="mailto:plt@synx.us.to">plt@synx.us.to</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
In my efforts to create a dynamically loading environment, I'd like to<br>
do something like this:<br>
- ---<br>
#lang racket/base<br>
<br>
(define-for-syntax db (something))<br>
(define-for-syntax (get-env key) (db-value db key))<br>
<br>
(define-syntax env<br>
(lambda (form)<br>
(syntax-case (form) ()<br>
(#'(_ key)<br>
(let ((key (syntax->datum (cadr form))))<br>
(do-something-to<br>
key<br>
(datum->syntax<br>
form<br>
(get-env key)<br>
form)))))))<br>
<br>
(require (env some-key))<br>
- ---<br>
<br>
But for the life of me I can't figure out how to do it. I looked into<br>
the import and import-source structures, but neither of them specify<br>
anything in regards to the value of what's being required. They just<br>
name it and the value is somehow acquired by other means. I tried<br>
putting something random in for the src-mod-path like 'env/foo but then<br>
racket actually tries to find and read the "env/foo.rkt" file in the<br>
current collections path, and won't just call get-env like I was hoping for.<br>
<br>
Basically what I'm looking for is some way to have the modules required<br>
be an evaluable module form returned by just some procedure, instead of<br>
being filesystem files or planet packages. The procedure would get the<br>
module from a database, and possibly as a side effect also trigger the<br>
recalculation of any other evaluation contexts that require that<br>
particular module.<br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v2.0.14 (GNU/Linux)<br>
Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org/" target="_blank">http://enigmail.mozdev.org/</a><br>
<br>
iQEcBAEBAgAGBQJMixjiAAoJECC/cKf8E7UIXAUH/2Zf3NsJ+jiJ47F3LRHh28Y2<br>
8wNMbI3W/JhPlQLBSDga5p3qEzrLX17cHFm3Tx8eE4vMLPVd7+gz2QKTWvNPFz6Q<br>
37chCXsHfUnnCP3rOMBvqoJKz2mlvfqjLj4F+/GDxwR+Ua3UAsocKvvk7TlT8yM7<br>
/lmVKIP1WcMLXLMLst+HuUYjFYMOzOtmog1x4/nA66cYJiDD1IgX1gX9h1HxqyDP<br>
HNFYih43fE4IZUXERBfFDW9C48Wj3cgcauiWfGmh+2GdrDvnJP+SzRSCnInJSpTT<br>
Fp/V3MCceoN9ue9RNEktze/ym4ixnXUra+nBOHCgwImh8BSSWbu3AZIGGNLDWAQ=<br>
=SsEf<br>
-----END PGP SIGNATURE-----<br>
_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Cheers,<br>yc<br><br>Taming the software dragon - <a href="http://dragonmaestro.com">http://dragonmaestro.com</a><br><br>
</div>