--- a/losh.lisp Fri Aug 05 23:35:35 2016 +0000
+++ b/losh.lisp Sat Aug 06 00:01:39 2016 +0000
@@ -365,6 +365,28 @@
(pop ,seq))))))))
+(defmacro-driver (FOR var IN-WHATEVER seq)
+ "Iterate over items in the given sequence.
+
+ Unlike iterate's own `in-sequence` this won't use the horrifically inefficient
+ `elt`/`length` functions on a list.
+
+ "
+ (let ((kwd (if generate 'generate 'for)))
+ (with-gensyms (is-list source i len)
+ `(progn
+ (with ,source = ,seq)
+ (with ,is-list = (typep ,source 'list))
+ (with ,len = (if ,is-list -1 (length ,source)))
+ (for ,i :from 0)
+ (,kwd ,var next (if ,is-list
+ (if ,source
+ (pop ,source)
+ (terminate))
+ (if (< ,i ,len)
+ (elt ,source ,i)
+ (terminate))))))))
+
;;;; Hash Sets
(defclass hash-set ()
((data :initarg :data)))
--- a/package.lisp Fri Aug 05 23:35:35 2016 +0000
+++ b/package.lisp Sat Aug 06 00:01:39 2016 +0000
@@ -53,6 +53,7 @@
#:run-time
#:in-lists
#:in-sequences
+ #:in-whatever
#:hash-set
#:make-set