Advertisement
Guest User

Untitled

a guest
Jun 12th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.50 KB | None | 0 0
  1. (defmacro loop-do-chunked (chunk-sym list n &body body)
  2.   (let ((elt-sym (gensym "elt"))
  3.         (i-sym (gensym "i"))
  4.         (n-sym (gensym "n")))
  5.     `(loop
  6.         with ,chunk-sym = nil
  7.         with ,n-sym = ,n
  8.         for ,elt-sym in ,list
  9.         for ,i-sym from 1
  10.         do (push ,elt-sym ,chunk-sym)
  11.         when (zerop (mod ,i-sym ,n-sym)) do
  12.           (progn (progn ,@body)
  13.                  (setf ,chunk-sym nil))
  14.         finally (when ,chunk-sym
  15.                   (progn ,@body)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement