Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. (defun deepth (list)
  2. (if (atom list)
  3. 0
  4. (1+ (reduce (function max) list :key (function deepth) :initial-value 0))))
  5.  
  6. (defun flatten-before-deepest (list)
  7. (case (deepth list)
  8. (0 list)
  9. (1 list)
  10. (2 (flatten list))
  11. (otherwise (mapcar (function flatten-before-deepest) list))))
  12.  
  13. (flatten-before-deepest '(a (b (c) d) e ((f g) h i) j))
  14. ;; --> (a (b c d) e (f g h i) j)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement