[REBOL] Re: Find on a nested structure
From: ryanc::iesco-dms::com at: 11-Apr-2001 10:58
Ah, very good points Scott, and clean solution. Using deep-find for that is
like using a chainsaw to prune a rose bush.
--Ryan
GS Jones wrote:
> From: <[Sanghabum--aol--com]>
> <snip>
> > Can you guys help me on this one?
> >
> > I've got a structure like this:
> >
> > MyStructure: [ [key1 data1] [key2 data2] [key3 data3] ... ]
> >
> > where each Key is a single string, but the Data is another block.
> >
> > Example:
> >
> > MyStructure: [
> > ["US" ["USA" "English" "Spanish"] ]
> > ["DE" ["Germany" "German"] ]
> > ["NZ" ["New Zealand" "English"] ]
> > ]
> >
> >
> > I can't find any way to use Find to find me a given key:
> >
> > >> find MyStructure "US"
> > == none
> > >> find MyStructure ["US"]
> > == none
> >
> > Is there something I can do with Find?
> >
> > I don't want to change the structure to
> >
> > MyStructure: [ key1 [data1] key2 [data2] key3 [data3] ... ]
> >
> > which is Find-able, but isn't SORT-able,--or at least not by me.
> >
> > Thanks,
> > Colin.
>
> Hi, Colin,
>
> Been there and agonized over the same things. You are going to be much
> happier if you do your second option. 'Find works more seemlessly and sort
> accomplished using the /skip refinement, such as:
> MyStructure: [
> "US" ["USA" "English" "Spanish"]
> "DE" ["Germany" "German"]
> "NZ" ["New Zealand" "English"]
> ]
>
> sort/skip mystructure 2
>
> ---
> yields
> [
> "DE" ["Germany" "German"]
> "NZ" ["New Zealand" "English"]
> "US" ["USA" "English" "Spanish"]
> ]
>
> If you are intent on the first form (of enclosing each grouping in its own
> block), as far as I know you will need to iterate through the structure and
> perform a 'find on each group, such as:
>
> MyStructure: [
> ["US" ["USA" "English" "Spanish"] ]
> ["DE" ["Germany" "German"] ]
> ["NZ" ["New Zealand" "English"] ]
> ]
> foreach s mystructure [if (find s "US") [print s]] ;yields US USA English
> Spanish
> foreach s mystructure [if (find s "DE") [print s]] ; yields DE Germany
> German
>
> Although I know what I've said is not what you are really looking for, I
> hope the 'sort refinement eases your "pain." (I guess I'll have to "feel
> your pain" since the current US President no longer does!!) I've set up
> very complex and long data structures using this method, and it works great
> (, even without making it a hash).
>
> --Scott Jones
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
I am enough of an artist to draw freely upon my imagination.
Imagination is more important than knowledge. Knowledge is
limited. Imagination encircles the world.
-Einstein