Subject: [clisp-list] loop finally compound+, not compound* !

From: Pascal J.Bourguignon <[email-masked]>
Date: Wed Aug 4 10:21:01 2004

Low priority, but for ANSI comformance, the LOOP macro should expect 
at least one compound form after FINALLY.

(loop for i from 1 to 10 finally return i)
is parsed and accepted as:
(loop for i from 1 to 10 finally (values) return i)
but it should be rejected.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.

---

From: Sam Steingold <[email-masked]>
Date: Thu Aug 5 07:37:01 2004

> * Pascal J.Bourguignon <[email-masked]> [2004-08-04 19:20:12 +0200]:
>

actually, it is parsed as
(loop for i from 1 to 10 finally (return i))
but I see your point.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
((lambda (x) `(,x ',x)) '(lambda (x) `(,x ',x)))

---

From: Sam Steingold <[email-masked]>
Date: Thu Aug 5 12:12:03 2004

<http://www.lisp.org/HyperSpec/Body/mac_loop.html>:
initial-final::= initially compound-form+ | finally compound-form+ 

The appended patch makes
    (loop for i from 1 to 10 finally return i)
illegal as required by the ANSI CL.

The code above "looks reasonable" (to whom?) and "works as expected" (by
whom?), i.e., returns 11 in both CLISP and LW.
It signals an error in CMUCL.

(loop initially for i from 1 to 10)
elicits only a warning even though it is illegal in ANSI CL.

The proposed patch incompatibly changes the behavior, so that both
initially and finally are treated identically (as specified in ANSI CL)
and require non-empty list of forms (also, as specified in ANSI CL).

The code which relies on the current behavior is non-portable an
non-compliant, and should be changes regardless of whether this
proposal is accepted or rejected.

This proposal is follows the CLISP tradition of strict compliance and
signaling errors in all questionable areas.

Unless there is a strong feeling to the contrary,
I will check in this patch.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
As a computer, I find your faith in technology amusing.

--- loop.lisp	11 Jun 2004 09:32:30 -0400	1.27
+++ loop.lisp	05 Aug 2004 15:06:30 -0400	
@@ -328,11 +328,8 @@
               (return))
             (push (pop body-rest) list))
            (nreverse list)))
-       (parse-nonempty-progn (kw) ;; after kw: parses {expr}* (CLtL2) or {expr}+ (CLHS)
-         (let ((exprs (parse-progn)))
-           (unless exprs
-             (warn (TEXT "~S: missing forms after ~A") 'loop (symbol-name kw)))
-           exprs))
+       (parse-nonempty-progn (kw) ;; after kw: parses {expr}+
+         (or (parse-progn) (loop-syntax-error kw)))
        (parse-unconditional () ;; parse an unconditional
          ;; unconditional ::= {do | doing} {expr}*
          ;; unconditional ::= return expr
@@ -521,8 +518,8 @@
         ; main ::= clause | termination | initially | finally |
         ;          with | for-as | repeat
         ; termination ::= {while | until | always | never | thereis} expr
-        ; initially ::= initially {expr}*
-        ; finally ::= finally { unconditional | {expr}* }
+        ; initially ::= initially {expr}+
+        ; finally ::= finally {expr}+
         ; with ::= with {var-typespec [= expr]}+{and}
         ; for-as ::= {for | as} {var-typespec ...}+{and}
         ; repeat ::= repeat expr
@@ -557,9 +554,7 @@
                  (push `(PROGN ,@(parse-nonempty-progn kw)) initially-code))
                 ((FINALLY)
                  (pop body-rest)
-                 (push (or (parse-unconditional)
-                           `(PROGN ,@(parse-nonempty-progn kw)))
-                       finally-code))
+                 (push `(PROGN ,@(parse-nonempty-progn kw)) finally-code))
                 ((WITH FOR AS REPEAT)
                  (pop body-rest)
                  (when already-within-main