[REBOL] Re: Hashes in Rebol
From: nitsch-lists:netcologne at: 9-Dec-2003 21:09
Am Dienstag 09 Dezember 2003 15:59 schrieb Andreas Bolka:
> Tuesday, December 9, 2003, 12:47:53 PM, Konstantin wrote:
> > Once again sorry for question which may be obvious for experienced
> > Rebol programmers, but how can I
> >
> > 1. Remove <key, value> pair from hash
>
> remove/part find hash key 2
>
> > 2. Change value associated with the particular key
>
> change find/tail hash key newvalue
some notes when used to "usual" hash-tables:
1) there is /skip for find and such. If you have the same type for key and
data, that helps. then:
find/skip block key 2
instead of
find block key
with different types it does not matter, because 'fid is type-sensitive.
2) use /only when adding blocks to blocks. append/only, change/only.
>> append to-hash[1 2 3] [4 5] ; wrong
== make hash! [1 2 3 4 5]
>> append/only to-hash[1 2 3] [4 5] ;right
== make hash! [1 2 3 [4 5]]
3), when changing/adding items first check if they are pesent. in other
languages old keys are overwritten, rebol wants a user-check.
;to add something
either pos: find/tail hash key [
change/only pos value
] [
repend hash [key value] ; = append hash reduce[key value]
]
-Volker