Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tree pretty printer in clojure
(defn print-subtree [subtree prefix]
(if (empty? subtree)
""
(apply str prefix (first subtree) "\n"
(map #(print-subtree %1 (str "\t" prefix)) (rest subtree)))))
(defn print-tree [tree]
(print-subtree tree ""))
(deftest print-empty-tree
(is (= (print-tree
'("parent"
("child1")
("child2"
("grand1")
("grand2"))))
"parent\n\tchild1\n\tchild2\n\t\tgrand1\n\t\tgrand2\n")))
@fatso83

This comment has been minimized.

Copy link

@fatso83 fatso83 commented Apr 29, 2011

Ganske lik mitt forsøk på å skrive lisp i Java, men det ser litt mer elegant ut :-)
https://github.com/fatso83/Code-Snippets/blob/master/Functional%20Dojo/src/no/kopseng/dojo/functional/Node.java (tabbedString3 versjonen)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.