I presumed shallowCopy for literal arrays / OrderedCollection should have
been a true copy. Perhaps need to understand this..

shallowCopy
    "Answer a copy of the receiver which shares the receiver's instance
variables. It should never be overridden. I'm invoked from the copy
template method. Subclasses that need to specialize the copy should
specialize the postCopy hook method."
   ...
    <primitive: 148>
    class := self class.
    class isVariable
        ifTrue:
            [...   newObject :=* class basicNew: index*. ....]
        ifFalse: [newObject := *class basicNew*].
    ..
        whileTrue:
            [newObject instVarAt: index put: (self instVarAt: index).
           ...
    ^ newObject

On Wed, Feb 18, 2015 at 10:52 PM, Marcus Denker <marcus.den...@inria.fr>
wrote:

>
> On 18 Feb 2015, at 18:13, Cameron Sanders via Pharo-users <
> pharo-users@lists.pharo.org> wrote:
>
>
> *Date: *18 Feb 2015 18:12:33 CET
> *Subject: **i feel dumb / Pharo3 > OrderedCollection >> do:*
> *From: *Cameron Sanders <camsand...@aol.com>
> *To: *Any question about pharo is welcome <pharo-users@lists.pharo.org>
>
>
> I must be making some silly error here that i cannot see clearly. Why does
> the following leave anything in the list 'a'? Run it in a workspace. With
> or without the shallowCopy, i am left with a list with half of the elements
> in it. Always half.
>
> This version of Pharo3 (21.0) was downloaded last week. I am running on a
> Mac.
>
> Thanks in advance. ... Maybe I just need more coffee.
> -Cam
>
> | a  |
> a := {  #a. #b. #c. #d. } asOrderedCollection.
> a shallowCopy do: [ :item | (a includes: item) ifTrue: [ a remove: item ]].
> a size
>
>
> shallowCopy is not enough… OrderedCollection is made up of an internal
> array.
>
> #copy does the right thing, just copies the array:
>
> postCopy
> array := array copy
>
> and for Array, copy is a shallowCopy.
>
> Marcus
>
>
>
>

Reply via email to