Hi Gregg,
On Wednesday, May 10, 2006, 11:23:19 PM, you wrote:
GI> How does it work?
GI> It takes a word and a block as arguments. Anytime the word appears
GI> as a set-word! in the block, the value assigned to it is
GI> "collected".
GI> The above func would look like this:
GI> fn: func [series] [
GI> collect v [foreach val series [v: val]
GI> ]
Hmm, interesting. Alternative approach:
use [out] [
out: []
collect: func [body /into output] [
output: any [:output make block! 16]
; allows recursive usage
set [out output] reduce [output out]
do body
set [out output] reduce [output out]
output
]
emit: func [value] [repend out :value :value]
]
(If you make OUT global you also have a "global" collect)
GI> collect zz [repeat i 10 [if (zz: i) >= 3 [break]]]
>> collect [repeat i 10 [if 3 <= emit i [break]]]
== [1 2 3]
GI> dest: copy []
GI> collect/into zz [repeat n 10 [zz: n * 100]] dest
>> dest: copy []
== []
>> collect/into [repeat n 10 [emit n * 100]] dest
== [100 200 300 400 500 600 700 800 900 1000]
GI> iota: func [n [integer!]][collect zz [repeat i n [zz: i]]]
>> iota: func [n [integer!]] [collect [repeat i n [emit i]]]
>> iota 10
== [1 2 3 4 5 6 7 8 9 10]
GI> dest: copy ""
GI> collect/into zz [repeat n 10 [zz: n * 100 zz: " "]] dest
>> dest: copy ""
== ""
>> collect/into [repeat n 10 [emit [n * 100 " "]]] dest
== "100 200 300 400 500 600 700 800 900 1000 "
Regards,
Gabriele.
--
Gabriele Santilli <[EMAIL PROTECTED]> --- http://www.rebol.com/
Colella Chiara software division --- http://www.colellachiara.com/
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.