Skip to content

Instantly share code, notes, and snippets.

@erjoalgo
Last active April 30, 2018 05:37
merge
(defun merge-structs (type &rest objs)
"values appearing earlier have higher precedence. nil interpreted as undefined"
(loop with ret = (make-instance type)
with slots = (loop for slot in (sb-mop:class-direct-slots (find-class type))
collect (slot-value slot 'SB-PCL::NAME))
for obj in (reverse objs) if obj do
(loop for slot in slots
as val = (slot-value obj slot)
if val do
(setf (slot-value ret slot) val))
finally (return ret)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment