What about something like what you are proposing, but where you have to explicitly state when you use the module namespace, since we obviously can't overwrite = without sad effects ?
For example, let's take the $ symbol (another ugly one :) to mean "the current module". The above could be written :
(module foo (export a bar)
(= $!a 'in-top)
(def $!foo (x) (+ x 1))
(def $!bar (x) (+ x 1))
(pr a))
(prn foo!a)
(foo!bar 0)
(= bar foo!bar) ; an import.
(= a2 foo!a) ; a qualified import.
Advantages :
- very simple
- written in pure Arc (thus candidate to the core language)
Here's a macro implementing part of that behavior :
(= $ nil)
(= $path* '()) ; Current module hierarchy
(mac module (name . body)
(w/uniq old-$
`(with (,old-$ $)
(= $ (table))
(push $ $path*)
,@body
(pop $path*)
(if $path*
(= (,old-$ ',name) $) ; Put it in the parent
(= ,name $)) ; Put it in global namespace
(= $ ,old-$))))
It supports imbricated modules. To import a module, or do a qualified import, the classical table manipulation functions work.