this is a variant proposed by Gabriele (note the usage of the /only 
refinement):

    collect: closure [
        {Collects values, returning them as a series.}
        [throw]
        emit [word!]  "Word used to collect values"
        block [block!] "Block to evaluate"
        /into dest [series!] "Where to append results"
    ] [
        ; 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]
        dest: any [:dest []]
        ; make the function used to collect values.
        set emit func [value [any-type!] /only] [
            either only [insert/only tail :dest get/any 'value] [
                insert tail :dest get/any 'value
            ]
            get/any 'value
        ]
        do bind/copy block emit
        head :dest
    ]

probe collect 'emit [emit [1 2] emit/only [3 4]] ; == [1 2 [3 4]]

-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to