mirror of https://codeberg.org/cage/tinmop/
- fixed misc:array-slice;
- changed misc:split-into-sublist to misc:split-into-chunks.
This commit is contained in:
parent
950b669455
commit
bf23d728b4
|
@ -615,7 +615,7 @@ to the array"
|
||||||
(defun array-slice (array start &optional (end nil))
|
(defun array-slice (array start &optional (end nil))
|
||||||
(let* ((new-size (if end
|
(let* ((new-size (if end
|
||||||
(- end start)
|
(- end start)
|
||||||
(length array)))
|
(- (length array) start)))
|
||||||
(new-fill-pointer (cond
|
(new-fill-pointer (cond
|
||||||
((array-has-fill-pointer-p array)
|
((array-has-fill-pointer-p array)
|
||||||
(if end
|
(if end
|
||||||
|
@ -670,13 +670,26 @@ to the array"
|
||||||
(swap (elt sequence rnd) (elt sequence i))))
|
(swap (elt sequence rnd) (elt sequence i))))
|
||||||
sequence)
|
sequence)
|
||||||
|
|
||||||
(defun split-into-sublist (lst len)
|
(defun %split-into-chunks (sequence subseq-fn chunk-length &optional (accum ()))
|
||||||
(if (or (= len 0)
|
(assert (> chunk-length 0))
|
||||||
(< (length lst) len))
|
(cond
|
||||||
(if (null lst)
|
((null sequence)
|
||||||
lst
|
(reverse accum))
|
||||||
(list lst))
|
((< (length sequence) chunk-length)
|
||||||
(append (list (subseq lst 0 len)) (split-into-sublist (subseq lst len) len))))
|
(%split-into-chunks nil subseq-fn chunk-length (push sequence accum)))
|
||||||
|
(t
|
||||||
|
(%split-into-chunks (funcall subseq-fn sequence chunk-length)
|
||||||
|
subseq-fn
|
||||||
|
chunk-length
|
||||||
|
(push (funcall subseq-fn sequence 0 chunk-length) accum)))))
|
||||||
|
|
||||||
|
(defgeneric split-into-chunks (object chunk-length))
|
||||||
|
|
||||||
|
(defmethod split-into-chunks ((object list) chunk-length)
|
||||||
|
(%split-into-chunks object #'subseq chunk-length))
|
||||||
|
|
||||||
|
(defmethod split-into-chunks ((object vector) chunk-length)
|
||||||
|
(%split-into-chunks object #'array-slice chunk-length))
|
||||||
|
|
||||||
(defun group-by (sequence &key (test #'=))
|
(defun group-by (sequence &key (test #'=))
|
||||||
(let ((distinct '()))
|
(let ((distinct '()))
|
||||||
|
|
|
@ -133,7 +133,7 @@
|
||||||
:dump-hash-table
|
:dump-hash-table
|
||||||
:with-messages-start-end
|
:with-messages-start-end
|
||||||
:safe-random
|
:safe-random
|
||||||
:split-into-sublist
|
:split-into-chunks
|
||||||
:group-by
|
:group-by
|
||||||
:delete@
|
:delete@
|
||||||
:return-whole
|
:return-whole
|
||||||
|
|
Loading…
Reference in New Issue