[REBOL] Re: [COLLECT] COLLECT function/Examples?
From: tim-johnsons:web at: 12-May-2006 15:07
* Gregg Irwin <greggirwin-mindspring.com> [060512 14:41]:
> 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?
Of course...
Duh! Was thinking it worked like my 'yield function.
I see now. It will be very handy.
FYI:
I'm seeing something strange on my system:
It appears that [throw] is suppressing the docstring.
Remove it or replace with [catch] and the docstring is enabled.
Are you getting the same?
tim
> -- Gregg
>
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
Tim Johnson <tim-johnsons-web.com>
http://www.alaska-internet-solutions.com