From: Tim Bradshaw
Subject: A LOOP question
Date: 
Message-ID: <ey3snciif9e.fsf@cley.com>
[The `LOOP is too poorly-specified to use' people are going to have a
field day here...]

I have a LOOP which begins

        (loop for x below 10
              while (property x)
              for y = (compute-thing x)
              do ...)

This works OK, and I think the meaning is reasonably clear (basically
I don't want to COMPUTE-THING unless PROPERTY is OK, and I want to
stop the moment PROPERTY is not OK).

CLISP (2.27) doesn't like this, it says that `FOR clauses should occur
before the loop's main body' (as a warning).

Other systems I've tried don't complain.

I *think* this is a clisp bug, but I'm hesitant to say.  Does anyone
have an opinion (other than on my programming style...)?

--tim

From: Kent M Pitman
Subject: Re: A LOOP question
Date: 
Message-ID: <sfwadyqo06i.fsf@world.std.com>
Tim Bradshaw <···@cley.com> writes:

> [The `LOOP is too poorly-specified to use' people are going to have a
> field day here...]

Huh?  LOOP has a very plain BNF.  I worked hard on that to make it readable.
(You should have seen it before I started.)
 
Annotation added--------------------------------------v

> I have a LOOP which begins
> 
>         (loop for x below 10               ;<-- for-as-clause
>               while (property x)           ;<-- termination-test
>               for y = (compute-thing x)    ;<-- for-as-clause
>               do ...)                      ;<-- unconditional


loop [name-clause] {variable-clause}* {main-clause}* => result*

 variable-clause::= with-clause | initial-final | for-as-clause 
 
 main-clause::= unconditional    | accumulation  | conditional
              | termination-test | initial-final 

There is no room for a termination-test in the variable clauses.

> This works OK,

Read: "is tolerated" by.

> and I think the meaning is reasonably clear (basically
> I don't want to COMPUTE-THING unless PROPERTY is OK, and I want to
> stop the moment PROPERTY is not OK).

Old-style MIT LOOP used to allow this and other cases.  Some of them were
problematic.  This might have been or it might be it was just a casualty
when the syntax was simplified to avoid other known-bad cases.   

> CLISP (2.27) doesn't like this, it says that `FOR clauses should occur
> before the loop's main body' (as a warning).

Yes, that's right.

> Other systems I've tried don't complain.

They're being nice to you, but they aren't obliged to.
 
> I *think* this is a clisp bug, but I'm hesitant to say.  Does anyone
> have an opinion (other than on my programming style...)?

Honestly, I don't think the LOOP bnf is that hard to decipher.
From: Tim Bradshaw
Subject: Re: A LOOP question
Date: 
Message-ID: <ey3k7xuianx.fsf@cley.com>
* Kent M Pitman wrote:

>> [The `LOOP is too poorly-specified to use' people are going to have a
>> field day here...]

> Huh?  LOOP has a very plain BNF.  I worked hard on that to make it readable.
> (You should have seen it before I started.)
 
Yes, it turns out they aren't and I was just not reading it right.
Everything you say in the bit I've elided is right of course, and
CLISP is just more careful than any other implementations I know.


> Honestly, I don't think the LOOP bnf is that hard to decipher.

No neither do I (despite having failed!) but it's a commonly-heard
reason not to use LOOP by people who don't like it (I am not one of
those people!).

I've corrected my code.

--tim
From: Tim Moore
Subject: Re: A LOOP question
Date: 
Message-ID: <9qkjfv$m6g$0@216.39.145.192>
In article <···············@world.std.com>, "Kent M Pitman"
<······@world.std.com> wrote:


> Tim Bradshaw <···@cley.com> writes:
> There is no room for a termination-test in the variable clauses.
>> This works OK,
> Read: "is tolerated" by.

>> Other systems I've tried don't complain.
> They're being nice to you, but they aren't obliged to.

That's too bad; I've gotten in the habit of intermixing for and while
clauses in the case where the fors are "= then" which don't have a
built-in termination. "while" terminates the loop, and the following fors
only happen if the earlier fors have produced valid results.  That was
the theory, anyway.  Guess I'll have to find a new idom.

Tim
From: Kent M Pitman
Subject: Re: A LOOP question
Date: 
Message-ID: <sfwhesyt7lb.fsf@world.std.com>
"Tim Moore" <·····@bricoworks.com> writes:

> In article <···············@world.std.com>, "Kent M Pitman"
> <······@world.std.com> wrote:
> 
> > Tim Bradshaw <···@cley.com> writes:
> > There is no room for a termination-test in the variable clauses.
> >> This works OK,
> > Read: "is tolerated" by.
> 
> >> Other systems I've tried don't complain.
> > They're being nice to you, but they aren't obliged to.
> 
> That's too bad; I've gotten in the habit of intermixing for and while
> clauses in the case where the fors are "= then" which don't have a
> built-in termination. "while" terminates the loop, and the following fors
> only happen if the earlier fors have produced valid results.  That was
> the theory, anyway.  Guess I'll have to find a new idom.

Now, wait... I wasn't advocating changing existing code or coding
style.  I'm of the opinion that it would be fine for clisp to
voluntarily get in line with what other vendors do and to say that "de
facto" everyone agrees this exception is allowable. LOOP is not required
to signal an error when the offered syntax is violated, so it's not 
non-conforming for a vendor to do this.  That leaves it a personal choice
of the programmer whether to use the extension, pretty much like it's a
personal choice whether to use the MOP.

The only point of my prior post was to say that clisp is not being bad
for not offering this.
From: Hannu Koivisto
Subject: Re: A LOOP question
Date: 
Message-ID: <87vghel7gs.fsf@lynx.ionific.com>
Tim Bradshaw <···@cley.com> writes:

| I have a LOOP which begins
| 
|         (loop for x below 10
|               while (property x)
|               for y = (compute-thing x)
|               do ...)
| 
| This works OK, and I think the meaning is reasonably clear (basically

I think so too.  Unfortunately that doesn't seem to be valid code
according to CLHS.  The extended loop form is specified as follows:

loop [name-clause] {variable-clause}* {main-clause}* => result*

Since only variable-clauses may contain for clauses and only
main-clauses may contain while clauses, your for-while-for ordering
is not valid.

Hm, now that I think of it, I have probably written that kind of
loops too :-\

-- 
Hannu
From: Janis Dzerins
Subject: Re: A LOOP question
Date: 
Message-ID: <87bsj6o05z.fsf@asaka.latnet.lv>
Tim Bradshaw <···@cley.com> writes:

> [The `LOOP is too poorly-specified to use' people are going to have a
> field day here...]
> 
> I have a LOOP which begins
> 
>         (loop for x below 10
>               while (property x)
>               for y = (compute-thing x)
>               do ...)
> 
> This works OK, and I think the meaning is reasonably clear (basically
> I don't want to COMPUTE-THING unless PROPERTY is OK, and I want to
> stop the moment PROPERTY is not OK).
> 
> CLISP (2.27) doesn't like this, it says that `FOR clauses should occur
> before the loop's main body' (as a warning).

I remember seeing this in the spec...

> Other systems I've tried don't complain.

and also noticed that some implementations allow to do it.

> I *think* this is a clisp bug, but I'm hesitant to say.  Does anyone
> have an opinion (other than on my programming style...)?

I think I found it, 6.1.2.1 Iteration Control has this to say:

  The iteration control clauses for, as, and repeat must precede any
  other loop clauses, except initially, with, and named, since they
  establish variable bindings.

-- 
Janis Dzerins

  Eat shit -- billions of flies can't be wrong.