Welcome to the CHICKEN Scheme pasting service
iota revisited added by elflng on Wed Sep 16 11:30:12 2020
(define (iota count . maybe-start+step)
; (check-arg integer? count iota)
(##sys#check-number count 'iota)
(if (< count 0) (##sys#error 'iota "Negative step count" iota count))
(let-optionals maybe-start+step ((start 0) ; Olin, I'm tired of fixing your stupid bugs - why didn't
(step 1) ) ; you use your own macros, then?
(##sys#check-number start 'iota)
(##sys#check-number step 'iota)
; (check-arg number? start iota)
; (check-arg number? step iota)
(if (= 0 count)
'()
(let loop ((count count)
(val (+ start (* (- count 1) step)))
(ans '()))
(if (= 1 count)
(cons start ans)
(loop (- count 1) (- val step) (cons val ans)))))))