Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#375 loop (...) for vars on vars misbehaving

open
Jörg Höhle
clisp (525)
5
2006-11-02
2006-11-02
Tomas Zellerin
No

Following construct behaves different than expected in
clisp (2.40 and 2.41, Linux and Windows tried):

(let ((vars '(1 2 3 4)))
(loop for i from 0 to 10 for vars on vars do (print
vars)))
=> nil

The expansion (macroexpand-1 '(loop for i from 0 to
10 for vars on vars do (print vars))) shows the
reason.

(MACROLET ((LOOP-FINISH NIL (SYSTEM::LOOP-FINISH-
ERROR)))
(BLOCK NIL
(LET ((I 0))
(PROGN
(LET ((VARS NIL)) ; <-------- here
(LET NIL
(LET NIL
(MACROLET ((LOOP-FINISH NIL '(GO SYSTEM::END-
LOOP)))
(TAGBODY (SETQ VARS VARS) SYSTEM::BEGIN-LOOP
(WHEN (> I 10) (LOOP-FINISH)) (WHEN (ATOM
VARS) (LOOP-FINISH))
(PROGN (PROGN (PRINT VARS))) (PSETQ I (+ I
1)) (PSETQ VARS (CDR VARS))
(GO SYSTEM::BEGIN-LOOP) SYSTEM::END-LOOP
(MACROLET
((LOOP-FINISH NIL (SYSTEM::LOOP-FINISH-WARN)
'(GO SYSTEM::END-LOOP)))))))))))))

See discussion on
http://thread.gmane.org/gmane.lisp.clisp.general/11568
/focus=11568

Discussion

  • Jörg Höhle
    Jörg Höhle
    2006-11-02

    Logged In: YES
    user_id=377168

    Bug was not present in clisp-2.28
    (macroexpand'
    (loop for i from 0 to 10 for vars on vars do (print
    vars)))

    (MACROLET ((LOOP-FINISH NIL (SYSTEM::LOOP-FINISH-ERROR)))
    (BLOCK NIL
    (LET NIL
    (LET ((I 0))
    (PROGN
    (LET ((#:G232 NIL))
    (MACROLET ((LOOP-FINISH NIL '(GO SYSTEM::END-LOOP)))
    (TAGBODY (PROGN (SETQ #:G232 VARS))
    SYSTEM::BEGIN-LOOP
    (PROGN (WHEN (> I 10) (LOOP-FINISH)))
    (PROGN (WHEN (ENDP #:G232) (LOOP-FINISH))
    (LET ((VARS #:G232)) (PROGN (PROGN (PRINT VARS)))))
    (PROGN (PSETQ I (+ I 1)) (PSETQ #:G232 (CDR
    #:G232)))
    (GO SYSTEM::BEGIN-LOOP) SYSTEM::END-LOOP
    (MACROLET
    ((LOOP-FINISH NIL (SYSTEM::LOOP-FINISH-WARN)
    '(GO SYSTEM::END-LOOP)))))))))))) ;

    I'm really surprised that such a bug can get in. I'd
    expected ANSI tests to catch such shadowing issues. When
    were these last ran?
    Maybe that's another TODO item for the pre-release process?

    It appears that 2.28's loop is radically different: the vars
    variable is bound anew for every iteration, not bound

     
  • Jörg Höhle
    Jörg Höhle
    2006-11-02

    • assigned_to: haible --> hoehle
    • status: open --> open-invalid
     
  • Jörg Höhle
    Jörg Höhle
    2006-11-02

    Logged In: YES
    user_id=377168

    Not a bug.
    CLHS 6.1.1.4 states "One implication of this interleaving is
    that it is implementation-dependent whether the lexical
    environment in which the initial value forms (variously
    called the form1, form2, form3, step-fun, vector,
    hash-table, and package) in any for-as-subclause, except
    for-as-equals-then, are evaluated includes only the loop
    variables preceding that form or includes more or all of the
    loop variables; the form1 and form2 in a for-as-equals-then
    form includes the lexical environment of all the loop
    variables."

    Therefore, no wonder no tests detects this change, since
    it's not portable code.

    Thus the only bug is that CLISP is encouraged to and should
    document its "implementation dependent" choices (see CLHS
    glossary).
    Once this is documented, the testsuite may verify CLISP's
    specific choice.

    Given that CLISP's implementation changed over time, maybe
    imnotes should instead document exactly that: do *not* rely
    on it, its unportable anyway

     
  • Sam Steingold
    Sam Steingold
    2006-11-02

    • status: open-invalid --> open
     
  • Sam Steingold
    Sam Steingold
    2006-11-02

    Logged In: YES
    user_id=5735

    I am not sure I agree with Jorg.
    if this code works in ALL other CL implementations
    (including an older CLISP), it is de facto portable.
    there is no good reason for CLISP not to accept it
    (especially since it already does the expected thing
    without the "for i from ..." part).