Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.lisp
Re: beggining lisp
William James
12/30/2015 12:15:00 AM
Nicolas Neuss wrote:
> > CL-USER> (defun fib (n)
> > (loop for x below n
> > for a = 0 then b
> > and b = 1 then (+ a b)
> > finally (return b)))
> > CL-USER> (mapcar #'fib (loop for x from 1 upto 20 collecting x))
> > (1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765)
> > CL-USER>
>
> 0-th Fibonacci is 0, IIRC. Furthermore, the use of loop's repeat clause is
> appropriate here. Thus,
>
> (defun fib (n)
> (loop repeat n
> for a = 0 then b
> and b = 1 then (+ a b)
> finally (return a)))
MatzLisp (Ruby):
def fib n
a,b = 0,1
n.times{ a,b = b,a+b}
a
end
8.times{|i| p [i, fib(i)]}
[0, 0]
[1, 1]
[2, 1]
[3, 2]
[4, 3]
[5, 5]
[6, 8]
[7, 13]
--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunk...
https://www.youtube.com/watch?v=E...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: beggining lisp
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password