From: Ralf Mattes
Subject: Strange LOOP  error in SBCL
Date: 
Message-ID: <pan.2006.12.07.22.00.23.73497@mh-freiburg.de>
Hello everyone,

why does this

 (loop for x from 0 by -2 when (< x -10) return x)

compile and run fine in ACL (Express), LispWorks (Personal), CMUCL and
CLISP but fail in SBCL (1.0 on Ubuntu)?

There's both a warning:

; caught WARNING:
;   Asserted type (OR (SINGLE-FLOAT (0.0)) (DOUBLE-FLOAT (0.0d0)) (RATIONAL (0)))
;   conflicts with derived type (VALUES (INTEGER -2 -2) &OPTIONAL).
;   See also:
;     The SBCL Manual, Node "Handling of Types"
; 
; compilation unit finished
;   caught 1 WARNING condition
;   printed 4 notes


as well as an error:
 The value -2 is not of type
  (OR (SINGLE-FLOAT (0.0)) (DOUBLE-FLOAT (0.0d0)) (RATIONAL (0))).
   [Condition of type TYPE-ERROR]

Hmm. Any ideas? Hyperspec doesn't seem too clear here. One _could_ read
the arithmetic-downto case as allowing only:

;;;  arithmetic-downto::= [[{{from form1}}1  |   {{{downto | above}
form2}}1  | by form3]]

 (loop for x from 0 downto -100 by 2 when (< x -10) return x)

i.e. the by-clause describes an interval that has to be positive - 
This works in SBCL but requires the limit to be known in advance, so the
following can't be expresed:

 (loop for money from 1000 by -5 
    do (buy hamburgers money)
    when (enough-food-p) return :burp!)



 Cheers  

       Ralf Mattes


  Ralf Mattes


 

From: Joel Wilsson
Subject: Re: Strange LOOP error in SBCL
Date: 
Message-ID: <1165531733.500279.17270@j44g2000cwa.googlegroups.com>
Ralf Mattes wrote:
> why does this
>
>  (loop for x from 0 by -2 when (< x -10) return x)
>
> compile and run fine in ACL (Express), LispWorks (Personal), CMUCL and
> CLISP but fail in SBCL (1.0 on Ubuntu)?

I don't know (might be a bug), but this seems more logical to me:
(loop for x downfrom 0 by 2 when (< x -10) return x)

It also has the benefit of working just fine in SBCL! ;)
From: Ralf Mattes
Subject: Re: Strange LOOP error in SBCL
Date: 
Message-ID: <pan.2006.12.07.23.06.02.386153@mh-freiburg.de>
On Thu, 07 Dec 2006 14:48:53 -0800, Joel Wilsson wrote:

> Ralf Mattes wrote:
>> why does this
>>
>>  (loop for x from 0 by -2 when (< x -10) return x)
>>
>> compile and run fine in ACL (Express), LispWorks (Personal), CMUCL and
>> CLISP but fail in SBCL (1.0 on Ubuntu)?
> 
> I don't know (might be a bug), but this seems more logical to me:
> (loop for x downfrom 0 by 2 when (< x -10) return x)
> 
> It also has the benefit of working just fine in SBCL! ;)

Yes, it does (Chr. Rhodes pointed that out in a private mail).
Unfortunately this will get tricky when the in/decrement value isn't known
in advance: 

 (defun draw-stacked (count offset)
 	   (loop for count from 0 to 10
 	             and y from 0 by offset do (draw-block count 0 y)))

Off course this can be expressed in other (more clumsy) LOOP syntax. I was
merely curious about what the standard says (SBCL seems to follow the
standard) and maybe the rationale behind it.

 Thanks, RalfD


 
From: Thomas A. Russ
Subject: Re: Strange LOOP error in SBCL
Date: 
Message-ID: <ymi8xhem197.fsf@sevak.isi.edu>
Ralf Mattes <··@mh-freiburg.de> writes:

> On Thu, 07 Dec 2006 14:48:53 -0800, Joel Wilsson wrote:
> 
> > Ralf Mattes wrote:
> >> why does this
> >>
> >>  (loop for x from 0 by -2 when (< x -10) return x)
> >>
> >> compile and run fine in ACL (Express), LispWorks (Personal), CMUCL and
> >> CLISP but fail in SBCL (1.0 on Ubuntu)?
> > 
> > I don't know (might be a bug), but this seems more logical to me:
> > (loop for x downfrom 0 by 2 when (< x -10) return x)
> > 
> > It also has the benefit of working just fine in SBCL! ;)
> 
> Yes, it does (Chr. Rhodes pointed that out in a private mail).
> Unfortunately this will get tricky when the in/decrement value isn't known
> in advance: 
> 
>  (defun draw-stacked (count offset)
>  	   (loop for count from 0 to 10
>  	             and y from 0 by offset do (draw-block count 0 y)))
> 
> Off course this can be expressed in other (more clumsy) LOOP syntax. I was
> merely curious about what the standard says (SBCL seems to follow the
> standard) and maybe the rationale behind it.

Well, I'm sure that the rationale behind it is to enable the LOOP macro
to emit non-conditional code.  The point of knowing the direction is to
enable the easy production of termination condition code.  By mandating
that "from" be an increasing index and "downfrom" be decreasing, it
makes it possible to know whether a > or < test is needed to terminate
when using the full loop clause:

    for x from start to end by offset

What is the test for termination?  Surely you don't want to force the
implementation to have to include the following in every loop iteration:

   (if (< end start)
       (< x end)
       (> x end))

And a suggestion to move the IF statement outside the loop and just emit
two different LOOP expansion becomes impractical when more than one
iteration variable is involved.


-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Ralf Mattes
Subject: Re: Strange LOOP error in SBCL
Date: 
Message-ID: <pan.2006.12.12.13.10.09.251256@mh-freiburg.de>
On Mon, 11 Dec 2006 16:00:36 -0800, Thomas A. Russ wrote:

> Ralf Mattes <··@mh-freiburg.de> writes:
> 
> [snip]
>> Off course this can be expressed in other (more clumsy) LOOP syntax. I was
>> merely curious about what the standard says (SBCL seems to follow the
>> standard) and maybe the rationale behind it.
> 
> Well, I'm sure that the rationale behind it is to enable the LOOP macro
> to emit non-conditional code.  The point of knowing the direction is to
> enable the easy production of termination condition code.  By mandating
> that "from" be an increasing index and "downfrom" be decreasing, it
> makes it possible to know whether a > or < test is needed to terminate
> when using the full loop clause:
> 
>     for x from start to end by offset
>

Yes, this is all pretty clear. But we have downto/upto and downfrom/upfrom
for these cases already.  Unfortunately "from" is legal both in
arithmetic-up and  arithmetic-downto. 

> What is the test for termination?  Surely you don't want to force
the
> implementation to have to include the following in every loop iteration:
> 
>    (if (< end start)
>        (< x end)
>        (> x end))

No, I don't. But there a use cases where a 'x from n' clause doesn't
provide a termination condition. 
Anyway, just me being too curious.

 Thanks. RalfD

> And a suggestion to move the IF statement outside the loop and just emit
> two different LOOP expansion becomes impractical when more than one
> iteration variable is involved.
From: John Thingstad
Subject: Re: Strange LOOP error in SBCL
Date: 
Message-ID: <op.tkf95nf6pqzri1@pandora.upc.no>
On Tue, 12 Dec 2006 01:00:36 +0100, Thomas A. Russ <···@sevak.isi.edu>  
wrote:

> Ralf Mattes <··@mh-freiburg.de> writes:
>
>> On Thu, 07 Dec 2006 14:48:53 -0800, Joel Wilsson wrote:
>>
>> > Ralf Mattes wrote:
>> >> why does this
>> >>
>> >>  (loop for x from 0 by -2 when (< x -10) return x)

(loop for x from 0 downto -10 by 2 do ...)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Barry Margolin
Subject: Re: Strange LOOP  error in SBCL
Date: 
Message-ID: <barmar-3BBB50.21345907122006@comcast.dca.giganews.com>
In article <·····························@mh-freiburg.de>,
 Ralf Mattes <··@mh-freiburg.de> wrote:

> Hello everyone,
> 
> why does this
> 
>  (loop for x from 0 by -2 when (< x -10) return x)
> 
> compile and run fine in ACL (Express), LispWorks (Personal), CMUCL and
> CLISP but fail in SBCL (1.0 on Ubuntu)?
> 
> There's both a warning:
> 
> ; caught WARNING:
> ;   Asserted type (OR (SINGLE-FLOAT (0.0)) (DOUBLE-FLOAT (0.0d0)) (RATIONAL 
> (0)))
> ;   conflicts with derived type (VALUES (INTEGER -2 -2) &OPTIONAL).
> ;   See also:
> ;     The SBCL Manual, Node "Handling of Types"
> ; 
> ; compilation unit finished
> ;   caught 1 WARNING condition
> ;   printed 4 notes
> 
> 
> as well as an error:
>  The value -2 is not of type
>   (OR (SINGLE-FLOAT (0.0)) (DOUBLE-FLOAT (0.0d0)) (RATIONAL (0))).
>    [Condition of type TYPE-ERROR]
> 
> Hmm. Any ideas? Hyperspec doesn't seem too clear here.

The description of the FROM preposition says: "If decremental 
stepping[1] is desired, the preposition downto or above must be used 
with form2."  Since you didn't use either of those prepositions, it 
assumed that you were doing incremental stepping, and inserted type 
checks for this.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Pascal Bourguignon
Subject: Re: Strange LOOP  error in SBCL
Date: 
Message-ID: <87odqf48yq.fsf@thalassa.informatimago.com>
Ralf Mattes <··@mh-freiburg.de> writes:

> Hello everyone,
>
> why does this
>
>  (loop for x from 0 by -2 when (< x -10) return x)

This is CLtL2 syntax, but not ANSI CL syntax.  

  (loop for x from 0 by -2 when (< x -10) do (return x))

> Hmm. Any ideas? Hyperspec doesn't seem too clear here. One _could_ read
> the arithmetic-downto case as allowing only:
>
> ;;;  arithmetic-downto::= [[{{from form1}}1  |   {{{downto | above}
> form2}}1  | by form3]]

Irrelevant.  Try to find a production leading to RETURN! (there's none).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This is a signature virus.  Add me to your signature and help me to live.
From: Pascal Costanza
Subject: Re: Strange LOOP  error in SBCL
Date: 
Message-ID: <4tsilkF158imoU1@mid.individual.net>
Pascal Bourguignon wrote:
> Ralf Mattes <··@mh-freiburg.de> writes:
> 
>> Hello everyone,
>>
>> why does this
>>
>>  (loop for x from 0 by -2 when (< x -10) return x)
> 
> This is CLtL2 syntax, but not ANSI CL syntax.  
> 
>   (loop for x from 0 by -2 when (< x -10) do (return x))
> 
>> Hmm. Any ideas? Hyperspec doesn't seem too clear here. One _could_ read
>> the arithmetic-downto case as allowing only:
>>
>> ;;;  arithmetic-downto::= [[{{from form1}}1  |   {{{downto | above}
>> form2}}1  | by form3]]
> 
> Irrelevant.  Try to find a production leading to RETURN! (there's none).

Of course, it's the production for "unconditional".


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Pascal Bourguignon
Subject: Re: Strange LOOP  error in SBCL
Date: 
Message-ID: <87vekm3egz.fsf@thalassa.informatimago.com>
Pascal Costanza <··@p-cos.net> writes:

> Pascal Bourguignon wrote:
>> Ralf Mattes <··@mh-freiburg.de> writes:
>>
>>> Hello everyone,
>>>
>>> why does this
>>>
>>>  (loop for x from 0 by -2 when (< x -10) return x)
>>
>> This is CLtL2 syntax, but not ANSI CL syntax.  
>>
>>   (loop for x from 0 by -2 when (< x -10) do (return x))
>>
>>> Hmm. Any ideas? Hyperspec doesn't seem too clear here. One _could_ read
>>> the arithmetic-downto case as allowing only:
>>>
>>> ;;;  arithmetic-downto::= [[{{from form1}}1  |   {{{downto | above}
>>> form2}}1  | by form3]]
>>
>> Irrelevant.  Try to find a production leading to RETURN! (there's none).
>
> Of course, it's the production for "unconditional".

Oops, sorry, I was confused, it was  'finally return expr'  that was
in CLtL2 and not in ANSI.  (Or at least some CLtL2 implementations accepted).

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

The world will now reboot.  don't bother saving your artefacts.
From: Thomas A. Russ
Subject: Re: Strange LOOP  error in SBCL
Date: 
Message-ID: <ymiodqem4m9.fsf@sevak.isi.edu>
Ralf Mattes <··@mh-freiburg.de> writes:

> Hello everyone,
> 
> why does this
> 
>  (loop for x from 0 by -2 when (< x -10) return x)
> 
> compile and run fine in ACL (Express), LispWorks (Personal), CMUCL and
> CLISP but fail in SBCL (1.0 on Ubuntu)?

SBCL is pickier about the semantics.  Try this instead:

  (loop for x downfrom 0 by 2 when (< x -10) return x)

Note that with downfrom the sign of the increment is positive!

-- 
Thomas A. Russ,  USC/Information Sciences Institute