Re: beggining lisp

Liste des GroupesRevenir à cl lisp 
Sujet : Re: beggining lisp
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 28. Aug 2024, 01:31:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <valnkn$35t58$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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)

Date Sujet#  Auteur
28 Aug 24 o Re: beggining lisp1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal