t3x.org / nss / iota.html

(Nils' Scheme Snippets)

 
Paren matching: OFF  |  Category: lists  |  Overview  |  Scheme Books  |  License
 

(iota integer1 integer2) => list

 
Purpose
Create ranges of integers.
 
Arguments
l least integer in range
h greatest integer in range
 
Example
(iota 17 21) => (17 18 19 20 21)
(define (iota l h)
  (letrec
    ((j (lambda (x r)
          (cond ((= x l) (cons l r))
                (else (j (- x 1) (cons x r)))))))
    (cond ((> l h) (wrong "iota: bad range" (list l h)))
          (else (j h '())))))

Copyright (C) 2007 Nils M Holm <nmh @ t3x . org>