Subject: Bug in loop..?

From: Rob <[email-masked]>
Date: Tue, 24 Mar 1998 20:36:00 -0500

I've been struggling with some code that I've been cutting over to CLISP,
and I've come across something that looks like a bug.

In the CLtL2 text on page 745 I found this:

(loop for i from 1 to 10 
      when (> i 5) 
      collect i
      finally (print i))

returns
11
(6 7 8 9 10)

which works fine. I tried it because the following does not:

(loop for i in '(1 2 3 4 5 6 7 8 9 10) 
      when (> i 5) 
      collect i
      finally (print i))

returns
*** - EVAL: variable I has no value

Is this correct behaviour, or is there something wrong with one of the
environments, caused perhaps by the 'in' ?

Please let me know if there is a fix, or this is not supported.

Thanks.

---

From: Bruno Haible <[email-masked]>
Date: Thu, 26 Mar 1998 15:26:52 +0100 (MET)

[email-masked] writes:
> the following does not [work]:
> 

What are you trying to do anyway in the finally clause? Accessing the value
of an element which is not on the list? In some implementations you might
get 10, in some implementations you might get NIL. In CLISP you get an
error because the situation is just too hairy to be supported.

Bruno

---

From: Rob <[email-masked]>
Date: Thu, 26 Mar 1998 15:39:46 -0500

>What are you trying to do anyway in the finally clause? 

Well, this was just a simplified example. I'm actually running through a
larger list that looks something like: ((a 5) (b 8) c)

Until the point that a non-list is hit, the variable is pointing to the
last list. At the end, finally actually returns (second i). So, I'm
returning the second element of the last list in the larger list. In MCL,
where this thing originated, it works (and the previous example returns 10).

Rather than re-write it immediately, I tried the simple example with the
'from' 1..10. When I saw that it worked but the 'in' didn't, I figured it
for a bug. Not a big deal really, I try to get it another way. Hopefully
the code doesn't rely on this 'technique' too often! :)

Thanks.