1.) I use namespaces in what I currently work on. Works good, I use
them wherever I would've earlier just created a "static" class as a
container. It helps to communicate the intent better where intent in
this case is just a collection of functions that I want to
group/encapsulate together.

Here is the top of a namespace that I use to extend the default
functions that operate on lists:

(symbols 'exlst 'pico)

(local range replace)

(de range (Start End . @)
  (let Pad (next)
        (for (N Start (>= End N) (inc N)) (link (if Pad (pad Pad N) N))) ) ) )

(de replace (Search Replace Stack)
   (use @A @B
      (ifn (match (append (list '@A) Search (list '@B)) Stack)
         (append @A Replace @B) ) ) )

(de flatten @
      (for L (rest)
         (recur (L)
            (for El L
               (if (lst? El)
                  (recurse El)
                  (link El)))))))

2.) As you can see the call to local there is needed to avoid clashes
with functions that are already defined. So no, you don't need to put
everything there, for instance flatten in my case since it doesn't
exist in 'pico (at least not per default).

3.) No, don't keep it "simple".

On Sun, Apr 21, 2013 at 3:12 PM, Thorsten Jolitz <tjol...@gmail.com> wrote:
> Hi List,
> 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?
> 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) ...)
> `-----------------------------
> 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, or should I use
>  ,---------------------
>  | (symbols 'pio 'pico)
>  `---------------------
> instead?
> 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?
> 3. Should I use namespaces anyway, or rather keep it simple and use the
> "pio-" prefix?
> --
> cheers,
> Thorsten
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to