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

[REBOL] Re: COLLECTing results

From: AJMartin:orcon at: 24-Jul-2003 18:32

> >> foreach [a b] [1 2 3 4] collect [a + b] > == [3 7]
Unfortunately, it fails in this case:
>> foreach [a b] [1 2 3 4] collect [print a print b a + b]
1 2 3 4 == [unset unset] But this version:
>> collect: func [
[ {Collects block evaluations, use with For, Repeat, etc.} [ block [block!] [ /init result "Initialise the result series." [ /only "Inserts into result using Only refinement." [ ] [ [ if empty? block [return block] [ compose/deep [ [ result: any [result make block! 100] [ (pick [insert/only insert] found? only) tail result do [(block)] [ result [ ] [ ] ...works bettter:
>> foreach [a b] [1 2 3 4] collect [print a print b a + b]
1 2 3 4 == [3 7] :) Note: compose/deep and: do [(block)] Andrew J Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/