I was looking for a tree-drawing utility, to depict the syntax trees generated by a compiler I wrote in Prolog in order to teach a friend how compilers work. I have just found Christoph Lehner's Prolog Tree Drawing Program.
His program can be downloaded from the link above,
which also shows some examples. It
displays trees as ASCII. Here are some examples
which I tried,
passing various terms to the main predicate
3 ?- drucke_baum( 1 ). 1 true. 4 ?- drucke_baum( a ). a true. 5 ?- drucke_baum( 1+a ). + | / \ 1 a true . 6 ?- drucke_baum( sum( [1,2,3] ) ). sum | | . _|_ / \ 1 . _|_ / \ 2 . _| / \ 3  true . 7 ?- drucke_baum( root( a, b(1), c(3,4), d(e(5),f(g(6))), h ) ). root ________|_______ / | | | \ a b c d h | | | | / \ / \ 1 3 4 e f | | | | 5 g | | 6 true .
Notice that the program displays lists in terms of their underlying representation: the list
.(1, .(2, .(3, )))
I tried the program under SWI-Prolog for XP, version 5.6.64. Consulting it gave me lots of singleton-variable warnings, which can be ignored. It also gave three errors, which I fixed (correctly, I hope) as follows:
'\\'. This escapes the backslash. Otherwise, SWI will complain about a string being too long.
not. On SWI,
notisn't an operator, so needs a bracketed argument.
compound. This is built in to SWI, and will provoke an error about attempted redefinition.