[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rationalising c[ad]\{2,5\}r.

From: Samuel W. Flint
Subject: Re: Rationalising c[ad]\{2,5\}r.
Date: Wed, 11 Mar 2015 20:35:12 -0500
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (gnu/linux)

Thien-Thi Nguyen <address@hidden> writes:

> I first heard of ‘iota’ in Scheme:
>  (iota 8) => (0 1 2 3 4 5 6 7)
> which was inspired by APL (i believe):
>  https://en.wikipedia.org/wiki/APL_(programming_language)
> although the APL ‘iota’ (written "ι" (U+03b9)) produces
> a 1-based sequence instead of 0-based.  I wonder what the
> Common Lisp idiom for this functionality would be...

(defun ι (n)
         (loop for i from 0 to n collecting i))

At least that's what I've always seen.  I guess you could to something
like the following if you don't want to use LOOP:

(defun ι (n)
         (let ((list '()))
           (do ((i 0 (1+ i)))
               ((= i n) t)
             (push i list))
           (reverse list)))


Samuel W. Flint
address@hidden                  (402) 517-8468      <XMPP>
freenode: swflint
      (9477 D23E 389E 40C5 2F10  DE19 68E5 318E 2665 96F4)
"The most dangerous phrase in the language is, 'We've always done it
this way'."  -- Grace Hopper

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]