Hi Thorsten,

> I haven't seen so many uses of the (quite recently) introduced
> namespaces in PicoLisp, so I would like to ask what is the canonical way
> to use them?

An important question. I've thought about this, too from time to time,
but never actually used namespaces in production code so far.


> Say I have a library called 'pio.l'. In Emacs Lisp I now would prefix
> all definitions in this library with "pio-", i.e. 
> 
> ,-----------------------------
> | (de pio-do-something (X Y) ...)
> `-----------------------------

This is a prefectly valid strategy, and anyway is the only way to go in
PicoLisps without namespaces (i.e. on 32-bits).


> Since there are namespaces available now, I would rather avoid this and
> use something like this:
> 
> ,----------------------------
> | (symbols "pio" 'pico)
> | (local do-something X Y)
> | 
> | (de do-something (X Y) ...)
> `----------------------------
> 
> My questions are now:
> 
> 1. Is using a transient namespace the default,

Transient namespaces I would only use for small packages. Doing so would
require prefixing "exported" symbols with a target-namespace, e.g.
'pico', to make them resident there

   (de pico~myPioFunction (X Y)
      .. )

because otherwise _all_ definitions of that namespace would be gone when
"pio" goes out of scope. With the above, 'myPioFunction' can be directly
used in the 'pico' namespace.


Transient namespaces are nice if you want to avoid using transient
symbols for local variables in cases they are necessary. So instead of

   (de pico~myPioFunction ("X" "Y")
      (fun "X" .. "Y" ..) )

you could write

   (symbols "pio" 'pico)
   (local X Y)

   (de pico~myPioFunction (X Y)
      (fun X .. Y ..) )


> or should I use
> 
>  ,---------------------
>  | (symbols 'pio 'pico)
>  `---------------------

This I would use for creating larger packages. In that case I would not
prefix "exported" symbols:

   (symbols 'pio 'pico)
   (local X Y)

   (de myPioFunction (X Y)
      (fun X .. Y ..) )

so that 'myPioFunction' can be accessed from other packages as

   (pio~myPioFunction ..)

or by spaning other packages as descendenants from 'pio'

   (symbols 'myApp 'pio)

or possibly from more than one package

   (symbols 'myApp 'pio 'bla 'mumble)


> 2. Is it necessary to put all library definitions (and all ARGS) into
> the (local ...) function to define them as part of the new namespace?

I would not do so, to avoid clobbering the sources with too many 'local'
calls.

Instead, I would just go ahead, and 'load' the new package, watching for
the "redefined" messages of possible collisions. This is a matter of
taste, though.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to