Hi, so I played with this a bit and attached a patch to fix it by moving
the wrapping with WRAP-FORM/LOOP-BODY-WRAPPERS one level down inside the
variable declarations.  Two test cases are included (one for IN-HASHTABLE, the 
other
for IN-PACKAGE, which shares the behaviour).

Since no other parts of the code need the current behaviour of WRAP-FORM
I just changed it instead of introducing another wrapper list like
LOOP-BODY-INNER-WRAPPERS or so ...

Cheers,
Olof

-- 
The world is burning.  Run.
diff -rN -U3 old-iterate/iterate.lisp new-iterate/iterate.lisp
--- old-iterate/iterate.lisp	2010-08-16 03:13:09.000000000 +0200
+++ new-iterate/iterate.lisp	2010-08-16 03:13:09.000000000 +0200
@@ -582,14 +582,14 @@
 		      ,(if (member *result-var* *bindings* :key #'car)
 			   *result-var*
 			   nil))))
-	(wrap-form *loop-body-wrappers*
-		   `(let* ,(nreverse *bindings*)
-		     ,.(if *declarations*
-			   `((declare .,*declarations*)))
-		     ,.decls
-		     ,(if final-prot 
-			  `(unwind-protect ,it-bod .,final-prot)
-			  it-bod)))))))
+	`(let* ,(nreverse *bindings*)
+	   ,.(if *declarations*
+		 `((declare .,*declarations*)))
+	   ,.decls
+	   ,(if final-prot 
+		`(unwind-protect ,it-bod .,final-prot)
+		(wrap-form *loop-body-wrappers*
+			   it-bod)))))))
 
 (defmacro defmacro-clause (clause-template &body body)
   "Create your own iterate clauses"
diff -rN -U3 old-iterate/iterate-test.lisp new-iterate/iterate-test.lisp
--- old-iterate/iterate-test.lisp	2010-08-16 03:13:09.000000000 +0200
+++ new-iterate/iterate-test.lisp	2010-08-16 03:13:09.000000000 +0200
@@ -291,6 +291,15 @@
        #'< :key #'car))
   ((1 . b) (6 . 3)))
 
+;; to test the behaviour of WITH versus WITH-HASH-TABLE-ITERATOR
+(deftest in-hashtable.immediate.1
+    (iter
+      (with table = (let ((ht (make-hash-table)))
+		      (setup-hash-table ht)
+		      ht))
+      (for (k) in-hashtable table))
+  nil)
+
 (deftest in-package.internals
     (let ((syms nil)
 	  (iter-syms (iterate (for sym in-package *package* :external-only nil)
@@ -333,6 +342,13 @@
        (set-difference iter-syms syms)))
   (()()))
 
+;; to test the behaviour of WITH versus WITH-PACKAGE-ITERATOR
+(deftest in-package.immediate.1
+    (iter
+      (with package = (find-package '#:cl-user))
+      (for sym in-package package))
+  nil)
+
 (deftest in-packages.external
     (let ((syms nil)
 	  (iter-syms (iterate (as (sym access package) in-packages '(#:cl-user)

_______________________________________________
iterate-devel site list
iterate-devel@common-lisp.net
http://common-lisp.net/mailman/listinfo/iterate-devel

Reply via email to