You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest making it a method so that users can specialize the copy on their own specific objects.
Indeed, the above function assumes that the initarg is the keyword version of the slot name. This is a strong assumption that won't work in all cases.
The above function copies the slots in the make-instance call so that initialize-instance :after has the slots set the right values already. Without this requirement, we could first call make-instance without initializing any slot and then loop over the slots, which has the benefit of not relying on a guess of the initargs. The downside is that some classes require slot values at make-instance time.
Maybe add an argument to allow for deep copies, that is, replace slot-value with copy-object so that it copies the slots recursively.
Thoughts?
The text was updated successfully, but these errors were encountered:
I'll think about this. I don't want to take on the bigger issue of what it means to "copy" something (see Pitman's essay on the subject), but I could see a place for a shallow copy-object function that works for CLOS objects the same way copy-structure works for structs.
I might be missing an existing implementation of
copy-object
, but I find it useful sometimes.Shallow copy:
make-instance
call so thatinitialize-instance :after
has the slots set the right values already. Without this requirement, we could first call make-instance without initializing any slot and then loop over the slots, which has the benefit of not relying on a guess of the initargs. The downside is that some classes require slot values atmake-instance
time.slot-value
withcopy-object
so that it copies the slots recursively.Thoughts?
The text was updated successfully, but these errors were encountered: