request for comments: namespace mechanism

Ralf Juengling <[email protected]> Sun, 26 Feb 2006 10:56:17 -0800 (PST)
Newsgroups gmane.lisp.lush.devel
Message-ID <[email protected]>
Hi,

I am working on a mechanism for simulating namespaces. The
implementation is inspired by the package macro. Here is my
idea so far: Writing

(namespace abc

   (de func1 (..) ...)
   (defun func2 (..) (..) (func1 ...))
   ...
   (defvar sym1 (func1 815))
   (setq sym2 (func2 sym1))
   ...
)

defines functions 'abc-func1', 'abc-func2', ..., and symbol
'abc-sym1'. Within the namespace form the already defined
things can be referenced by the symbols without the namespace
prefix (e.g., function 'func2' invokes function 'abc-func1'
through the name 'func1', similar for the lhs expressions
defining the value bound to 'abc-sym1'. Bindings established
by de, df, dm, defun, defvar, defparameter, and defclass will
be affected, bindings by set ot setq will not be affected (so
the result of (abc-func2 sym1) would be bound to 'sym2' above).

The namespace form creates a mapping from unqualified names
('func1' ...) to qualified names ('abc-func1') and binds it
to the name 'abc' using defparameter. Thus, there is an
object 'abc' that represents the namespace and that you may
pass around to other code.

Other code outside the namespace form has three options to
reference the things defined in the namespace:
1. It uses the qualified names 'abc-func1',...
2. It uses the unqualified names within a 'with-namespace'
    form:

(with-namespace abc
   (print (func1 815))
   ...
)

3. It may globally bind selected things to the unqualified
    names using 'import'

(import (func1 sym1) from abc)
(print (func1 815))
(print (abc-func2 816))
...

Namespace forms may be nested. For example evaluating

(namespace abc
   (defun func1 (...) ...)
   (namespace def
     (defun func2 (...) ...)
   )
)

creates the namespaces 'abc' and 'abc-def'. Namespace 'abc'
contains the mappings
'func1' -> 'abc-func1'
'def-func2' -> 'abc-def-func2'
'def' -> 'abc-def'

and namespace 'abc-def' contains the mapping
'func2' -> 'abc-def-func2'


I'm half-way done with this, please let me know if you
have any suggestions. For instance, what should happen when
an import form occurs in a namespace form?

(namespace abc
   (import (f1 f2) from xyz)
   (defun func1 (..)
     (+ (f1 ..) (f2 ...)) )
)

This could either (in line with my earlier definition of
import) establish the global bindings 'f1' -> 'xyz-f1'
and 'f2' -> 'xyz-f2' and add nothing to the namespace
'abc'. Alternatively, import could add the names 'f1'
and 'f2' to the namespace 'abc' instead (hence, import
would establish the global bindings 'abc-f1' -> 'xyz-f1',
'abc-f2' -> 'xyz-f2').

Ralf



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642