<div dir="ltr"><div>I have a namespace behind a particular API. I'd love to hook into the module system to control compilation, visibility, etc. of all the definitions and references.</div><div><br></div><div>Here's an example. 'a' is available in the top level module even though it was defined by module 'm1' and not provided by any explicit mechanism. (Also, order dependencies seem imminent.)</div><div><br></div><div><div><font face="courier new, monospace">#lang racket</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(module base racket</font></div><div><font face="courier new, monospace"> (define my-table (make-hasheq))</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"> (define-syntax (my-define stx)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>(syntax-case stx ()</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span> [(_ my-id expr) (identifier? #'my-id)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span> #'(hash-set! my-table 'my-id expr)]))</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span> </font></div><div><font face="courier new, monospace"> (define-syntax (my-eval stx)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>(syntax-case stx ()</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span> [(_ my-id)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span> #'(hash-ref my-table my-id #f)]))</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"> (provide my-define</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span> my-eval)</font></div><div><font face="courier new, monospace"> )</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(module m1 racket</font></div><div><font face="courier new, monospace"> (require (submod ".." base))</font></div><div><font face="courier new, monospace"> (my-define a (+ 1 2))</font></div><div><font face="courier new, monospace"> )</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(require 'base</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span> 'm1)</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(my-eval 'a)</font></div></div><div><br></div><div><br></div><div>Is there any example of doing something like this using the module system without polluting the top level namespace? Am I correct in assuming that this will not work under separate module compilation?<br></div><div><br></div>-- <br>Dan Liebgold [<a href="mailto:dan.liebgold@gmail.com">dan.liebgold@gmail.com</a>]
</div>