From: Peter Seibel
Subject: REPEAT clauses within LOOP
Date: 
Message-ID: <m3wuhjuhwy.fsf@javamonkey.com>
Both Allegro Common Lisp and CLISP get grumpy if I put a 'repeat'
clause in a LOOP after a 'do' clause. CLISP signals a warning; Allegro
an error.

Yet I can't find any justifiction for this grumpiness. Which
probably means I'm not looking the right place.

Anyway, my analysis so far is that in the BNF for LOOP a 'repeat'
clause is just another kind of 'termination-test' which can occur
wherever a 'main-clause' can.

And I don't see anything in the text of 6.1 that suggests 'repeat' is
only legal in certain positions. (Though I haven't quite gone over
*every* bit of 6.1 with a fine tooth comb yet.) To the contrary--it
seems to me--6.1.4 says:

  Termination-test control constructs can be used anywhere within the
  loop body. The termination tests are used in the order in which they
  appear.

Given that verbiage, and the fact that 'repeat' is lumped in with the
termination test clauses, I'd expect that a loop like:

  (loop for i from 1 repeat 4 collect i repeat 3)

would evaluate to (1 2 3 4) on the grounds that the test implied by
the 'repeat' clauses are evaluated "in the order in which they occur"
and thus the 'repeat 3' wouldn't "notice" that we were on the 4th
iteration until after '4' had already been collected. In other words
I'd expect the loop above to behave like the following:

  (loop for i from 1 until (> i 4) collect i until (> i 3))

I *understand* that these are extreme edge cases--I'm just trying to
make sure I understand both the theory *and* the common practice as
well as I can before I try to explain it to anyone else.

Any pointers to sections of the standard I may have overlooked that
bear on this?

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

  The intellectual level needed   for  system design is  in  general
  grossly  underestimated. I am  convinced  more than ever that this
  type of work is very difficult and that every effort to do it with
  other than the best people is doomed to either failure or moderate
  success at enormous expense. --Edsger Dijkstra

From: Barry Margolin
Subject: Re: REPEAT clauses within LOOP
Date: 
Message-ID: <lwcqa.7$Q97.439@paloalto-snr1.gtei.net>
In article <··············@javamonkey.com>,
Peter Seibel  <·····@javamonkey.com> wrote:
>Both Allegro Common Lisp and CLISP get grumpy if I put a 'repeat'
>clause in a LOOP after a 'do' clause. CLISP signals a warning; Allegro
>an error.
>
>Yet I can't find any justifiction for this grumpiness. Which
>probably means I'm not looking the right place.
>
>Anyway, my analysis so far is that in the BNF for LOOP a 'repeat'
>clause is just another kind of 'termination-test' which can occur
>wherever a 'main-clause' can.

The original LOOP specification (chapter 26 of CLTL2) listed REPEAT among
the Iteration Control clauses.  I'm not sure how it ended up in Termination
Test in the standard.  My understanding is that it's essentially an
abbreviation for "for I from 1 to N" where the iteration variable is hidden
internally.

-- 
Barry Margolin, ··············@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Peter Seibel
Subject: Re: REPEAT clauses within LOOP
Date: 
Message-ID: <m3sms6v820.fsf@javamonkey.com>
Barry Margolin <··············@level3.com> writes:

> In article <··············@javamonkey.com>,
> Peter Seibel  <·····@javamonkey.com> wrote:
> >Both Allegro Common Lisp and CLISP get grumpy if I put a 'repeat'
> >clause in a LOOP after a 'do' clause. CLISP signals a warning; Allegro
> >an error.
> >
> >Yet I can't find any justifiction for this grumpiness. Which
> >probably means I'm not looking the right place.
> >
> >Anyway, my analysis so far is that in the BNF for LOOP a 'repeat'
> >clause is just another kind of 'termination-test' which can occur
> >wherever a 'main-clause' can.
> 
> The original LOOP specification (chapter 26 of CLTL2) listed REPEAT among
> the Iteration Control clauses.  I'm not sure how it ended up in Termination
> Test in the standard.  My understanding is that it's essentially an
> abbreviation for "for I from 1 to N" where the iteration variable is hidden
> internally.

That certainly fits with the observed behavior of ACL and CLISP.
Thanks.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

  The intellectual level needed   for  system design is  in  general
  grossly  underestimated. I am  convinced  more than ever that this
  type of work is very difficult and that every effort to do it with
  other than the best people is doomed to either failure or moderate
  success at enormous expense. --Edsger Dijkstra
From: Lieven Marchand
Subject: Re: REPEAT clauses within LOOP
Date: 
Message-ID: <87d6jaiixy.fsf@wyrd.be>
Peter Seibel <·····@javamonkey.com> writes:

> Both Allegro Common Lisp and CLISP get grumpy if I put a 'repeat'
> clause in a LOOP after a 'do' clause. CLISP signals a warning; Allegro
> an error.
> 
> Yet I can't find any justifiction for this grumpiness. Which
> probably means I'm not looking the right place.

Look at 6.1.2.1.

The iteration control clauses for, as, and repeat must precede any
other loop clauses, except initially, with, and named, since they
establish variable bindings. When iteration control clauses are used
in a loop, the corresponding termination tests in the loop body are
evaluated before any other loop body code is executed.

-- 
Jane - Daria? Come on, the neighbors are starting to talk.
Daria - Um... good. Soon they'll progress to cave drawings and civilization 
will be on its way.