A tiny Lisp script, noticed first in a recent post in comp.lang.lisp and then ported to SBCL:
% cat ~/bin/iota
#!/usr/local/bin/sbcl --script
(defun iota (count &optional (start 0) (step 1))
"Build a list of `count' numbers, starting from `start' and
incrementing by `step' between successive elements."
(loop repeat count for i from start by step collect i))
(format t "~{~a~^ ~}~%"
(apply 'iota (mapcar #'read-from-string (rest *posix-argv*))))
Running this from a shell prompt works fine in SBCL 1.0.25:
% iota 10 0 1 2 3 4 5 6 7 8 9 % iota 10 1 1 2 3 4 5 6 7 8 9 10
It even works with float step values, which is a bit cool:
% iota 10 0 1d-2 0 0.01d0 0.02d0 0.03d0 0.04d0 0.05d0 0.06d0 0.07d0 0.08d0 0.09d0
It is good style to use REDUCE instead of APPLY.
foo In general, I would agree, but not in this case.
#'iotaexpects 3 arguments, and#'reducewould do something slightly odd; it would pass only the first two *posix-argv* elements, then pass the result and the third *posix-argv* element, and so on…Just passing by.Btw, your website have great content!
_________________________________
Making Money $150 An Hour