I was just thinking about a minimalist module system for Arc. I tried to implement it, but it's far to be done. Here's the idea : a macro called module defines a module (sic). In this module, a new (virtual) namespace is created. Both the module and the global namespace can then be accessed : (module 'foo
(m= a 'in-foo)
(= a 'in-top)
(mdef bar (x) (+ x 1))
(pr a)
)
This declares a module (a default namespace) called "foo". There are two more macros : m= and mdef ; they are the counterpart of = and def, but the defined variables / functions are prefixed by "foo@". Thus, the above code is the equivalent of(= foo@a 'in-foo)
(= a 'in-top)
(def foo@bar (x) (+ x 1))
(pr foo@a) As you can see, m= defines a package variable (that's the new part), = a global one (as usal, since you must sometimes modify global values). Inside the module, a is equivalent to foo@a (to make it work, I had to hack a little arc-var-ref in ac.scm). In foo, a is hidden by foo@a. Once outside the module, we're back in the global namespace. So the variable has to be prefixed by foo@, or else we're talking about the global one : arc> a
'in-top
arc> foo@a
'in-foo
There is no magic here, the @ is just an arbitrary character I chose, foo is not a hash table or something like that. It is just a string-append.mmac should be added I guess. Good points : - modules can be ignored if you don't want them. symbols from modules are just plain symbols with an @ in the middle
- the mechanism can be written in a few macros only
Bad points : - not yet totally implemented
- needs to modify the axioms in *ac.scm*, which could drive pg crazy as this is not the priority :)
What do you think of this idea ? Do I miss very important things ? Should I spend my time on more valuable things ? |