From a2c3d3c8380c26c615b7e6a9c67ab467e55d7bfd Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 24 Jan 2017 14:10:30 -0800 Subject: [PATCH] Implement fix:iota. --- src/runtime/fixart.scm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/runtime/fixart.scm b/src/runtime/fixart.scm index 75d183650..fecafb7a9 100644 --- a/src/runtime/fixart.scm +++ b/src/runtime/fixart.scm @@ -118,6 +118,30 @@ USA. (if (not (fix:fixnum? n)) (error "Unable to compute smallest fixnum:" n)) n))))) + +(define (fix:iota count #!optional start step) + (guarantee index-fixnum? count 'fix:iota) + (let ((start + (if (default-object? start) + 0 + (begin + (guarantee fix:fixnum? start 'fix:iota) + start))) + (step + (if (default-object? step) + 1 + (begin + (guarantee fix:fixnum? step 'fix:iota) + step)))) + (let loop + ((index (fix:- count 1)) + (value (fix:+ start (fix:* step (fix:- count 1)))) + (result '())) + (if (fix:>= index 0) + (loop (fix:- index 1) + (fix:- value step) + (cons value result)) + result)))) ;;;; Flonums -- 2.25.1