On Wed, 1 Feb 2012 05:53:11 -0800
Imran Rafique <im...@rafique.org> wrote:

> Thanks for responding Alex.
> 
> As you know, I'm just trying out picolisp in my spare time (hence my
> slow responses on this list, sorry about that). To put some context
> to these questions, I thought that using seperate namespaces to
> simulate a key/value dictionary/hash-table would be a nice idea to
> play with, to understand picolisp better.
> 
> (alists are nice and easy, but if you update it frequently cons'ing
> changes to the begining, it gets slower & slower to work with the
> less frequently changing key/values at the end of the alist)
> 
Why not use a 'idx tree then? http://software-lab.de/doc/refI.html#idx

##################################################
# I used 'name here to prevent accidental clobbering
(de iset (Tree Key Value)
   (set
      (or
         (car (idx Tree Key))
         (prog1 (name Key) (idx Tree @ T)) )
      Value ) )

(de iget (Tree Key)
   (val (car (idx Tree Key))) )

###### Tests ######
: (iset 'mydict "Foo" 42)
-> 42

: (iset 'mydict "Bar" T)
-> T

: (iset 'mydict "Bam" "Baz")
-> "Baz"

: (iget 'mydict "Foo")
-> 42

: (iget 'mydict "Bam")
-> "Baz"

: (iget 'mydict "Bar")
-> T

: (mapcar show (idx 'mydict)) 
"Bam" "Baz"
"Bar" T
"Foo" 42
-> ("Bam" "Bar" "Foo")
###################################################

> Anyway, as the symbol-table/namespace itself is just a big
> hash-table, then all we would need are: + a way to create a new
> namespace + check if a variable exists in that namespace + get or set
> a variable in that namespace
> 
[...]

Cheers,
José
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to