Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created November 10, 2011 14:27
Show Gist options
  • Save jackfranklin/1354957 to your computer and use it in GitHub Desktop.
Save jackfranklin/1354957 to your computer and use it in GitHub Desktop.
Lisp flatten a list
;Flattens a list, e.g., ((a b) ((c)) d) -> (a b c d)
(defun flatten (li)
(cond ((null li) nil)
((atom li) `(,li) ) ;;THIS CONFUSES ME :(
(t (mapcan #'flatten li))))
(print (flatten `(a (a b) (a b (a c)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment