[REBOL] Re: hash code for object ?
From: tim-johnsons:web at: 6-Jun-2007 8:36
On Wednesday 06 June 2007, Gregg Irwin wrote:
> Hi Arnaud,
>
> AG> Is there something like an hashcode for object in rebol as we have in
> AG> java ?
>
> Forgot to include an example of how to make hash! values. You either
>
> need to to MAKE, TO, or the serialized format:
> >> make hash! [1 2 3 4 5]
>
> == make hash! [1 2 3 4 5]
>
> >> to hash! [1 2 3 4 5]
>
> == make hash! [1 2 3 4 5]
>
> There is also a list! type. Both hash! and list! are covered in the
> Core manual in more detail as well.
Python has a dictionary type, which is sort of a hash implemented
as a btree.
One of the gotchas can be illustrated as follows:
>> H: make hash! [4 1 1 4]
== make hash! [4 1 1 4]
>> select H 1
== 1
;; if you think of 'H as a series of pairs, the python corollary would
;; return 4
;; The fix would be:
>> first select/skip H 1 2
== 4
;; which is easily implemented in a function such as:
mate: def["Finds an odd-numbered value in a series"
" and returns the value after it (the 'mate')"
[catch] b[series!] v[any-type!]][
res: select/skip b v 2
either block? res[first res][res]
]
;; Note my use of 'def and the multiple docstring :-)
tim