copyEmpty: newSize
"Answer an empty copy of the receiver whose size is newSize"
^self species new: newSize
Clearly, this has a different meaning when the argument to new: is
treated as a capacity. Furthermore, is #(nil nil nil nil nil)
considered an empty Array?
I recently discovered that, due to this discrepancy, OrderedCollections
cannot be used as contents of WriteStreams. This isn't a major problem,
because WriteStreams are after all designed to do the extra work that
OrderedCollections do for you. And Squeak, at least, shares this "feature".
I suppose my real question is whether this method can be rewritten in a
way such that it would work sensibly for OrderedCollections without
expanding the Collection protocol or doing explicit isKindOf: tests? --
not that I would recommend replacing this perfectly sensible
implementation for such a silly purpose at all:
growCollection
"Private - Double the size of the collection or, if its size < 8,
grow it to 8 places"
| size |
size := collection size.
"Guess which collection is which :-)"
collection := ((collection copyEmpty: (size * 2 max: 8))
replaceFrom: 1 to: collection size with: collection startingAt:
1;
yourself).
--
Stephen Compall
http://scompall.nocandysw.com/blog##smalltalk,#gnu-smalltalk on Freenode IRC
_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk