[REBOL] Re: COLLECTing results
From: brett:codeconscious at: 24-Jul-2003 22:06
Don't you just hate it when after testing, trying some more and some more
testing you press Send and then test think "Oh no!". The last version worked
for Repeat but not for Foreach - and I still don't know why. This one seems
to work however.
>> repeat i 10 collect [i]
== [1 2 3 4 5 6 7 8 9 10]
>> for i 1 10 2 collect [i * 10]
== [10 30 50 70 90]
>> foreach [a b] [1 2 3 4] collect [a + b]
== [3 7]
>> foreach w [a b c d] collect [w]
== [a b c d]
collect: func [
{Collects block evaluations, use as body in For, Repeat, etc.}
block [block!] "Block to evaluate."
/init result "Initialise the result series."
/only "Inserts into result using Only refinement."
] [
result: any [result make block! 100]
reduce [
'head pick [insert insert/only] not only 'tail result to paren!
block
]
]
Regards,
Brett.