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

[REBOL] Re: [COLLECT] COLLECT function/Examples?

From: greggirwin:mindspring at: 12-May-2006 16:28

Hi Tim, TJ> I've tried using this, but am unsure how. Can you give some TJ> examples?
>> b: [1 2 3 4 5 6 7 8 9 10]
== [1 2 3 4 5 6 7 8 9 10]
>> collect n [foreach [x y] b [n add x y]]
== [3 7 11 15 19] COLLECT returns a block. The word you give it is the "collector function"; wherever that word appears in the block, a value will be collected. It's main goal is to eliminate tedious code. e.g. fn: func [/local res] [ res: copy [] foreach ... [append res value] res ] becomes: fn: does [collect [foreach val ... [val value]] Does that make sense? -- Gregg