跳转到内容

Rebol 编程/forskip

来自维基教科书,开放的书籍,用于开放的世界
FORSKIP 'word skip-num body 

在系列中评估块以获取周期性值。

FORSKIP 是一个函数值。

  • word -- 设置为系列中每个位置的单词,并作为结果而更改(类型:单词)
  • skip-num -- 每次跳过的值的数量(类型:整数)
  • body -- 每次评估的块(类型:块)

(特殊属性)

[编辑 | 编辑源代码]
  • 抛出
  • 捕捉

源代码

[编辑 | 编辑源代码]
forskip: func [
    "Evaluates a block for periodic values in a series." 
    [throw catch] 
    'word [word!] {Word set to each position in series and changed as a result} 
    skip-num [integer!] "Number of values to skip each time" 
    body [block!] "Block to evaluate each time" 
    /local orig result
][
    if not positive? skip-num [throw make error! join [script invalid-arg] skip-num] 
    if not any [
        series? get word 
        port? get word
    ] [throw make error! {forskip/forall expected word argument to refer to a series or port!}] 
    orig: get word 
    while [any [not tail? get word (set word orig false)]] [
        set/any 'result do body 
        set word skip get word skip-num 
        get/any 'result
    ]
]
华夏公益教科书