Re: DEFUN list argument

Liste des GroupesRevenir à cl scheme 
Sujet : Re: DEFUN list argument
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 29. Sep 2024, 01:52:08
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vda8bn$1f4vl$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
(defun list-of-length (n list)
  "Predicate which tests whether LIST is a list
of length N."
  (loop for i from 0 below n
        when (null list) do (return nil)
        do (pop list)
        finally (return (null list))))

Instead of using a macro whose source measures 60 kilobytes,
we can make it shorter by simply using recursion.  Of course,
that's not possible in CL since it's not a Lispy language and
doesn't offer tail-call optimization. (Lispy languages
encourage recursive solutions.)

Scheme:

(define (list-of-length? n lst)
  (cond ((zero? n)  (null? lst))
        ((null? lst) #f)
        (#t (list-of-length? (- n 1) (cdr lst)))))

Date Sujet#  Auteur
29 Sep 24 * Re: DEFUN list argument3B. Pym
29 Sep 24 `* Re: DEFUN list argument2Kaz Kylheku
29 Sep 24  `- Re: DEFUN list argument1Axel Reichert

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal