跳轉到內容

Rebol 程式設計/collect

來自華夏公益教科書,開放的書籍,為開放的世界
COLLECT body /into output 

評估一個程式碼塊,透過 KEEP 函式儲存值,並返回收集到的值的程式碼塊。

COLLECT 是一個函式值。

  • body -- 要評估的程式碼塊(型別:程式碼塊)
  • /into -- 插入到緩衝區中(返回插入後的位置)
    • output -- 緩衝區系列(已修改)(型別:系列)

原始碼

[編輯 | 編輯原始碼]
collect: func [
    {Evaluates a block, storing values via KEEP function, and returns block of collected values.} 
    body [block!] "Block to evaluate" 
    /into {Insert into a buffer instead (returns position after insert)} 
    output [series!] "The buffer series (modified)"
][
    unless output [output: make block! 16] 
    do make function! [keep] copy/deep body make function! [value /only] copy/deep [
        output: either only [insert/only output :value] [insert output :value] 
        :value
    ] 
    either into [output] [head output]
]
華夏公益教科書