I think my understanding of OrderedCollections has been incorrect for a very long time. I have never had a situation where it mattered, but in modeling a current project, I think I have been approaching it incorrectly. Since I have been using Smalltalk, I assumed that a copy of an object is added to an OrderedCollection. A quick test shows that a reference to that object is added to the OrderedCollection. I just wanted a sanity check on this. Is this true with all collections? Thanks! ---- peace, sergio photographer, journalist, visionary Public Key: http://bit.ly/29z9fG0 #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV http://www.codeandmusic.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101 signature.asc (849 bytes) Download Attachment |
Yes, it is the same. Everything is passed by "reference" (*).
And if you copy the collection you'll get two collections referencing the same object. E.g. | a c1 c2 | a := Object new. b := OrderedCollection with: a. b identityIncludes: a. "true" c := b copy. c identityIncludes: a. "true" (*) Some objects like SmallIntegers are "immediate" objects, and could be considered that they're passed by value. E.g. 1 copy == 1 "true" Regards, Esteban A. Maringolo On Wed, Jul 24, 2019 at 9:45 AM sergio ruiz <[hidden email]> wrote: > > I think my understanding of OrderedCollections has been incorrect for a very long time. I have never had a situation where it mattered, but in modeling a current project, I think I have been approaching it incorrectly. > > Since I have been using Smalltalk, I assumed that a copy of an object is added to an OrderedCollection. A quick test shows that a reference to that object is added to the OrderedCollection. > > I just wanted a sanity check on this. Is this true with all collections? > > Thanks! > > > ---- > peace, > sergio > photographer, journalist, visionary > > Public Key: http://bit.ly/29z9fG0 > #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV > http://www.codeandmusic.com > http://www.twitter.com/sergio_101 > http://www.facebook.com/sergio101 > |
Okay.
This makes the entire universe make more sense. Thanks!
---- peace, sergio photographer, journalist, visionary Public Key: http://bit.ly/29z9fG0 #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV http://www.codeandmusic.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101 signature.asc (849 bytes) Download Attachment |
In reply to this post by sergio_101
To a very good approximation, Smalltalk doesn't copy anything unless you ask it to. In this respect it's just like Java, Python, Ruby, ECMAScript, and most OO languages. C++ *does* like to copy things, but it is unusual. On Thu, 25 Jul 2019 at 00:46, sergio ruiz <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |