Skip to content

Instantly share code, notes, and snippets.

@kurohuku
Created May 27, 2011 10:22
Show Gist options
  • Save kurohuku/995000 to your computer and use it in GitHub Desktop.
Save kurohuku/995000 to your computer and use it in GitHub Desktop.
yielding.lisp
(defmacro yielding (&body body)
(let ((gtail (gensym))
(ghead (gensym))
(garg (gensym))
(gtmp (gensym)))
`(let* ((,ghead (cons nil nil))
(,gtail ,ghead))
(macrolet
((yield (,garg) `(setf (cdr ,',gtail) (cons ,,garg nil)
,',gtail (cdr ,',gtail)))
(yield! (,garg) `(loop :for ,',gtmp :in ,,garg :do (yield ,',gtmp))))
,@body
(cdr ,ghead)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment