Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

She is not refined. She is not unrefined. She keeps a parrot. -- Mark Twain


comp / comp.lang.lisp / Re: beggining lisp

SubjectAuthor
o Re: beggining lispB. Pym

1
Subject: Re: beggining lisp
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Tue, 27 Aug 2024 23:31 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: beggining lisp
Date: Tue, 27 Aug 2024 23:31:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <valnkn$35t58$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Wed, 28 Aug 2024 01:31:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="041112d065965f343e15ec8c67e04ac3";
logging-data="3339432"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1xh1MWxdHBlMiOW/6LpJQ"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:72BPQG/MQNtc9Kj0gGHZTKMZPYA=
View all headers

> After a bit of effort, my first working lisp code which is slightly more
> complex than printing "hello", it returns the nth fibonacci number.
> How would you lisp gurus have written the code in the proper lisp way.
>
> (defun fib (n)
> (let ( (f0 0) (f1 1) (counter 1) )
> (loop
> (if (>= counter n) (return-from fib f1) )
> (let* ( (tmp f0) )
> (setf f0 f1) (setf f1 (+ f1 tmp)) (incf counter)))))

Gauche Scheme

(define (nth-fib n)
(do ((n n (- n 1))
(a 0 b)
(b 1 (+ a b)))
((zero? n) b)))

(map nth-fib (iota 9))
===>
(1 1 2 3 5 8 13 21 34)

1

rocksolid light 0.9.8
clearnet tor