Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you insert declarations into loops?

6 views
Skip to first unread message

Robert L.

unread,
Dec 9, 2017, 3:43:48 PM12/9/17
to
Thomas A. Russ 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))

(map cdr '((a . 2) (b . 3)))
===>
'(2 3)


--
Jews in America are 100 percent united in demanding "open borders" and
"immigration reform", but at the same time hypocritically support Israel
which now uses DNA tests on potential immigrants in order to keep the Jewish
state racially pure. http://archive.org/details/nolies
0 new messages