As far as I can tell this makes the (context) thing you implemented before
pretty redundant or is it worth keeping?


On Fri, Sep 16, 2011 at 6:39 PM, Alexander Burger <a...@software-lab.de>wrote:

> Hi all,
>
> from time to time, the issue of symbol namespaces (or the lack of them)
> in PicoLisp is brought up again.
>
> Personally, I think that namespaces (that is, different sets of interned
> symbols in different contexts) may confuse more than they do really
> help.
>
> But with transient symbols we do already have a certain kind of
> namespaces, implicit by the lexical (source file) context. So I decided
> to go ahead, and implement "named" symbol namespaces ... if we regard
> transient symbols as residing in the own anonymous namespaces.
>
> This feature is available only in the 64-bit version. It could perhaps
> be implemented also in Ersatz and MiniPicoLisp, but unfortunately not in
> the 32-bit version, because of its different symbol table mechanism.
>
>
> The underlying concepts are very simple. Only a single new function was
> added, 'symbols', and a new global 'pico' holding the initial (default)
> symbol namespace.
>
> If 'symbols' is never called, everything should work as before.
>
> Calling it without arguments
>
>   : (symbols)
>   -> pico
>
> returns the current namespace.
>
>
> If you call it with the name of a new namespace and the name of an
> existing namespace
>
>   : (symbols 'myNames 'pico)
>   -> pico
>
> the following happens: The symbol 'myNames' (existing in the current
> namespace) receives a _copy_ of the namespace 'pico', and is made the
> new current one. Check:
>
>   : (symbols)
>   -> myNames
>
>
> After a namespace is created that way, it is independent from other
> namespaces. New symbols will be added here, and deleting symbols (with
> 'zap') will not influence other namespaces.
>
> Thus, a symbol will not be garbage collected as long as it is referred
> to from at least one namespace. Symbols from other namespaces, when
> visible in data structures, will appear as transient symbols.
>
>
> If you call 'symbols' with a single argument, it should be an existing
> namespace, and this will be set to be the new current one.
>
>   : (symbols 'pico)
>   -> myNames
>
> The previously current namespace is returned.
>
> Check:
>
>   : (symbols)
>   -> pico
>
> Fiddling around with symbols named "Foo":
>
>   : (zero Foo)
>   -> 0
>
>   : (symbols 'myNames)
>   -> pico
>
>   : (one Foo)
>   -> 1
>
>   : Foo
>   -> 1
>
>   : (symbols 'pico)
>   -> myNames
>
>   : Foo
>   -> 0
>
> To access a symbol in another namespace, we can use a tilde character
> separating a namespace from a symbol. The tile was chosen because it
> possibly does not conflict with the rest of the PicoLisp syntax.
>
>   : myNames~Foo
>   -> 1
>
>   : (setq myNames~Bar 'myNames~Foo)
>   -> "Foo"
>
>   : Bar
>   -> NIL
>
>   : (symbols 'myNames)
>   -> pico
>
>   : Bar
>   -> Foo
>
> This syntax can also be chained, e.g. myNames~yourNames~foo
>
>
> I have released a new testing version as a draft. Documentation and unit
> tests are still missing, though.
>
> Any opinions?
>
> Cheers,
> - Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>

Reply via email to