Last active
December 14, 2016 05:47
-
-
Save dockimbel/db32d45ca7fd722c8e92f63b31626234 to your computer and use it in GitHub Desktop.
FORSKIP port from Rebol2 to Red.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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