18.4 Dispatch

  (de dispatch (item depth)  
    (cond ((instance item)  
           (apply (find-instance-template item)  
                  (list item depth)))  
          ((atom item)  
           (apply (find-atom-template item)  
                  (list item depth)))  
          ((> depth ⋆maxdepth⋆) (add-tokens "#"))  
          ((has-template item)  
           (apply (get-template item)  
                  (list item (add1 depth))))  
          (t (default-template item (add1 depth)))))))

It is useful to know how this function associates a format function with an expression. If the expression is an instance of a flavor then the dispatch function will search for a format function associated with the name of the flavor. For other atomic expressions, the type is used to locate a format function. Currently there are format functions for vectors, strings, numbers, code-pointers and identifiers. If the expression is a list and the first element of this list is an identifier then an attempt is made to find a format function associated with the identifier. Before resorting to a default a check is made for function application for which there is a separate default format function.

Function application is recognized when the first element of the list is a lambda expression, an application of getd to the first element returns a non-nil value, or the first element is an id which is a member of a global list named *function_names*. This list of function names is useful for prettyprinting a file since a file will normally contain a number of applications of functions defined within the file itself. The fexpr add-functions accepts any number of function names and adds then to *function_names*.

With respect to lists, any sub-expression below a maximum depth is printed as ‘#'. Once the maximum length of a list has been reached the display of the remaining elements will be ‘...’. The maximum depth (initially 10) and length (initially 25) can be modified with the functions new-depth and new-length.