That last little booger I posted didnt let you update values, and crashed when you
asked it a stupid question.  This updated version lets you update values, and
returns none when you ask it about a key it has not encountered:

assoc: make object! [
  list: copy[]
  clear: func[][list: copy[]]
  set: func[key value][
    if get key[unset key]
    append list key
    append/only list reduce[value]
  ]
  get: func[key] [
    rv: none
    error? try [rv: first select list key]
    :rv
  ]
  unset: func [key][remove/part find list key 2]
]

You still want to be careful when using block keys.

[EMAIL PROTECTED] wrote:

> This little booger might be handy too.  Though it has one peculiarity, dont use
> blocks as keys when values might match the contents of the block key.
>
> assoc: make object! [
>   list: copy []
>   clear: func [] [list: copy []]
>   set: func [key value] [ append list key append/only list reduce [value]]
>   get: func [key /rv] [ first select list key  ]
>   unset: func [key] [ remove/part find t key 2 ]
> ]
>
> --Ryan
>
>      Ryan Cole
>  Programmer Analyst
>  www.iesco-dms.com
>     707-468-5400
>
> The Tao that can be expressed
> is not the eternal Tao. -Lao Tzu

--ya ya ya


     Ryan Cole
 Programmer Analyst
 www.iesco-dms.com
    707-468-5400

The problem of language here are really serious.
We wish to speak in some way about the structure
of the atoms . . . But we cannot speak about atoms
in ordinary language. -W. Heisenberg


Reply via email to