"Brian" == Brian Murphy-Dye brian@murphydye.com writes:
Brian> My understanding as well is that this is the purpose of #become:, but Brian> also that it is not very efficient in some versions of Smalltalk. If Brian> you are using an OrderedCollection, this is probably a reasonably Brian> efficient method as it doesn't need to search through the whole list Brian> every time it removes an element:
Brian> removeAll Brian> [self notEmpty] whileTrue: [self removeLast]
What makes you think #removeLast doesn't need to search through the whole list in some kinds of OrderedCollection? You *do* have an implementation assumption there.
I'd just do:
removeAll self notEmpty ifTrue: [self become: self species new].
and let subclasses make it more efficient using implementation knowledge.