Highly ineffective :-) I already suggested find/deep (or 'locate), which
would return block of position or lit-path to be implemented in 'native C
level code ...

-pekr-

----- Original Message -----
From: "Ryan Cole" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, April 11, 2001 7:24 PM
Subject: [REBOL] Re: Find on a nested structure


> This should work, although it could be alot better.  --Ryan
>
> ;;;;;;;;;;;;;;;;;;;;;;;;
> MyStructure: [
>           ["US" ["USA" "English" "Spanish"]  ]
>           ["DE"  ["Germany" "German"]  ]
>           ["NZ" ["New Zealand" "English"]  ]
>            ]
>
>
> OtherStructure: [
>   words [ a b c ]
>   numbers [1 2 3 4 5]
>   blocks-of-strings [ [ "A" "B" "C" "D" "E" ] [ "F" "G" "H" ] ["I"] ]
>   deep-path [
>     etc [ profile [ %/etc/profile ] passwd [%/etc/profile] ]
>     usr [ bin [ X11 [ %X ] ] ]
>   ]
> ]
>
> deep-find: func [
>   "Searches for a particular element in a block, recursing sub-blocks."
>   haystack [block!] "Block to search."
>   needle [any-type!] "Element to search for."
> ][
>   foreach hay haystack [
>     if hay = needle [ return true] ; Ouch!
>     if all [ block? hay deep-find hay needle ] [ return true] ; More
> haystack: (
>   ]
>   return false
> ]
>
>
> confirm join "Find US (TRUE): " deep-find MyStructure "US"
>
> confirm join "Find AU (FALSE): " deep-find MyStructure "AU"
>
> confirm join "Find %X (TRUE): " deep-find OtherStructure %X
>
> confirm join "Find %command.com (FALSE: " deep-find OtherStructure
> %command.com
>
>
> ;;;;;;;;;;;;;;;;;;;;;;;;
>
> [EMAIL PROTECTED] wrote:
>
> > 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.
> > --
> > To unsubscribe from this list, please send an email to
> > [EMAIL PROTECTED] 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
>
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to