Issue LOOP-FINALLY-VARIABLES
Issue: LOOP-FINALLY-VARIABLES

Forum: Editorial

References: LOOP

Category: CLARIFICATION/CHANGE

Edit history: 2004-07-20, Version 1 by Bruno Haible

Status: For CLiki consideration

Problem Description:

It is not clear whether iteration variables are visible in FINALLY clauses, and if so, what their values are. CLHS 6.1.1.4 requires FINALLY clauses to end up in the same tagbody where the loop body is. The forms that bind iteration variables cannot be inside the tagbody as part of the loop body, because the loop prologue wouldn't then be able to access the variables. Thus, the binding forms must be around the tagbody, so the variables must be visible in FINALLY clauses. CLHS 6.1.1.6 may help deduce the values of the variables.

Proposal (LOOP-FINALLY-VARIABLES:RESTRICT):

Add to 6.1.7.2 a note saying: FINALLY clauses are processed inside the scope of the bindings of the LOOP variables. However, accessing the FOR-AS variables from a FINALLY clause leads to undefined consequences.

Test case:

(loop for i below 10 for j below 10 finally (return (list i j)))

Rationale:

This will allow to use COLLECTed lists inside FINALLY, but not variables which are stepped. Implementations vary regarding the values of variables when a termination test succeeds. The suggested wording will allow the compiler to signal a warning when a FOR-AS variable is used inside a FINALLY clause.

Current practice:

(loop for i below 10 for j below 10 finally (return (list i j))) => (10 9) in SBCL, => (10 10) in CLISP.

Cost to Implementors:

Small. A good implementation will add a warning when a FOR-AS variable is used in FINALLY.

Cost to Users:

Fix some code that was not portable anyway.

Cost of Non-Adoption:

Unclear specification, leading to bug reports about invalid user code.

Benefits:

Clarity.

Aesthetics:

Discussion:
  • Bruno Haible supports RESTRICT.

This page is presently Uncategorized: please add appropriate topic markers and remove this text