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

[REBOL] Re: Problem with 'collect?

From: AJMartin:orcon at: 17-Aug-2003 20:07

Brett wrote:
> Perhaps Gabriele's comment on my original collect function is the key to
your problem? - Gabriele wrote:
> > Small note: you should bind your RESULT word to a fresh context (USE,
etc.), otherwise you'll be relying on COLLECT's context not being modified while the body block is getting evaluated. Thanks for the hint from Gabriele, Brett. Collect: func [ {Collects the results of block evaluations.} Block [block!] "The block to 'do." /Only "Inserts the result as a series." /Full "Don't ignore none! values." /Initial Type [series! datatype!] "Specifies the type of the result." ] [ use [Break Result Results] [ Break: func [ "Breaks out of the 'Collect." /Return "Forces the loop function to return a Value." Value [any-type!] ] [ system/words/break/return either Return [ Value ] [ Results ] ] Results: any [ all [ datatype? Type make Type 0 ] Type copy [] ] compose/deep [ if not any [ unset? set/any 'Result do [(bind Block 'Break)] (pick [[none? :Result] []] not Full) ] [ (pick [insert insert/only] not Only) tail Results :Result Results ] Results ] ] ] With this script: probe foreach Row [[A 1 B 2] [A 11 B 12]] collect [ reform selects Row [A B] ] I get this result: ["1 2" "11 12"] Which is right! :) Andrew J Martin Learning from The Matrix... ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/