Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Passing hash keys to functions

From: carl:cybercraft at: 29-Dec-2004 11:52

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 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.