From: Kyle M on
Here's a question for the loopers. Say I'm using loop destructuring
like this:

(defun foo (some-list)
(loop for (a b c) in some-list
do ;; code that uses a and c, but not b:
(print a) (print c)))

(compile 'foo) -> Warning: Variable b is never used.

I know that in a destructuring-bind or a multivalue-bind you can just
throw a (declare (ignore b)) in there. Is there any way to ignore this
variable?

I'm using Allegro CL in case yer wondering.

Kyle
From: Kenneth Tilton on
Kyle M wrote:
> Here's a question for the loopers. Say I'm using loop destructuring
> like this:
>
> (defun foo (some-list)
> (loop for (a b c) in some-list
> do ;; code that uses a and c, but not b:
> (print a) (print c)))
>
> (compile 'foo) -> Warning: Variable b is never used.
>
> I know that in a destructuring-bind or a multivalue-bind you can just
> throw a (declare (ignore b)) in there. Is there any way to ignore this
> variable?

It's kinda weird:

(loop for (a nil c)....

Same as for destructuring-bind, btw.

kt
From: Kyle M on
On Nov 24, 9:33 am, Kenneth Tilton <kentil...(a)gmail.com> wrote:
> Kyle M wrote:
> > Here's a question for the loopers. Say I'm using loop destructuring
> > like this:
>
> > (defun foo (some-list)
> >   (loop for (a b c) in some-list
> >       do ;; code that uses a and c, but not b:
> >         (print a) (print c)))
>
> > (compile 'foo) -> Warning: Variable b is never used.
>
> > I know that in a destructuring-bind or a multivalue-bind you can just
> > throw a (declare (ignore b)) in there. Is there any way to ignore this
> > variable?
>
> It's kinda weird:
>
>     (loop for (a nil c)....
>
> Same as for destructuring-bind, btw.
>
> kt


Thanks. That helps, although I'm a little annoyed by that.

Partially because it looks weird. Although most of my code looks
weird, so that's not a huge deal.

Also, though, because I will wind up using the variable b at some
point later on, and I'd like to give it a name (a descriptive name,
not just b).

Now that I think about it I'm wondering if this is actually an
implementation issue:

(loop for x in '(1 2 3)
return 'nothing))

This will not warn me about not using x (in Allegro).

Kyle
From: russell_mcmanus on
Kyle M <kylemcg(a)gmail.com> writes:

> Here's a question for the loopers. Say I'm using loop destructuring
> like this:
>
> (defun foo (some-list)
> (loop for (a b c) in some-list
> do ;; code that uses a and c, but not b:
> (print a) (print c)))
>
> (compile 'foo) -> Warning: Variable b is never used.

Perhaps the obvious?

(defun foo (some-list)
(loop for (a b c) in some-list
do b
(print a) (print c)))

-russ

From: Tim Bradshaw on
On 2009-11-24 15:00:54 +0000, Kyle M <kylemcg(a)gmail.com> said:

> Now that I think about it I'm wondering if this is actually an
> implementation issue:
>
> (loop for x in '(1 2 3)
> return 'nothing))
>
> This will not warn me about not using x (in Allegro).

I think it is, probably, not an implementation issue, but I am not sure.

For DOTIMES (for instance) it is explicitly undefined whether each
variable is rebound for each iteration or whether there is only one
binding per variable. This means it is undefined whether the variable
is ignored or not if you do not use it. Simplifying to the point of
being wrong, the difference is between something like:

(...
(let ((i ...))
...your code...))

And

(...bind i...
(locally
...your code...)
...
(incf i)
...)

In the latter case, I is *not* ignored even if your code does not use it,

For LOOP, I *think* it is clear that the expansion is more like the
second case. So the variables are not ignored, even if your code does
not use them. However I am not sure that this is required to be the
case: I think it probably is, but I'm not completely sure.

This can make huge differences for code which returns closures of course.

I can imagine implementations clever enough that they realised that no
*user* code used a binding and warned about that, even though the LOOP
expansion itself did assign to the variable.

I have used "variable" and "binding" sloppily above.