From: Kenny Tilton
Subject: Loop bug or feature?
Date: 
Message-ID: <s36rc.49273$mX.18584461@twister.nyc.rr.com>
AllegroCL 6.2 for Win:

   (loop for nums on 42 by #'cdddr
       do (print nums))
   => nil

Bug or feature? Jes curious...

kenny


-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application

From: Thomas Schilling
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <2h4cu4F8sjseU1@uni-berlin.de>
Kenny Tilton wrote:

> AllegroCL 6.2 for Win:
> 
>    (loop for nums on 42 by #'cdddr
>        do (print nums))
>    => nil
> 
> Bug or feature? Jes curious...

Same in SBCL, but what do you expect? Doesn't "on" work only on lists?

So: feature.
From: Toomas Altosaar
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <3ef90b62.0405201333.5af5b2b9@posting.google.com>
MCL gives:

 Error: value 42 is not of the expected type LIST.
From: Kenny Tilton
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <808rc.131848$WA4.33561@twister.nyc.rr.com>
Thomas Schilling wrote:
> Kenny Tilton wrote:
> 
> 
>>AllegroCL 6.2 for Win:
>>
>>   (loop for nums on 42 by #'cdddr
>>       do (print nums))
>>   => nil
>>
>>Bug or feature? Jes curious...
> 
> 
> Same in SBCL, but what do you expect? Doesn't "on" work only on lists?

I expect an error.

CELLO(1): (cdddr 42)
Error: Attempt to take the cdr of 42 which is not listp.

If it blindly binds the "of" value to nums the above loop would print 42 
and then I would expect the error above. Otherwise I would expect an 
error straightaway when loop saw 42 is not listp (if the implementation 
chose to include that sanity check).

kenny


-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: Antonio Menezes Leitao
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <pan.2004.05.20.21.11.23.617100@evaluator.pt>
On Thu, 20 May 2004 19:52:36 +0000, Kenny Tilton wrote:

> 
> 
> Thomas Schilling wrote:
>> Kenny Tilton wrote:
>> 
>> 
>>>AllegroCL 6.2 for Win:
>>>
>>>   (loop for nums on 42 by #'cdddr
>>>       do (print nums))
>>>   => nil
>>>
>>>Bug or feature? Jes curious...
>> 
>> 
>> Same in SBCL, but what do you expect? Doesn't "on" work only on lists?
> 
> I expect an error.
> 
> CELLO(1): (cdddr 42)
> Error: Attempt to take the cdr of 42 which is not listp.
> 
> If it blindly binds the "of" value to nums the above loop would print 42 
> and then I would expect the error above. Otherwise I would expect an 
> error straightaway when loop saw 42 is not listp (if the implementation 
> chose to include that sanity check).
> 
> kenny

Just a guess from someone that has been involved in the last few weeks
working on an extended loop macro implementation :-(

The for-as-on-list subclause allows you to use non-proper lists, that is,
lists that terminate with an non-nil atom.  In fact, the Hyperspec says:

  6.1.2.1.3 The for-as-on-list subclause

  In the for-as-on-list subclause, the for or as construct iterates over a
  list. It checks for the end of the list as if by using atom.

So the loop in case, most probably, binds the variable nums to 42 and then
uses (atom nums) to stop the loop.

This is just a guess. Perhaps you could expand the macro call and look at
the result.

Antonio Leitao.
From: Kenny Tilton
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <32arc.132366$WA4.41452@twister.nyc.rr.com>
Antonio Menezes Leitao wrote:

> On Thu, 20 May 2004 19:52:36 +0000, Kenny Tilton wrote:
> 
> 
>>
>>Thomas Schilling wrote:
>>
>>>Kenny Tilton wrote:
>>>
>>>
>>>
>>>>AllegroCL 6.2 for Win:
>>>>
>>>>  (loop for nums on 42 by #'cdddr
>>>>      do (print nums))
>>>>  => nil
>>>>
>>>>Bug or feature? Jes curious...


....
> Just a guess from someone that has been involved in the last few weeks
> working on an extended loop macro implementation :-(
> 
> The for-as-on-list subclause allows you to use non-proper lists, that is,
> lists that terminate with an non-nil atom.  In fact, the Hyperspec says:
> 
>   6.1.2.1.3 The for-as-on-list subclause
> 
>   In the for-as-on-list subclause, the for or as construct iterates over a
>   list. It checks for the end of the list as if by using atom.
> 
> So the loop in case, most probably, binds the variable nums to 42 and then
> uses (atom nums) to stop the loop.
> 
> This is just a guess. Perhaps you could expand the macro call and look at
> the result.

(loop for x on 42 by #'cddr
       do (print x))

=>
(LET ((X 42))
   (BLOCK NIL
     (TAGBODY
      EXCL::NEXT-LOOP (WHEN (ATOM X) (GO EXCL::END-LOOP))
              (PRINT X)
              (EXCL::LOOP-REALLY-DESETQ X (CDDR X))
              (GO EXCL::NEXT-LOOP)
      EXCL::END-LOOP)))

Now I feel really stupid about bothering the list. :)

kenny
From: John Thingstad
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <opr8bd37g8pqzri1@mjolner.upc.no>
err
Loop being a macro it't behaviour when not used correctly is ill defined.
This is one of the reasons many peaple dislike loop.
I think if you look a little harder you will find many more such  
'features'.
(I don't have to say that it is bad form to rely on this .. do I)

On Thu, 20 May 2004 17:39:36 GMT, Kenny Tilton <·······@nyc.rr.com> wrote:

> AllegroCL 6.2 for Win:
>
>    (loop for nums on 42 by #'cdddr
>        do (print nums))
>    => nil
>
> Bug or feature? Jes curious...
>
> kenny
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Zach Beane
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <m3wu36n8mj.fsf@unnamed.xach.com>
"John Thingstad" <··············@chello.no> writes:

> err
> Loop being a macro it't behaviour when not used correctly is ill
> defined.

I think the meaning of the loop form Kenny posted is well defined in
section 6.1.2.1.3 of the HyperSpec:

   1. the end of the list is checked with ATOM

   2. the variable is bound to successive tails of the list

   3. at the end of iteration, the step function is applied to the
      list

Since 42 is an atom, the process never goes beyond step 1.

> This is one of the reasons many peaple dislike loop.

Ignorance of the spec is not a good reason to dislike loop.

Zach
From: Wolfhard Buß
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <m31xleomph.fsf@buss-14250.user.cis.dfn.de>
* Kenny Tilton:

> AllegroCL 6.2 for Win:
>
>    (loop for nums on 42 by #'cdddr
>        do (print nums))
>    => nil
>
> Bug or feature? Jes curious...

Feature.

 CLHS 6.1.2.1.3 The for-as-on-list subclause
 ... It checks for the end of the list as if by using atom.

CLtL2 suggests endp and would signal an error in your case.


-- 
"Hurry if you still want to see something. Everything is vanishing."
                                       --  Paul C�zanne (1839-1906)
From: Kenny Tilton
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <HW8rc.132245$WA4.59588@twister.nyc.rr.com>
Wolfhard Bu� wrote:

> * Kenny Tilton:
> 
> 
>>AllegroCL 6.2 for Win:
>>
>>   (loop for nums on 42 by #'cdddr
>>       do (print nums))
>>   => nil
>>
>>Bug or feature? Jes curious...
> 
> 
> Feature.
> 
>  CLHS 6.1.2.1.3 The for-as-on-list subclause
>  ... It checks for the end of the list as if by using atom.
> 
> CLtL2 suggests endp and would signal an error in your case.
> 
> 

Cool. Thanks all. Pardon for not trying CLHS first.

kenny

-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: David Steuber
Subject: Re: Loop bug or feature?
Date: 
Message-ID: <87lljm9vok.fsf@david-steuber.com>
Kenny Tilton <·······@nyc.rr.com> writes:

> Cool. Thanks all. Pardon for not trying CLHS first.

This was one of the many little features of the loop facility I did
not know about, so your post was not wasted even if I could have
learned about it in the CLHS or Peter's book first.

FWIW, I also tried it out on SBCL:

* (loop for nums on 42 by #'cdddr do (print nums))

NIL
* (macroexpand-1 '(loop for nums on 42 by #'cdddr do (print nums)))

(BLOCK NIL
  (LET ((NUMS 42))
    (SB-LOOP::LOOP-BODY NIL
                        (NIL NIL (WHEN (ATOM NUMS) (GO SB-LOOP::END-LOOP)) NIL)
                        ((PRINT NUMS))
                        (NIL (SB-LOOP::LOOP-REALLY-DESETQ NUMS (CDDDR NUMS))
                             (WHEN (ATOM NUMS) (GO SB-LOOP::END-LOOP))
                             NIL)
                        NIL)))
T
*

I also managed to make Xquartz crash for my first time ever.  I log
onto my webserver to read news from there because my ISP doesn't
provide news.  So I just lost all history of which articles I've read.

Apple's getting a bug report on this one.  If they didn't want it,
they shouldn't have posted a dialog asking if I wanted to file ;-)

-- 
I wouldn't mind the rat race so much if it wasn't for all the damn cats.