Open gefjon opened 2 years ago
Neat! I tried writing something like this to chase this same pattern, and I was unhappy about having to treat struct and class instances separately, so it never made it in. Some years older and wiser, I think it’s a good enough idea that it should go in anyway.
I think the only way to do this for subclasses of structure-object
is to define individual methods, though probably via a macro. But neither the CL spec nor the MOP defines any way to write a generic method.
Oh, speaking of which, the default method for copy-instance
should really specialize on standard-object
, not on t
. I'll make that change tomorrow and see if it breaks anything.
ETA: let's all take this as a lesson to prefer defclass
over defstruct
unless profiling suggests a performance incentive otherwise.
You can now do e.g.
(copy-instance SOME-BINARY-CLASSICAL-INSTRUCTION :left NEW-LEFT-OPERAND)
to make a copy ofSOME-BINARY-CLASSICAL-INSTRUCTION
that has itsleft
slot overwritten withNEW-LEFT-OPERAND
. I suspect there are plenty of places in the QuilC code where this would enable a much nicer functional style by eliminating patterns like(let ((copy (copy-instance FOO))) (setf (FOO-BAR FOO) BAR))
.