Re: Illegal LOOP usage?




* Edi Weitz <spamtrap@xxxxxxxxxx> <u1wk15tah.fsf@xxxxxxxxxx> :

| On Wed, 07 Mar 2007 06:34:28 +0530, Madhu <enometh@xxxxxxxx> wrote:
|
|> From which it is inferred that "the actual list being collected be
|> held separately from the variable used in the loop body)."
|>
|> Would that explain it?
|
| Er, no. Thanks for the link, though. I had read the CLHS entry
| myself, but I read it differently. If something is "bound as if
| using a WITH clause," I can modify it within the LOOP's body and
| have the new value available in FINALLY clauses. For what other
| reason would they even mention the WITH clause there?

No, as I read it: as it is bound within a (nested) WITH, your
modification would hold only within that single iteration.

On the next iteration the loop variable would be bound with WITH to
the current-collected-list.

| I see no wording that mandates that the list being collected is held
| separately from the variable used in the loop body. I also think
| that'd be completely counter-intuitive.

Not to me. Let me try again. CLHS 6.3.1 says

During each iteration, the constructs collect and collecting collect
the value of the supplied form into a list. When iteration
terminates, the list is returned. The argument var is set to the
list of collected values; if var is supplied, the loop does not
return the final list automatically. If var is not supplied, it is
equivalent to supplying an internal name for var and returning its
value in a finally clause. The var argument is bound as if by the
construct with.

The behaviour specified is that with a COLLECT ALL values are
collected. There is no provision for mutating that list. The behaviour
specified is (should be) identical whether or not a INTO VAR clause is
specified (as there is no reason to believe otherwise)

The only difference is that when a INTO clause is specified, the loop
does not automatically return the final list.

The behaviour is consistent AFAICT



| Besides, both SBCL and AllegroCL return 11 (and not 10) from this
| loop:
|
| (loop for i from 1 to 10
| maximize i into k
| do (incf k)
| finally (return k))
|

This is consistent. k retains its INCFd value at the end of the last
iteration before execution of the FINAL block.


| To me, the explanation you linked to sounds like an after-the-fact
| justification of the implementation. Unless I see more convincing
| arguments.


Again,

If var is not supplied, it is equivalent to supplying an internal
name for var and returning its value in a finally clause. The var
argument is bound as if by the construct with.

This binding happens on each iteration of loop. I think it is clear
I'm satisfied with things as they are :)

--
Madhu
.



Relevant Pages

  • Re: Illegal LOOP usage?
    ... | reason would they even mention the WITH clause there? ... On the next iteration the loop variable would be bound with WITH to ... the constructs collect and collecting collect ... The argument var is set to the ...
    (comp.lang.lisp)
  • Re: The LOOP macro (was Re: Be afraid of XML)
    ... > any different from any other LOOP clause? ... clauses and the into preposition of accumulation clauses." ... var and returning its value in a finally clause. ...
    (comp.lang.lisp)
  • Re: LOOP blows!
    ... There are two `initializations' in execution of LOOP, ... before staring the first iteration. ... |> The first for clause will never terminate. ...
    (comp.lang.lisp)
  • Re: Awesome Tutorials for JavaScript beginners
    ... If the statement is false we exit from the while loop. ... Most Web developers think browser scripting is ... var UA = navigator.userAgent.toLowerCase; ... I suppose they could contact the authors of the script ...
    (comp.lang.javascript)
  • Re: LOOP blows!
    ... The order of initialization follows the ... There are two `initializations' in execution of LOOP, ... before staring the first iteration. ... |> The first for clause will never terminate. ...
    (comp.lang.lisp)