(defun serialize-common (object transaction-log fn) (with-accessors ((object-id-table object-id-table) (next-object-id next-object-id) (log-stream log-stream)) transaction-log (let ((id (gethash object object-id-table))) (if (null id) (progn (setf id (incf next-object-id)) (setf (gethash object object-id-table) id) (funcall fn object id log-stream transaction-log)) (format log-stream "#~d^" id))))) (defmacro with-serialize-common ((object transaction-log id log-stream) &body body) `(serialize-common object transaction-log (lambda (,object ,id ,log-stream ,transaction-log) ,@body))) (defmacro def-serialize-method (((object class) transaction-log) (id log-stream) &body body) `(defmethod serialize ((,object ,class) ,transaction-log) (with-serialize-common (,object ,transaction-log ,id ,log-stream) ,@body)))