summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hyperquirks.lisp15
1 files changed, 9 insertions, 6 deletions
diff --git a/hyperquirks.lisp b/hyperquirks.lisp
index dd65b4f..b765e69 100644
--- a/hyperquirks.lisp
+++ b/hyperquirks.lisp
@@ -208,12 +208,15 @@ E.g.
"Group a list XS into consequtive sublists of size N, using the
DEFAULT to fill in any remainder in the case the length of XS is not
neatly divisible by N."
- (loop for l on xs by (lambda (l) (nthcdr n l))
- when (<= n (length l))
- collect (subseq l 0 n)
- else
- collect (append l (loop repeat (- n (length l)) collect default))))
-
+ (loop
+ with len = (length xs)
+ for start from 0 to len by n
+ for end = (+ start n)
+ when (<= end len)
+ collect (subseq xs start end)
+ when (and (< start len) (> end len))
+ collect (nconc (subseq xs start)
+ (loop repeat (- end len) collect default))))
;;; STRING FUNCTIONS