Skip to content

Instantly share code, notes, and snippets.

@gam
Created April 29, 2011 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gam/948247 to your computer and use it in GitHub Desktop.
Save gam/948247 to your computer and use it in GitHub Desktop.
tree pretty printer in clojure - variation
(defn print-tree
([tree]
(print-tree tree ""))
([tree prefix]
(apply str prefix (first tree) "\n"
(map #(print-tree %1 (str prefix "\t")) (rest tree)))))
(deftest print-tree-test
(is (= (print-tree
'(parent
(child1)
(child2
(grandchild1)
(grandchild2)))
"parent\n\tchild1\n\tchild2\n\t\tgrandchild1\n\t\tgrandchild2"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment