Generic Function Copy-Template (1 method)

( copy-template < object > )

Part of:

package metabang.moptilities

suppose you have an object

? (defclass foo ()
((test :accessor test :initform #'equal :initarg :test)))
==> #<STANDARD-CLASS FOO>

? (setf *foo* (make-instance 'foo :test #'eql))
? (test *foo*) => #'eql

Now you want to make another instance of foo that has the test as foo.

? (setf *new-foo* (make-instance (type-of foo)))
? (test *new-foo*) => #'equal

Wait, we wanted *new-foo* to have slot test to be #'eql. This seems trival
for simple objects, but consider this from make-filtered-graph

(make-graph (type-of old-graph)
:vertex-test (vertex-test old-graph)
:vertex-key (vertex-key old-graph)
:edge-test (edge-test old-graph)
:edge-key (edge-key old-graph)
:default-edge-type (default-edge-type old-graph)
:default-edge-class (default-edge-class old-graph)
:directed-edge-class (directed-edge-class old-graph)
:undirected-edge-class (undirected-edge-class old-graph))))
Yuck!

So we offer copy-template as a reasonable, though not perfect, solution.

Method Summary

copy-template < standard-object >