Skip to content

Instantly share code, notes, and snippets.

@alandipert
Last active November 2, 2018 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/9d7ff35952f33b3105f90f24a5103e48 to your computer and use it in GitHub Desktop.
Save alandipert/9d7ff35952f33b3105f90f24a5103e48 to your computer and use it in GitHub Desktop.
(defun collector ()
(let ((tail nil)
(head nil))
(lambda (&optional (item nil item?))
(cond
((not item?) head)
((null tail) (setq tail (cons item nil)
head tail))
(t (let ((new-tail (cons item nil)))
(rplacd tail new-tail)
(setq tail new-tail)))))))
(let ((collect (collector)))
(dotimes (i 10)
(funcall collect i))
(funcall collect))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment