Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Last active December 14, 2016 05:47
Show Gist options
  • Save dockimbel/db32d45ca7fd722c8e92f63b31626234 to your computer and use it in GitHub Desktop.
Save dockimbel/db32d45ca7fd722c8e92f63b31626234 to your computer and use it in GitHub Desktop.
FORSKIP port from Rebol2 to Red.
Red [
Title: "FORSKIP function"
Author: "Nenad Rakocevic"
Purpose: "Direct port of the REBOL2 forskip function"
]
forskip: func [
"Evaluates a block for periodic values in a series."
'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
][
unless positive? skip-num [cause-error 'script 'invalid-arg reduce [skip-num]]
unless any [
series? get word
port? get word
][cause-error 'user 'message ["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
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment