Package or something to pretty print a tree?

I’m using: SWI-Prolog version 8.1.9

I have a simple tree in my app without any loops between nodes. Each node has a list of child nodes and that structure descends downwards recursively. So the tree starts with a single node and grows wider as you descend to the terminal nodes. For example:

        child_1, [child_1_grandchild_1(), child_1_grandchild_2(), ...], 
        child_2, ([child_2_grandchild_1(), ...]).

Nothing surprisingly new I’m sure. What I’d like is some package or library that can draw a tree with nice arrows connecting ancestor nodes to child nodes (all pointing downwards). Even if it’s not written in Prolog, I’d like it to be callable from SWI-Prolog so I can call it at any time to check the structure of my tree(s).

Is there such a thing? I’m hoping I don’t have to reinvent the wheel here since I’m terrible with graphics. If there isn’t something like this then even something with “ASCII graphics” for the arrows that spaced things nicely would still be a big help.

Anything like this?

A recent post here just did something like this in SWISH. Go to bottom of SWISH page and click on triangle to run example.


1 Like

Nice! Thanks Eric.