[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: How do you insert declarations into loops?

William James

5/2/2015 9:35:00 PM

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))

Gauche Scheme:

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

--
Blacks are an estimated 39 times more likely to commit a violent crime against
a white than vice versa, and 136 times more likely to commit robbery. ---
www.colorofcrime.com/2005/10/the-color-of-crime-2005/
Let us be brought to believe it is ... favorable to ... our interest to
transfer the African to his native clime, and we shall find a way to do it,
however great the task may be. --- A. Lincoln, Sept. 22, 1856
1 Answer

William James

12/2/2015 5:03:00 PM

0

WJ wrote:

> 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))

Ocaml:

List.map snd ["a",2; "b",3] ;;

===>
[2; 3]

--
Every passing hour brings the Solar System forty-three thousand
miles closer to Globular Cluster M13 in Hercules---and still
there are some misfits who insist that there is no such thing as
progress. --- Kurt Vonnegut