[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: better way to enumerate

William James

1/7/2016 9:48:00 AM

Kaz Kylheku wrote:

> (defun enumerate-with-op-iter (start end &aux elist)
> (loop
> ;; test terminating condition, return result
> (when (> start end)
> (return (reverse elist)))
> ;; update variables for next iteration
> (psetf
> start (1+ start)
> elist (cons start elist)))))

MatzLisp (Ruby):

The hard way:

def number_sequence low, high
result = []
while low <= high
result << low
low += 1
end
result
end

The easy way:

(low .. high).to_a

Another way:

low.upto(high).to_a

--
[A]n unholy alliance of leftists, capitalists, and Zionist supremacists has
schemed to promote immigration and miscegenation with the deliberate aim of
breeding us out of existence in our own homelands.... [T]he real aim stays the
same: the biggest genocide in human history.... --- Nick Griffin
(https://www.youtube.com/watch?v=K...)