How about this?
    collector: func [args [block!] init [series!] code [block!]] [
        args: union args [/local out emit]
        func args compose [
            out: copy (reduce [init])
            emit: func [val] [
                repend out val
            ]
            (code)
            out
        ]
    ]
    "explicit"
    double: collector [series] [] [
        foreach num series [
            emit 2 * num
        ]
    ]
    probe double [1 2 3 4]
    "inline"
    probe do collector [] [] [foreach num [1 2 3 4] [emit 2 * num]]


On 5/12/06, Ladislav Mecir <[EMAIL PROTECTED]> wrote:
>
> Gregg Irwin napsal(a):
> > ; Accepts only word! and block! values for args now.
> >
> > ; Uses 'ins as the name for the first value in the function body.
> > ; and its value is set just before the function is made (for
> > ; visual context).
> >
> >
> ; two comment typos corrected
>
>     collect: func [
>         [throw]
>         {Collects values, returning them as a series.}
>         'emit [word!]  "Word used to collect values"
>         block [block!] "Block to evaluate"
>         /into dest [series!] "Where to append results"
>         /only "Insert series values as series"
>     ] [
>         ; Create a new context containing just one word (the EMIT
>         ; argument) and set the 'emit word to refer to the new context
>         ; word. Note the care taken to suppress possible conflicts and
>         ; undesired evaluations.
>         emit: reduce [emit]
>         emit: first use emit reduce [emit]
>         use [dst ins] copy/deep [
>             ; copy/deep lets us use just as the fallback value [] here.
>             dst: any [:dest []]
>             ; make the function used to collect values.
>             ins: either only [[insert/only]] [[insert]]
>             set emit func [value [any-type!]] compose [
>                 (ins) tail :dst get/any 'value
>                 get/any 'value
>             ]
>             do bind/copy block emit
>             head :dst
>         ]
>     ]
>
> -L
>
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
>
>


--=20
-Volker

"Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem." David
Wheeler
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to