Last active
July 22, 2017 13:32
-
-
Save phoe/ada194e3238892c9b15e2dea4264ebcc to your computer and use it in GitHub Desktop.
Fast destructive list splitting in Common Lisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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