A tree structure   (i.e. a rooted, connected acyclic graph)   is often used in programming.

It's often helpful to visually examine such a structure.

There are many ways to represent trees to a reader, such as:

   indented text   (à la unix  tree  command)
   nested HTML tables
   hierarchical GUI widgets
   2D   or   3D   images
   etc.
Task

Write a program to produce a visual representation of some tree.

The content of the tree doesn't matter, nor does the output format, the only requirement being that the output is human friendly.

Make do with the vague term "friendly" the best you can.




(defun visualize (tree)
  (labels
      ((rprint (list)
         (mapc #'princ (reverse list)))
       (vis-h (tree branches)
         (let ((len (length tree)))
           (loop
              for item in tree
              for idx from 1 to len do
                (cond
                  ((listp item)
                   (rprint (cdr branches))
                   (princ "+---+")
                   (let ((next (cons "|   "
                                     (if (= idx len)
                                         (cons "    " (cdr branches))
                                         branches))))
                     (terpri)
                     (rprint (if (null item)
                                 (cdr next)
                                 next))
                     (terpri)
                     (vis-h item next)))
                  (t
                   (rprint (cdr branches))
                   (princ item)
                   (terpri)
                   (rprint (if (= idx len)
                               (cdr branches)
                               branches))
                   (terpri)))))))
    (vis-h tree '("|   "))))