80f8e86b0e31

Add `element-type` to `gathering-vector`, add `doseq`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 24 Feb 2018 19:11:17 -0500
parents b46ad82523a6
children db6c924e7738
branches/tags (none)
files losh.lisp package.lisp

Changes

--- a/losh.lisp	Sat Feb 03 15:51:31 2018 -0500
+++ b/losh.lisp	Sat Feb 24 19:11:17 2018 -0500
@@ -582,10 +582,11 @@
     #(1 2 3 a b)
 
   "
-  (destructuring-bind (&key (size 16))
+  (destructuring-bind (&key (size 16) (element-type t))
       options
     (with-gensyms (result)
-      `(let ((,result (make-array ,size :adjustable t :fill-pointer 0)))
+      `(let ((,result (make-array ,size :adjustable t :fill-pointer 0
+                                  :element-type ,element-type)))
          (flet ((gather (item)
                   (vector-push-extend item ,result)))
            (declare (dynamic-extent #'gather))
@@ -907,6 +908,7 @@
   "Multiply `place` by `factor` in-place.")
 
 
+
 (defun %divf (value &optional divisor)
   (if divisor
     (/ value divisor)
@@ -2227,6 +2229,15 @@
              (multiplying n))))
 
 
+(defmacro doseq ((var sequence) &body body)
+  "Perform `body` with `var` bound to each element in `sequence` in turn.
+
+  It's like `cl:dolist`, but for all sequences.
+
+  "
+  `(map nil (lambda (,var) ,@body) ,sequence))
+
+
 ;;;; Lists --------------------------------------------------------------------
 (defun somelist (predicate list &rest more-lists)
   "Call `predicate` on successive sublists of `list`, returning the first true result.
--- a/package.lisp	Sat Feb 03 15:51:31 2018 -0500
+++ b/package.lisp	Sat Feb 24 19:11:17 2018 -0500
@@ -304,7 +304,8 @@
     :drop
     :drop-while
     :summation
-    :product))
+    :product
+    :doseq))
 
 (defpackage :losh.lists
   (:documentation "Utilities for operating on lists.")