Skip to content

Instantly share code, notes, and snippets.

@kanatzidis
Last active August 29, 2015 14:04
Show Gist options
  • Save kanatzidis/97c464e7b2595a614ed9 to your computer and use it in GitHub Desktop.
Save kanatzidis/97c464e7b2595a614ed9 to your computer and use it in GitHub Desktop.
Bubble sort without side effects (an embarrassingly bad way of doing it)
(defun my-bubble (lst)
(or (not lst)
(let ((ret nil) (iter nil) (small (reduce (lambda (x y) (min x y)) lst)))
(dolist (obj lst)
(if (not (eql obj small))
(setf iter (cons obj iter))
(setf ret (append ret (cons obj nil)))))
(append ret (let ((a (my-bubble iter))) (and (listp a) a))))))
(my-bubble '(1 4 3 8 2 9))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment