Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: COLLECTing results

From: brett:codeconscious at: 25-Jul-2003 14:39

> I'm using /Initial for my version of 'Collect, because it's like the > /Initial refinement in the 'Array function:
Sounds good. I'll do the same.
> And the 'datatype! specification allows me to be weird! :)
I'd thought of preallocated series, but not the datatype spec. I'll copy that! :^) ---Romano
> Foreach makes copy/deep on the body block to recurse well (repeat does not > make it)
Ahah. Thank you.
> this can also be: > reduce ['head pick [insert insert/only] not only 'tail result do
> with a small change it can handle also paren! init value under last betas: > > reduce ['head pick [insert insert/only] not only 'tail 'first reduce > [:result] do block]
The [do block], means that the block will be executed during reduce, which is too early. I need it to execute only when the outside control function evaluates it. I don't understand the issue with the paren! init value. Could you give an example how this version of my function will not work? ---latest examples
>> 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]
>> repeat e [a b c %.txt] collect/initial [e] %file
== %fileabc.txt
>> iota: func [n [integer!]][repeat i n collect/initial [i] make block! n] >> iota 10
== [1 2 3 4 5 6 7 8 9 10] ---latest version collect: func [ {Collects block evaluations, use as body in For, Repeat, etc.} block [block!] "Block to evaluate." /initial result [series! datatype!] "Initialise the result." /only "Inserts into result using Only refinement." ] [ if not initial [result: block!] result: any [all [datatype? result make result 1000] result] reduce ['head pick [insert insert/only] not only 'tail result 'do :block] ] Regards, Brett