Rebol Programming/forskip

USAGE: edit

FORSKIP 'word skip-num body 

DESCRIPTION: edit

Evaluates a block for periodic values in a series.

FORSKIP is a function value.

ARGUMENTS edit

  • word -- Word set to each position in series and changed as a result (Type: word)
  • skip-num -- Number of values to skip each time (Type: integer)
  • body -- Block to evaluate each time (Type: block)

(SPECIAL ATTRIBUTES) edit

  • throw
  • catch

SOURCE CODE edit

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
    ]
]