[REBOL] Re: Passing hash keys to functions
From: premshree::pillai::gmail::com at: 29-Dec-2004 16:25
On Wed, 29 Dec 2004 20:31:15 +1300, Carl Read <[carl--cybercraft--co--nz]> wrote:
> Hi Premshree,
>
> On Wednesday, 29-December-2004 at 3:18:10 Premshree wrote,
>
> >On Tue, 28 Dec 2004 16:16:14 EST, [SunandaDH--aol--com] <[SunandaDH--aol--com]>
> >wrote:
> >>
> >> Premshree:
> >>
> >> > I'm trying to write a function that accepts a key as an argument, and
> >> > then returns the corresponding value.
> >>
> >> You might be better off with the keys as strings rather than words:
> >>
> >> hsh: make hash! ["a" [1 2] "b" [3 4]]
> >>
> >> The code hardly needs a function:
> >>
> >> select hsh "b"
> >> == [3 4]
> >
> >Ah, I din't know of the existence of a select. :-|
>
> Incidentally, if you did use words as your keys (as apposed to strings), you wouldn't
even need SELECT...
>
> >> hsh: make hash! [a [1 2] b [3 4]]
> == make hash! [a [1 2] b [3 4]]
> >> hsh/a
> == [1 2]
> >> hsh/b
> == [3 4]
> >> hsh/b/1
> == 3
> >> hsh/b/2
> == 4
> >> of: 'a no: 1
> == 1
> >> hsh/:of/:no
> == 1
> >> of: 'b no: 2
> == 2
> >> hsh/:of/:no
> == 4
This was what I was using initially. But I need to use this within a
function, and the key is taken as an argument, so I cannot use this
method. Or can I?
> I'm not sure why Sunanda suggested using strings, but I'm sure there's a good reason
- possibly because of the limit to the number of words allowed in REBOL. Or perhaps
for speed reasons. Sunanda?
>
> -- Carl Read.
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.298 / Virus Database: 265.6.6 - Release Date: 12/28/04
>
> --
> To unsubscribe from the list, just send an email to rebol-request
> at rebol.com with unsubscribe as the subject.
>
--
Premshree Pillai
http://www.livejournal.com/~premshree