1
0
Fork 0

- fixed misc:array-slice;

- changed misc:split-into-sublist to misc:split-into-chunks.
This commit is contained in:
cage 2022-05-27 19:16:29 +02:00
parent 950b669455
commit bf23d728b4
2 changed files with 22 additions and 9 deletions

View File

@ -615,7 +615,7 @@ to the array"
(defun array-slice (array start &optional (end nil))
(let* ((new-size (if end
(- end start)
(length array)))
(- (length array) start)))
(new-fill-pointer (cond
((array-has-fill-pointer-p array)
(if end
@ -670,13 +670,26 @@ to the array"
(swap (elt sequence rnd) (elt sequence i))))
sequence)
(defun split-into-sublist (lst len)
(if (or (= len 0)
(< (length lst) len))
(if (null lst)
lst
(list lst))
(append (list (subseq lst 0 len)) (split-into-sublist (subseq lst len) len))))
(defun %split-into-chunks (sequence subseq-fn chunk-length &optional (accum ()))
(assert (> chunk-length 0))
(cond
((null sequence)
(reverse accum))
((< (length sequence) chunk-length)
(%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 #'=))
(let ((distinct '()))

View File

@ -133,7 +133,7 @@
:dump-hash-table
:with-messages-start-end
:safe-random
:split-into-sublist
:split-into-chunks
:group-by
:delete@
:return-whole