\section{Catalog} The catalog is a collection of known types and functions that can be searched so they can be reused when needed. The catalog includes the public interface to the Max system with its utilities for creating new types and functions. The catalog is implemented by a pointer to a set of functions. When a module defines a new function that it wants to publish, the module adds the address of the function to the catalog. Using the set of published functions, you can search for a function or functions with specified domains or codomains. A set of public types is automatically maintained in parallel with the set of public functions. If a function is registered with the catalog, and it takes or returns a new type that was not previously known to the catalog, the type is automatically added to the set of public types. \subsection{Implementation} <>= (in-package max) (defparameter public-functions (make-ptr (get-empty-set *functions*))) ; This should be a Max continuation (defun add-public-function (funcaddr) (change-ptr public-functions (set-add (deref-ptr public-functions) funcaddr)) ) (defun get-public-functions () (deref-ptr public-functions) ) (add-init-hook #'(lambda () (let ((get-public-functions (make-function 'builtin-function *null-type* *set-type* #'(lambda (ignore-nil) (get-public-functions) )) )) (add-public-function get-public-functions) (add-name get-public-functions "public-functions") ) )) (defun public-interface (typeaddr) (let ((interface (get-empty-set *functions*))) (mapset #'(lambda (item) (if (or (addr-equal (function-apply *domain* item) typeaddr) (addr-equal (function-apply *codomain* item) typeaddr)) (setq interface (set-add interface item))) ) (get-public-functions) ) interface ) ) (add-init-hook #'(lambda () (let ((public-interface (make-function 'builtin-function *types* *set-type* #'(lambda (sometype) (public-interface sometype) )) )) (add-public-function public-interface) (add-name public-interface "public-interface") ) )) (defun get-public-types () (let ((types (get-empty-set *types*))) (mapset #'(lambda (item) (setq types (set-add (set-add types (function-apply *domain* item)) (function-apply *codomain* item)) ) ) (get-public-functions) ) types ) ) (add-init-hook #'(lambda () (let ((get-public-types (make-function 'builtin-function *null-type* *set-type* #'(lambda (ignore-nil) (get-public-types) )) )) (add-public-function get-public-types) (add-name get-public-types "public-types") ) )) @