Skip to content

Instantly share code, notes, and snippets.

@erjoalgo
Last active April 30, 2018 05:37
Show Gist options
  • Save erjoalgo/1b9dcb5f317639e4b4971255c8b3c5cd to your computer and use it in GitHub Desktop.
Save erjoalgo/1b9dcb5f317639e4b4971255c8b3c5cd to your computer and use it in GitHub Desktop.
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