[armedbear-cvs] r14355 - in trunk/abcl: src/org/armedbear/lisp test/lisp/abcl

mevenson at common-lisp.net mevenson at common-lisp.net
Wed Jan 16 10:45:56 UTC 2013


Author: mevenson
Date: Wed Jan 16 02:45:54 2013
New Revision: 14355

Log:
Fix loop and default value for of-type problem.

Patch and (most of) test by Stas.

Fixes #293.

Modified:
   trunk/abcl/src/org/armedbear/lisp/loop.lisp
   trunk/abcl/test/lisp/abcl/bugs.lisp

Modified: trunk/abcl/src/org/armedbear/lisp/loop.lisp
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/loop.lisp	Mon Jan 14 02:01:01 2013	(r14354)
+++ trunk/abcl/src/org/armedbear/lisp/loop.lisp	Wed Jan 16 02:45:54 2013	(r14355)
@@ -976,10 +976,23 @@
 
 (defun loop-typed-init (data-type &optional step-var-p)
   (when (and data-type (subtypep data-type 'number))
-    (if (or (subtypep data-type 'float)
-	    (subtypep data-type '(complex float)))
-	(coerce (if step-var-p 1 0) data-type)
-	(if step-var-p 1 0))))
+    ;; From SBCL
+    (let ((init (if step-var-p 1 0)))
+      (flet ((like (&rest types)
+               (coerce init (find-if (lambda (type)
+                                       (subtypep data-type type))
+                                     types))))
+        (cond ((subtypep data-type 'float)
+               (like 'single-float 'double-float
+                     'short-float 'long-float 'float))
+              ((subtypep data-type '(complex float))
+               (like '(complex single-float)
+                     '(complex double-float)
+                     '(complex short-float)
+                     '(complex long-float)
+                     '(complex float)))
+              (t
+               init))))))
 
 (defun loop-optional-type (&optional variable)
   ;; No variable specified implies that no destructuring is permissible.

Modified: trunk/abcl/test/lisp/abcl/bugs.lisp
==============================================================================
--- trunk/abcl/test/lisp/abcl/bugs.lisp	Mon Jan 14 02:01:01 2013	(r14354)
+++ trunk/abcl/test/lisp/abcl/bugs.lisp	Wed Jan 16 02:45:54 2013	(r14355)
@@ -125,3 +125,11 @@
 (deftest bugs.pathname.make-pathname.2
   (probe-file (make-pathname :device (list "foo")))
 nil)
+
+;; http://trac.common-lisp.net/armedbear/ticket/293
+(deftest bugs.loop.1
+    (loop :with x :of-type (float 0) = 0.0
+       :for y :upto 1
+       :collecting (cons x y))
+  ((0.0 . 0) (0.0 . 1)))
+




More information about the armedbear-cvs mailing list