Type decl vs fixnum added by dieggsy on Thu Sep 17 10:05:03 2020

(import miscmacros
        chicken.fixnum)

(define (vector-iota count #!optional (start 0) (step 1))
  (if (negative? count)
      #()
      (let ((vec (make-vector count)))
        (do ((i 0 (+ (the fixnum i) 1))
             (val start (+ val step)))
            ((= i count))
          (vector-set! vec i val))
        vec) ))

(: vector-iota* (fixnum #!optional fixnum fixnum -> (vector-of fixnum)))
(define (vector-iota* count #!optional (start 0) (step 1))
  (if (negative? count)
      #()
      (let ((vec (make-vector count)))
        (do ((i 0 (+ (the fixnum i) 1))
             (val start (+ (the fixnum val) (the fixnum step))))
            ((= (the fixnum i) (the fixnum count)))
          (vector-set! vec i val))
        vec) ))

(define (vector-iota** count #!optional (start 0) (step 1))
  (if (negative? count)
      #()
      (let ((vec (make-vector count)))
        (do ((i 0 (fx+ (the fixnum i) 1))
             (val start (fx+ val step)))
            ((fx= i count))
          (vector-set! vec i val))
        vec) ))

(time
 (dotimes (i 10000)
   (vector-iota 10000)))

(time
 (dotimes (i 10000)
   (vector-iota* 10000)))

(time
 (dotimes (i 10000)
   (vector-iota** 10000)))