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 [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Jan 14, 2008 3:42 PM, Jakub <[hidden email]> wrote:
> I look for clone command in SBE book but i found > nothing. Perhaps you are looking for the #copy method. Also, see #shallowCopy _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Jakub-8
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 > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners Mth _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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 <[hidden email]>: Hi Jakub -- Jakub. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Jakub" == Jakub <[hidden email]> 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 <[hidden email]> <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 [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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 <
[hidden email]> wrote: >>>>> "Jakub" == Jakub < [hidden email]> writes: _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Marcin" == Marcin Tustin <[hidden email]> 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 <[hidden email]> <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 [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Jakub-8
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 <[hidden email]>: >> >> 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 >> > [hidden email] >> > http://lists.squeakfoundation.org/mailman/listinfo/beginners >> >> Mth >> >> >> >> _______________________________________________ >> Beginners mailing list >> [hidden email] >> http://lists.squeakfoundation.org/mailman/listinfo/beginners >> > > > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Randal L. Schwartz
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 <[hidden email]> wrote: >>>>> "Marcin" == Marcin Tustin <[hidden email]> writes: _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |