Skip to content

Instantly share code, notes, and snippets.

@borkdude
Created May 8, 2012 18:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save borkdude/2638228 to your computer and use it in GitHub Desktop.
(defmacro do-window-list
((varsym list &key (window-size 2) (skip 1) (ret-all t))
&body body)
(if (not (symbolp varsym)) (error "Not an appropriate symbol name."))
(let ((ivar (gensym))
(lvar (gensym))
(wvar (gensym))
(skp (gensym))
(result (gensym))
(retall (gensym)))
`(loop with ,wvar = ,window-size
with ,lvar = ,list
with ,skp = ,skip
with ,retall = ,ret-all
for ,ivar from 0 to (- (length ,lvar) ,wvar) by ,skp
as ,varsym = (subseq ,lvar ,ivar (+ ,ivar ,wvar))
as ,result = (progn ,@body)
if ,retall
collect ,result
else unless (null ,result) return ,result)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment