Preorder
In preorder, the parent node is processed before its children.
Suppose that we want to print out a directory name, then the contents of the directory. We will also indent to show the depth. We assume a directory tree as shown earlier: a directory is a list of the directory name followed by its contents; a non-list is a file.
(defun printdir (dir level) (spaces (* 2 level)) (if (symbolp dir) (progn (prin1 dir) (terpri)) (progn (prin1 (first dir)) (terpri) (dolist (contents (rest dir)) (printdir contents (+ level 1)) ) ) ) )