hello,
i want do i want set var a as all instance vars of b. Something s clone - coppy of one object. I look for clone command in SBE book but i found nothing.
Thnx.
On Jan 14, 2008 3:42 PM, Jakub seasidebeginner@gmail.com wrote:
I look for clone command in SBE book but i found nothing.
Perhaps you are looking for the #copy method. Also, see #shallowCopy
Hi Jakub
I don't really understand your question. What is a and b? Are they instance of the same class?
On Jan 14, 2008, at 10:42 PM, Jakub wrote:
hello,
i want do i want set var a as all instance vars of b. Something s clone - coppy of one object. I look for clone command in SBE book but i found nothing.
Thnx.
-- Jakub. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Mth
yeah a, b instance of same class and i want copy all instance variables values to a i want do a := b but i dont want to a is same object as b. In memory will be two objects a, b with same values .. but if i change a i dont change b.
regards
2008/1/15, Mathieu Suen mathk.sue@gmail.com:
Hi Jakub
I don't really understand your question. What is a and b? Are they instance of the same class?
On Jan 14, 2008, at 10:42 PM, Jakub wrote:
hello,
i want do i want set var a as all instance vars of b. Something s clone - coppy of one object. I look for clone command in SBE book but i found nothing.
Thnx.
-- Jakub. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Mth
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
"Jakub" == Jakub seasidebeginner@gmail.com writes:
Jakub> yeah a, b instance of same class and i want copy all instance variables Jakub> values to a i want do a := b but i dont want to a is same object as b. In Jakub> memory will be two objects a, b with same values .. but if i change a i dont Jakub> change b.
b := a copy.
but you might also want to look at #deepCopy.
So, I take it that clone is a "stupider" (no postCopy polymorphism) version of copy (or shallowCopy). Is that right, or does it do something odd?
On Jan 15, 2008 5:38 PM, Randal L. Schwartz merlyn@stonehenge.com wrote:
"Jakub" == Jakub seasidebeginner@gmail.com writes:
Jakub> yeah a, b instance of same class and i want copy all instance variables Jakub> values to a i want do a := b but i dont want to a is same object as b. In Jakub> memory will be two objects a, b with same values .. but if i change a i dont Jakub> change b.
b := a copy.
but you might also want to look at #deepCopy.
-- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
"Marcin" == Marcin Tustin mm3@zepler.net writes:
Marcin> So, I take it that clone is a "stupider" (no postCopy polymorphism) version Marcin> of copy (or shallowCopy). Is that right, or does it do something odd?
Object>>#clone looks like an optional-implemented primitive that does a #shallowCopy, but without the fallback-to-smalltalk that #shallowCopy performs. Not sure why those are both in the image.
I'd stick with #copy unless I was the implementor of the class being copied, and even then, I'd make copy "do the right thing". :)
Hi,
In squeak copy is implemented as: ^self shallowCopy postCopy
and deepCopy just copy 2 layers of instance, so if the object has tree like sub instance, postCopy must be implemented.
Best regards. -Liu Xinyu
On Jan 16, 2008 2:11 AM, Randal L. Schwartz merlyn@stonehenge.com wrote:
"Marcin" == Marcin Tustin mm3@zepler.net writes:
Marcin> So, I take it that clone is a "stupider" (no postCopy polymorphism) version Marcin> of copy (or shallowCopy). Is that right, or does it do something odd?
Object>>#clone looks like an optional-implemented primitive that does a #shallowCopy, but without the fallback-to-smalltalk that #shallowCopy performs. Not sure why those are both in the image.
I'd stick with #copy unless I was the implementor of the class being copied, and even then, I'd make copy "do the right thing". :)
-- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Hi Jakub,
on Tue, 15 Jan 2008 18:29:53 +0100, you wrote:
yeah a, b instance of same class and i want copy all instance variables values to a i want do a := b but i dont want to a is same object as b. In memory will be two objects a, b with same values ..
If you mean to have class Person and (aPerson := Person new), (bPerson := Person new) and later you want that aPerson has exactly the same instance variables as bPerson, then you might want
aPerson copyFrom: bPerson
This is not often used (it's rather at the system level), because most Smalltalk developers set instance variables by mutators, like
aPerson name: bPerson name. aPerson address: bPerson address. ...
See also the comment in #copyFrom: on the instance side of Object.
Enjoy Smalltalk :)
/Klaus
but if i change a i dont change b.
regards
2008/1/15, Mathieu Suen mathk.sue@gmail.com:
Hi Jakub
I don't really understand your question. What is a and b? Are they instance of the same class?
On Jan 14, 2008, at 10:42 PM, Jakub wrote:
hello,
i want do i want set var a as all instance vars of b. Something s clone - coppy of one object. I look for clone command in SBE book but i found nothing.
Thnx.
-- Jakub. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Mth
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
beginners@lists.squeakfoundation.org