Last active
April 30, 2018 05:37
-
-
Save erjoalgo/1b9dcb5f317639e4b4971255c8b3c5cd to your computer and use it in GitHub Desktop.
merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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