Subject: Re: builtin for generating list?
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 13 May 2008 23:30:20 -0500
Newsgroups: comp.lang.lisp
Message-ID: <_6WdnaHLPoBB97fVnZ2dnUVZ_sHinZ2d@speakeasy.net>
<philip.armitage@gmail.com> wrote:
+---------------
| globalrev <skanem...@yahoo.se> wrote:
| > if i want a list with the numbers between x and y is there a buil in
| > function to generate this?
| >
| > in python i can say range(x,y,step) so i can do:
| > map(lambda x:x*x*x,range(1,101,2)) which creates a list with all the
| > cubes of the odd numbers between 1 and 100.
| 
| Untested but something like:
| 
| (defun range (start end &optional (step 1))
|   (loop for n from start below end by step collect n))
| (mapcar (lambda (x) (* x x x)) (range 1 101 2))
+---------------

Here's mine, which is *very* similar but with a slightly different
signature which better matches the way I tend to use it:

    (defun iota (count &optional (start 0) (step 1))
      (loop repeat count for i upfrom start by step collect i))

    (mapcar (lambda (x) (* x x x)) (iota 100 1 2))


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607