• Loopy LOOP

    From B. Pym@21:1/5 to P. Seibel on Sun Sep 1 07:09:51 2024
    P. Seibel wrote:

    Pascal Bourguignon <spam@thalassa.informatimago.com> writes:

    Peter Seibel <peter@....com> writes:

    Pascal Bourguignon <spam@thalassa.informatimago.com> writes:

    rpw3@rpw3.org (Rob Warnock) writes:
    > (loop for i below 4
    for j below 4
    finally (return (list i j)))

    (4 3)
    >

    Oh. Duh.

    LOOP is definitely one of the parts of CL where you learn something new >> >> every day... ;-} ;-}

    Actually, the variables i and j could very well not be available in
    the finally clause.

    How do you figure that? Why would the finally clause be any different
    from any of the other clauses?

    Note how clisp returns a conforming but differnet result too:

    [193]> (loop for i below 4
    for j below 4
    finally (return (list i j)))
    (4 4)

    Hmmm. I'm not sure I buy that that's conforming. Given that LOOP
    provides AND for specifying parallel stepping, why should CLISP's
    behavior here be considered correct?

    Because the loop variables don't have to be available in the finally clause! If they're available, their value is unspecified.

    And why do you say they don't have to be available in the finally
    clause? Granted I can't see anything in the spec that *specifically*
    says they have to be but I can't see anything that specifically says
    they have to available *anywhere*. Why should the finally clause be
    any different from any other LOOP clause?

    In "ANSI Common Lisp", Paul Graham writes:

    The loop macro was originally designed to help inexperienced
    Lisp users write iterative code. Instead of writing Lisp code,
    you express your program in a form meant to resemble English,
    and this is then translated into Lisp. Unfortunately, loop is
    more like English than its designers ever intended: you can
    use it in simple cases without quite understanding how it
    works, but to understand it in the abstract is almost
    impossible.
    ....
    the ANSI standard does not really give a formal specification
    of its behavior.
    ....
    The first thing one notices about the loop macro is that it
    has syntax. A loop expression contains not subexpressions but
    clauses. The clauses are not delimited by parentheses;
    instead, each kind has a distinct syntax. In that, loop
    resembles traditional Algol-like languages. But the other
    distinctive feature of loop, which makes it as unlike Algol as
    Lisp, is that the order in which things happen is only
    loosely related to the order in which the clauses occur.
    ....
    For such reasons, the use of loop cannot be recommended.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)