Nobody uses For to traverse a series, I guess. OTOH, the
implementation of For should be correct. (apologizing, if it was
discussed before) My correction to the series traversing part of
For is as follows:
for: func [
"Repeats a block over a range of values." [catch throw]
'word [word!] "Variable to hold current value"
start [number! series! money! time! date! char!] "Starting
value"
end [number! series! money! time! date! char!] "Ending value"
bump [number! money! time! char!] "Amount to skip each time"
body [block!] "Block to evaluate"
/local result do-body op cond
][
if (type? start) <> (type? end) [
throw make error! reduce ['script 'expect-arg 'for 'end
type? start]
]
do-body: func reduce [[throw] word] body
op: either positive? bump [:greater-or-equal?][
:lesser-or-equal?
]
either series? start [
if not same? head start head end [
throw make error! reduce ['script 'invalid-arg end]
]
cond: op index? end index? start
while [cond] [
set/any 'result do-body start
cond: op index? end (index? start) + bump
start: skip start bump
]
] [
while [op end start] [
set/any 'result do-body start
start: start + bump
]
]
get/any 'result
]
; Example:
a: [1 2]
for s a tail a 1 [print s]
for s a next a -1 [print s]
Opinions?