I am trying to understand self language.

My doubt is that, whether cloning in self language deep clone or shallow one. I.e., whether clone just clones objects slots or objects inside the slots are get cloned.

有帮助吗?

解决方案 2

Typically, clones in self are shallow copies.

Regarding your comment, yes it would change. That is why you clone “empty” prototypes.

Note that self knows about copy-downs to selectively copy slot content one level deeper when you clone a prototype to make a new one.

其他提示

As Tobias says, typically the copy message is implemented as a shallow copy.

Semantically, copy in Self pretty much means 'give me a safe/useful copy'. For many objects this is just a shallow copy.

Objects are responsible for implementing their own copy, either by delegating to a pure shallow copy method such as the implementation in traits clonable or by having their own copy slot.

For example, morphs typically respond to the copy message by giving you a usable copy, rather than a shallow copy. Also objects which shouldn't be copied often implement or delegate to a method copy = (self) so that attempts to copy just return the original object.

If you want a strict shallow copy, most copiable objects will respond to clone though this should be used with care. And at the base is the VM defined primitive method _Clone which is a shallow copy.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top