\section{Names} This module provides the ability to associate names with Max objects. Max uses direct references in a single address space, so names are not required for proper operation. However, names are very useful for humans as a basic form of documentation. We would like a Max object to possibly have zero, one, or more names, so names are implemented using a binary relation between the Objects type and the String type. <>= (in-package max) (defparameter *names* (make-ptr (get-empty-set (type-product *objects* *string-type*)))) (defun add-name (obj name) (let ((names (deref-ptr *names*))) (change-ptr *names* (set-add names (make-product-addr (set-type names) (list obj (make-string-address name))))) ) ) (defun get-names () (deref-ptr *names*) ) (add-init-hook #'(lambda () (let ((get-names (make-function 'builtin-function *null-type* *set-type* #'(lambda (ignore-nil) (get-names) )) )) (add-public-function get-names) (add-name get-names "names") ) )) @ Given an object, return a set of strings naming it. Create a function that given an tuple, returns the name part. Then pass that function to UPDATE to create a new set from the NAMES relation. That's a selection [obj=obj] followed by projection [name], which could be a composition of Max functions. Since we don't have projection yet, pass a builtin function to UPDATE. We also don't have equality in Max yet, so we also pass a builtin function to SELECT. <>= (defun names (obj) (let ((result (get-empty-set *string-type*))) (mapset #'(lambda (item) (if (addr-equal obj (first (product-values item))) (setq result (set-add result (make-address-form (addr-value *string-type*) (second (product-values item)) ) ) ) ) ) (deref-ptr *names*) ) result ) ) @ Return a set of objects with a given name. <>= (defun lookup (name) (let ((result (get-empty-set *objects*))) (mapset #'(lambda (item) (if (addr-equal name (second (product-values item))) (setq result (set-add result (make-address-form (addr-value *objects*) (first (product-values item)) ) ) ) ) ) (deref-ptr *names*) ) result ) )