mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-13 21:02:47 -08:00
The sequence iteration macros allow specifying the name of the index variable
This commit is contained in:
parent
365ad7b1e2
commit
eb090229ee
1 changed files with 24 additions and 21 deletions
|
|
@ -57,50 +57,53 @@
|
|||
(defmacro reckless (&body body)
|
||||
`(locally (declare (optimize (safety 0) (speed 3) (debug 0))) ,@body))
|
||||
|
||||
(defmacro do-vector ((elt vector start end &key from-end output) &body body)
|
||||
(with-unique-names (%vector %i %count)
|
||||
(defmacro do-vector ((elt vector start end
|
||||
&key from-end output (index (gensym)))
|
||||
&body body)
|
||||
(with-unique-names (%vector %count)
|
||||
(if from-end
|
||||
`(do* ((,%vector ,vector)
|
||||
(,%i ,end)
|
||||
(,index ,end)
|
||||
(,%count ,start))
|
||||
((= ,%i ,%count) ,output)
|
||||
(declare (fixnum ,%i ,%count)
|
||||
((= ,index ,%count) ,output)
|
||||
(declare (fixnum ,index ,%count)
|
||||
(vector ,%vector))
|
||||
(let ((,elt (reckless (aref ,%vector (setf ,%i (1- ,%i))))))
|
||||
(let ((,elt (reckless (aref ,%vector (setf ,index (1- ,index))))))
|
||||
,@body))
|
||||
`(do* ((,%vector ,vector)
|
||||
(,%i ,start (1+ ,%i))
|
||||
(,index ,start (1+ ,index))
|
||||
(,%count ,end))
|
||||
((= ,%i ,%count) ,output)
|
||||
(declare (fixnum ,%i ,%count)
|
||||
((= ,index ,%count) ,output)
|
||||
(declare (fixnum ,index ,%count)
|
||||
(vector ,%vector))
|
||||
(let ((,elt (reckless (aref ,%vector ,%i))))
|
||||
(let ((,elt (reckless (aref ,%vector ,index))))
|
||||
,@body)))))
|
||||
|
||||
(defmacro do-sublist ((elt list start end &key output) &body body)
|
||||
(with-unique-names (%sublist %i %count)
|
||||
`(do* ((,%i ,start)
|
||||
(,%sublist (nthcdr ,%i ,list) (cdr ,%sublist))
|
||||
(,%count (- ,end ,%i) (1- ,%count)))
|
||||
(defmacro do-sublist ((elt list start end &key output (index (gensym))) &body body)
|
||||
(with-unique-names (%sublist %count)
|
||||
`(do* ((,index ,start (1+ ,index))
|
||||
(,%sublist (nthcdr ,index ,list) (cdr ,%sublist))
|
||||
(,%count (- ,end ,index) (1- ,%count)))
|
||||
((<= ,%count 0) ,output)
|
||||
(declare (fixnum ,%i ,%count)
|
||||
(declare (fixnum ,index ,%count)
|
||||
(cons ,%sublist))
|
||||
(let ((,elt (car ,%sublist)))
|
||||
,@body))))
|
||||
|
||||
(defmacro do-sequence ((elt sequence start end &key output specialize) &body body)
|
||||
(defmacro do-sequence ((elt sequence start end &key (index (gensym)) output specialize)
|
||||
&body body)
|
||||
(if specialize
|
||||
(with-unique-names (%sequence)
|
||||
`(let ((,%sequence ,sequence))
|
||||
(if (listp ,%sequence)
|
||||
(do-sublist (,elt ,%sequence ,start ,end :output ,output)
|
||||
(do-sublist (,elt ,%sequence ,start ,end :output ,output :index ,index)
|
||||
,@body)
|
||||
(do-vector (,elt ,%sequence ,start ,end :output ,output)
|
||||
(do-vector (,elt ,%sequence ,start ,end :output ,output :index ,index)
|
||||
,@body))))
|
||||
(with-unique-names (%sequence %start %i %count)
|
||||
`(do* ((,%sequence ,sequence)
|
||||
(,%start ,start)
|
||||
(,%i (make-seq-iterator ,%sequence ,%start)
|
||||
(,index ,start (1+ ,index))
|
||||
(,%i (make-seq-iterator ,%sequence ,index)
|
||||
(seq-iterator-next ,%sequence ,%i))
|
||||
(,%count (- ,end ,start) (1- ,%count)))
|
||||
((or (null ,%i) (not (plusp ,%count))) ,output)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue