For Programmers: Free Programming Magazines  


Home > Archive > Lisp > May 2004 > Loop bug or feature?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Loop bug or feature?
Kenny Tilton

2004-05-20, 2:32 pm

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

Thomas Schilling

2004-05-20, 3:32 pm

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.
Kenny Tilton

2004-05-20, 9:31 pm



Thomas Schilling wrote:
> Kenny Tilton wrote:
>
>
>
>
> 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

John Thingstad

2004-05-20, 9:31 pm

Xref: 127.0.0.1 comp.lang.lisp:22405

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 <ktilton@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/
Zach Beane

2004-05-20, 9:31 pm

"John Thingstad" <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
Wolfhard Buß

2004-05-20, 9:31 pm

* 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)
Kenny Tilton

2004-05-20, 9:31 pm



Wolfhard Buß wrote:

> * Kenny Tilton:
>
>
>
>
> 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

Toomas Altosaar

2004-05-20, 9:31 pm

MCL gives:

Error: value 42 is not of the expected type LIST.
Antonio Menezes Leitao

2004-05-20, 9:31 pm

On Thu, 20 May 2004 19:52:36 +0000, Kenny Tilton wrote:

>
>
> Thomas Schilling wrote:
>
> 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 ws
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.
Kenny Tilton

2004-05-20, 9:31 pm



Antonio Menezes Leitao wrote:

> On Thu, 20 May 2004 19:52:36 +0000, Kenny Tilton wrote:
>
>


.....[color=darkred]
> Just a guess from someone that has been involved in the last few ws
> 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

David Steuber

2004-05-21, 2:31 am

Kenny Tilton <ktilton@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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com