Skip to content

Instantly share code, notes, and snippets.

@ydm
Created November 20, 2023 23:55
Show Gist options
  • Select an option

  • Save ydm/c51a8d31a6a1af7ffcea92a064851d61 to your computer and use it in GitHub Desktop.

Select an option

Save ydm/c51a8d31a6a1af7ffcea92a064851d61 to your computer and use it in GitHub Desktop.
(setq *xs* '(1 (2 (3 (4 5 6) 7) 8 9 ) 10 11))
(defun flatten (xs)
(unless (null xs)
(let ((head (car xs))
(tail (cdr xs)))
;; (message "head=%s tail=%s" (car xs) (cdr xs))
(if (atom head)
(cons head (flatten tail))
(append (flatten head) (flatten tail))))))
(flatten *xs*)
(1 2 3 4 5 6 7 8 9 10 11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment