Draft: fix conflict with CL’s count function (GitLab issue #1)

Pulled in a copy of the old !1 (closed) to integrate with our testing and with an eye to pushing it.

@dmorrison -- Could we fix this problem not by removing count, but by no longer exporting it? If people had code that used count they must have gotten it by doing some kind of shadowing import anyway, so if we keep it as an internal symbol, we could avoid the howls that @alendvai is worried about.

Edited by Robert Goldman

Merge request reports

Loading
+18 −10
Changes for iterate-test.lisp: 18 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@
  (a b c))

(deftest repeat.1
    (iter (repeat 9) (count 1))
    (iter (repeat 9) (counting 1))
  9)

(deftest repeat.2
@@ -125,6 +125,15 @@
    (iter (repeat -1.5f0) (counting t))
  0)

(deftest count.1
    (ignore-errors
      ;; a regression test for a bug formerly added to iterate, but now repaired, where
      ;; "count" was mistakenly a synonym of "counting" -- if it recurs this test will
      ;; fail cleanly
      (iter (for list in '((1 2 1) (t nil 1 t)))
            (collect (count 1 list))))
  (2 1))

(deftest locally.1
    (iterate (for i in '(1 2 3)) (repeat 2)
             (locally (collect i) (collect 0)))
@@ -365,7 +374,7 @@
        (incf sym-count))
      (= sym-count
	 (iterate (for () in-package '#:iterate external-only t)
                  (count 1))))
		  (counting 1))))
  t)

(deftest in-package.generator
@@ -798,7 +807,7 @@
(deftest next-iteration.1
    (iter (for i below 10)
	  (when (oddp i) (next-iteration))
          (count t))
	  (counting t))
  5)

(deftest next-iteration.2
@@ -1295,7 +1304,7 @@
  (1 2))

(deftest dotted.3
    (values (ignore-errors (iter (for i in '(1 2 . 3)) (count t))))
    (values (ignore-errors (iter (for i in '(1 2 . 3)) (counting t))))
  nil)

(deftest dotted.4
@@ -1374,7 +1383,7 @@
(deftest type.3
    (iter (declare (iterate:declare-variables))
	  (for el in '(1 2 3 4 5))
          (count (oddp el) into my-result)
	  (counting (oddp el) into my-result)
	  (declare (integer my-result))
	  (finally (return my-result)))
  3)
@@ -1883,7 +1892,7 @@
      (iter (for (k1 v1) in-hashtable ht1)
	    (counting
	     (iter (for (k2 nil) in-hashtable ht2)
                   (count k2)))))
		   (counting k2)))))
  1)

(deftest nested.in-hashtable.3
@@ -1894,7 +1903,7 @@
      (iter (for (k1 v1) in-hashtable ht1)
	    (progn
	     (iter (for (nil v2) in-hashtable v1)
                   (count v2))
		   (counting v2))
	     (collect k1))))
  (a))

@@ -1902,7 +1911,7 @@
  (< 6
     (print
      (iter (for scl in-package '#:iterate :external-only t)
            (count ; Iterate exports ~50 symbols
	    (counting ; Iterate exports ~50 symbols
	     (iter (for si in-package #.*package*)
		   (thereis (eq si scl))))))
     80)
@@ -1944,8 +1953,7 @@
                          (problem-because-i-return-nil))))
             (tags (all-tagbody-tags form)))
         (iter (for tag in tags)
              ;; invoke cl:count, not the Iterate clause:
              (always (= 1 (funcall #'count tag tags :from-end nil))))))
              (always (= 1 (count tag tags :from-end nil))))))
  t)

(deftest walk.tagbody.1
+2 −2
Changes for iterate.lisp: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@
;;;           used, to avoid compiler warnings from some compilers (Allegro)
;;;  3/4/91 - treat cond as a special form for allegro
;;;  (v. 1.1.1)
;;;  2019-02-10 - Don Morrison (dfm@ringing.org): removed defsynonym defining
;;;               count, per section 2.3 or the Iterate Manual

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; OUTSTANDING PROBLEMS & QUESTIONS:
@@ -2840,8 +2842,6 @@ e.g. (DSETQ (VALUES (a . b) nil c) form)"
			   `((if ,test-expr ,update-code ,var))
			   (list update-code)))))

(defsynonym count counting)

;;; (COUNTING &optional INTO)
(defclause (counting expr &optional into var)
  "Increment a variable if expression is non-nil"
Loading