[go: up one dir, main page]

Menu

#739 CLISP fails ANSI-TEST LOOP.1.40

closed-invalid
None
5
2019-11-04
2019-11-02
No
(loop for i from 1 to 5 finally (return i)) ;=> 6, should be 5

Rationale: https://gist.github.com/phoe/335fecfdc195bddd47ab0928b0e62e52

Discussion

  • Bruno Haible

    Bruno Haible - 2019-11-03

    There are two more related cases:

    > (loop for i from 1 to 5 finally (return i))
    6
    > (loop for i from 1 upto 5 finally (return i))
    6
    > (loop for i from 1 below 6 finally (return i))
    6
    

    ANSI CL 6.1.2.1.1 http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/sec_6-1-2-1-1.html says: "The variable var is bound to the value of form1 in the first iteration and is stepped[1] by the value of form3 in each succeeding iteration, or by 1 if form3 is not provided." Therefore here, the variable I is set to the values 1, 2, 3, ... consecutively.

    The question is whether the last value attained is 5 or 6.

    The text regarding TO and UPTO in http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/sec_6-1-2-1-1.html is not precise: For UPTO it says "the loop terminates when the variable var passes the value of form2" which - to a certain degree - indicates that FOR I FROM 1 UPTO 5 will set I to 6.

    The text regarding BELOW in http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/sec_6-1-2-1-1.html, on the other hand, is clearly contradictory: "These keywords stop iteration just before the value of the variable var reaches the value supplied by form2" but also "iteration continues until the value var is stepped to the exclusive or inclusive limit supplied by form2".

    I think all three cases should be handled in the same way - either use a temporary variable for the stepping in all three cases, or use an assignment to var during the stepping, in all three cases.

    Since SBCL produces the the same results as CLISP for the three cases above, I vote for doing nothing.

    Users need to be aware that accessing the loop variables in the FINALLY clause is - and always has been - hairy. This is also true for the other iteration controls, such as FOR I ACROSS or FOR I BEING EACH HASH-KEY and so on.

     
  • Bruno Haible

    Bruno Haible - 2019-11-03
    • status: open --> closed-invalid
    • assigned_to: Bruno Haible
     

Log in to post a comment.