• Re: loop never + thereis

    From B. Pym@21:1/5 to Pascal Bourguignon on Tue Jun 25 10:22:08 2024
    Pascal Bourguignon wrote:

    I find this while trying to compile ThinLisp in clisp 2.33.2:

    *** - LOOP: ambiguous result of loop
    (LOOP FOR SUBFORM = (CAR SUBFORM-CONS) WHILE SUBFORM-CONS NEVER (ATOM SUBFORM)
    THEREIS (EQUAL SUBFORM '(TL:GO TL::NEXT-LOOP)) DO
    (SETF SUBFORM-CONS (CONS-CDR SUBFORM-CONS)))
    n++Break 1 TLI[7]>


    The formal syntax of LOOP does not impose any exclusion between always
    or never and thereis.

    Here is what CLHS says about the default return value for always,
    never and thereis:

    always: Otherwise, it provides a default return value of t.

    never: Unless some other clause contributes a return value, the
    default value returned is t.

    thereis: Unless some other clause contributes a return value, the
    default value returned is nil.


    So, the result specified by never and thereis seem to be in
    contradiction, but these clauses are not evaluated in parallel!

    ...

    Or for another example:

    (loop for i from 1 to 10 thereis nil never nil)

    should return the default value of the last clause seen: T




    My reading of CLHS - T

    ThinLisp source expects: - T

    clisp 2.33.2 error -

    gcl 2.6.3 warning NIL

    ecl 0.9 warning T

    cmucl 18e warning T

    sbcl 0.8.14.9 - T (issues a deleting
    unreachable code note
    as expected).


    So, the question is: what does the standard specify in the case where
    we mix ALWAYS or NEVER with THEREIS in a LOOP?


    Paul Graham:

    I consider Loop one of the worst flaws in CL, and an example
    to be borne in mind by both macro writers and language designers.


    [In "ANSI Common Lisp", Graham makes the following comments:]

    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)
  • From B. Pym@21:1/5 to Pascal Bourguignon on Sat Jul 12 18:04:18 2025
    Pascal Bourguignon wrote:

    So, the question is: what does the standard specify in the case where
    we mix ALWAYS or NEVER with THEREIS in a LOOP?


    Paul Graham:

    I consider Loop one of the worst flaws in CL, and an example
    to be borne in mind by both macro writers and language designers.


    [In "ANSI Common Lisp", Graham makes the following comments:]

    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)