跳轉到內容

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
    ]
]
華夏公益教科書