Marc Tfardy <bum@cyk.cyk> writes:
Hi!
I looking for a ELISP function that do the job like Partition in
Mathematica. The simplest case:
(partition '(a b c d e f) 2)
should return:
((a b) (c d) (e f))
(defun partition-list (list length)
(loop
while list
collect (subseq list 0 length)
do (setf list (nthcdr length list))))
(defun partition-vector (vector length)
(loop
for i = 0 then (+ i length)
while (< i (length vector))
collect (subseq vector i (+ i length))))
(defun partition (sequence length)
(etypecase sequence
(list (partition-list sequence length))
(string (partition-vector sequence length)) ; emacs lisp strings are not vectors!
(vector (partition-vector sequence length))))