Skip to content

Instantly share code, notes, and snippets.

@phoe
Last active July 22, 2017 13:32
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 phoe/ada194e3238892c9b15e2dea4264ebcc to your computer and use it in GitHub Desktop.
Save phoe/ada194e3238892c9b15e2dea4264ebcc to your computer and use it in GitHub Desktop.
Fast destructive list splitting in Common Lisp
(let* ((list (list 1 2 3 4 5 6 7 8 9 0))
(first list)
(second (cdr list)))
(do ((left list (cdr left))
(right (cdr list) (cdr right)))
((and (null (cdr left))
(null (cdr right))))
(setf (cdr left) (cddr left)
(cdr right) (cddr right)))
(values first second))
;; => (1 3 5 7 9)
;; => (2 4 6 8 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment