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

[REBOL] Re: Find/deep

From: ryan:christiansen:intellisol at: 20-Apr-2001 16:17

I learn something every day! :) I, too, was trying to solve this problem and did not realize you could call a function from within the function itself. Nice. My solution was similar, but only recursive to three levels. Here is my clunky solution, including debug output to the console. find-deep: func [a x][ foreach b a [ print rejoin [{b is } b] either all [(block? b) ((length? b) > 1)][ foreach c b [ print rejoin [{c is } c] either all [(block? c) ((length? c) > 1)][ foreach d c [ print rejoin [{d is } d] if find d x [print rejoin [{found } x { in } d]] ] ][ if find c x [print rejoin [{found } x { in } c]] ] ] ][ if find b x [print rejoin [{found } x { in } b]] ] ] ] Once again I realize I should have taken some mathematics and programming classes at the college level. :) -Ryan bill wrote:
> Hi all, > I was wondering if anyone has a function that will do a find/deep > on arrays. > arrays such as [["AA"] [["B"]["C"]] ["DD"]]. > Bill. >
Once again I dig into my chainsaw collection. While not as multipurpose as 'find, this sucker will tell you if its in there. 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 thing haystack [ if thing = needle [ return true] ; Ouch! if all [ block? thing deep-find thing needle ] [ return true] ; Found it deep! ] return false ; Not here! ] Ryan C. Christiansen Web Developer Intellisol International 4733 Amber Valley Parkway Fargo, ND 58104 701-235-3390 ext. 6671 FAX: 701-235-9940 Global Leader in People Performance Software _____________________________________ Confidentiality Notice This message may contain privileged and confidential information. If you think, for any reason, that this message may have been addressed to you in error, you must not disseminate, copy or take any action in reliance on it, and we would ask you to notify us immediately by return email to [ryan--christiansen--intellisol--com]