[REBOL] Re: Passing hash keys to functions
From: premshree:pillai::gmail at: 29-Dec-2004 3:45
Yeah, I realised that (as posted in the earlier reply)
Thanks!
On Tue, 28 Dec 2004 14:07:09 -0800 (PST), Tom Conlin
<[tomc--darkwing--uoregon--edu]> wrote:
>
> Hi Premshree
>
> if 'select returns a series you can just again 'select form that series
>
> >> select select hsh "a" 1
> == 2
>
> is that what you were wondering?
>
> (where what you are reffering to as a hash could be any series in rebol)
>
> >> h1: ["a" [ 123 456 789] "b" ["foo" "bar" "ack"] "c" "whatever"]
> >> select select h1 "a" 123
> == 456
> >> select select h1 "b" "bar"
> == "ack"
> >> select select h1 "c" "e"
> == #"v"
>
> On Wed, 29 Dec 2004, Premshree Pillai 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. :-|
> >
> > I'm a bit confused as to how to use it for keys that have values as
> > hashes, though. If I have something like:
> >
> > hsh: make hash! ["a" [1 2] "b" [3 4]]
> >
> > How do I do something like hsh->"a"->1?
> >
> > TIA
> > >
> > > But if you want one:
> > >
> > > get-val: func [of [hash!] key [string!]
> > > ][
> > > return select of key
> > > ]
> > >
> > > get-val hsh "b"
> > > == [3 4]
> > >
> > > Sunanda
> > > --
> > > 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
> > --
> > To unsubscribe from the list, just send an email to rebol-request
> > at rebol.com with unsubscribe as the subject.
> >
> --
> 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