@@ -51,10 +51,6 @@ sources. See `sources.lisp' and `entry.lisp' for examples of how to do this.
5151
5252" ))
5353
54- (defmethod transduce (xform f (source cl :string))
55- " Elements are indexed via `char'."
56- (string-transduce xform f source))
57-
5854(defmethod transduce (xform f (source list ))
5955 " Transducing over an alist works automatically via this method, and the pairs are
6056streamed as-is as cons cells."
@@ -72,6 +68,20 @@ streamed as-is as cons cells."
7268 " Elements are indexed via `bit'."
7369 (bit-vector-transduce xform f source))
7470
71+ #- (or ecl allegro)
72+ (defmethod transduce (xform f (source cl :simple-bit-vector))
73+ " Elements are indexed via `sbit'."
74+ (simple-bit-vector-transduce xform f source))
75+
76+ (defmethod transduce (xform f (source cl :string))
77+ " Elements are indexed via `char'."
78+ (string-transduce xform f source))
79+
80+ #- (or ecl allegro)
81+ (defmethod transduce (xform f (source cl :simple-string))
82+ " Elements are indexed via `schar'."
83+ (simple-string-transduce xform f source))
84+
7585(defmethod transduce (xform f (source cl :hash-table))
7686 " Yields key-value pairs as cons cells."
7787 (hash-table-transduce xform f source))
@@ -189,6 +199,30 @@ streamed as-is as cons cells."
189199#+ nil
190200(bit-vector-transduce (map #' 1+ ) #' cons #* 0101)
191201
202+ (declaim (ftype (function (t t cl :simple-bit-vector) * ) simple-bit-vector-transduce))
203+ (defun simple-bit-vector-transduce (xform f coll)
204+ (let* ((init (funcall f))
205+ (xf (funcall xform f))
206+ (result (simple-bit-vector-reduce xf init coll)))
207+ (funcall xf result)))
208+
209+ (declaim (ftype (function (t t cl :simple-bit-vector) * ) simple-bit-vector-reduce))
210+ (defun simple-bit-vector-reduce (f identity vec)
211+ (declare (optimize (speed 3 ) (safety 1 ) (debug 1 )))
212+ (let ((len (length vec)))
213+ (labels ((recurse (acc i)
214+ (declare (type fixnum i))
215+ (if (= i len)
216+ acc
217+ (let ((acc (funcall f acc (sbit vec i))))
218+ (if (reduced? acc)
219+ (reduced-val acc)
220+ (recurse acc (1+ i)))))))
221+ (recurse identity 0 ))))
222+
223+ #+ nil
224+ (simple-bit-vector-transduce (map #' 1+ ) #' cons #* 0101)
225+
192226(defun reversed-transduce (xform f coll)
193227 (let* ((init (funcall f))
194228 (xf (funcall xform f))
@@ -236,6 +270,30 @@ streamed as-is as cons cells."
236270 (recurse acc (1+ i)))))))
237271 (recurse identity 0 ))))
238272
273+ (declaim (ftype (function (t t cl :simple-string) * ) simple-string-transduce))
274+ (defun simple-string-transduce (xform f coll)
275+ (let* ((init (funcall f))
276+ (xf (funcall xform f))
277+ (result (simple-string-reduce xf init coll)))
278+ (funcall xf result)))
279+
280+ #+ nil
281+ (simple-string-transduce (map #' char-upcase ) #' string " hello" )
282+
283+ (declaim (ftype (function (t t cl :simple-string) * ) simple-string-reduce))
284+ (defun simple-string-reduce (f identity str)
285+ (declare (optimize (speed 3 ) (safety 1 ) (debug 1 )))
286+ (let ((len (length str)))
287+ (labels ((recurse (acc i)
288+ (declare (type fixnum i))
289+ (if (= i len)
290+ acc
291+ (let ((acc (funcall f acc (schar str i))))
292+ (if (reduced? acc)
293+ (reduced-val acc)
294+ (recurse acc (1+ i)))))))
295+ (recurse identity 0 ))))
296+
239297(declaim (ftype (function (t t cl :hash-table) * ) hash-table-transduce))
240298(defun hash-table-transduce (xform f coll)
241299 " Transduce over the contents of a given Hash Table."
0 commit comments