Brian Downing <see-signature@lavos.net> wrote:
+---------------
| Coby Beck <cbeck@mercury.bc.ca> wrote:
| > What's this IOTA beast?
|
| Traditionally, something like:
| (defun iota (n)
| (loop for i below n collect n))
+---------------
Yup. It seemed obvious, so I neglected to mention it, sorry.
The version in my personal toolbox only a tiny bit more general
than Coby's, and matches versions I have seen elsewhere [though
there is considerable controversy over just what the "right" args
are for IOTA, though I prefer these, obviously]:
(defun iota (count &optional (start 0) (step 1))
(loop repeat count for i from start by step collect i))
It's especially convenient to generate test input data interactively:
(iota 5) ==> (0 1 2 3 4)
(iota 5 7) ==> (7 8 9 10 11)
(iota 5 7 3) ==> (7 10 13 16 19)
(iota 5 2 -1) ==> (2 1 0 -1 -2)
(iota 5 1 0) ==> (1 1 1 1 1)
(coerce (mapcar #'code-char (iota 10 65)) 'string) ==> "ABCDEFGHIJ"
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607