Re: How do you insert declarations into loops?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: How do you insert declarations into loops?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 25. Jun 2025, 20:58:21
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103hkcq$2vmml$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
B. Pym wrote:

 > How do you insert declarations into loops?
 >
 > Example:  This function loops over a list of associations
 > collecting the cdrs.
 >
 >    (defun list-cdrs (list)
 >      (loop for (unwanted-var . wanted-var) in list
 >            collect wanted-var))
 >
 > When I compile list-cdrs, I get an "unused lexical variable, UNWANTED-VAR"
 > message (this is fine.).  Normally, if I wanted to inhibit this
 > warning I would stick a (declare (ignore unwanted-var)) in the
 > beginning of the function body immediately following the declaration.
 > It doesn't seem that you can do this using loop.
 
The solution is not to introduce an ignore declartion, but instead to
use a hack in the destructuring pattern matcher:
 
    (defun list-cdrs (list)
      (loop for (NIL . wanted-var) in list
            collect wanted-var))
 
Scheme
 
(map cdr '((a . 2) (b . 3)))
 ===>
'(2 3)

Is it true that users of CL inspired the movie "Idiocracy"?
 


Date Sujet#  Auteur
23 Jun 25 * Re: How do you insert declarations into loops?2B. Pym
25 Jun 25 `- Re: How do you insert declarations into loops?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal