Smalltalk Best Practice Patterns Volume 1: Coding - Free
Smalltalk Best Practice Patterns Volume 1: Coding - Free
Smalltalk Best Practice Patterns Volume 1: Coding - Free
- No tags were found...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
ConcatentationHow do you put two collections together?Concatentation is one of those intermediate idioms in most languages. You can get along without it,but pretty soon you have to learn how. The typical concatenation idiom goes something like this:1. Allocate a collection big enough for the result.2. Copy the first collection into the first part of the result.3. Copy the second collection into the second part of the result.Sometimes there is a library function to do both copies for you.<strong>Smalltalk</strong> simplifies this to a single message you send to the first collection, “,” (comma), with thesecond collection as an argument.Many programming language treat strings specially. Often the “+” (plus) operator is used for stringconcatenation. In <strong>Smalltalk</strong>, Strings are just collections of characters. All the usual collectionprotocol works. In particular, to concatenate strings, you use “,”, just as you would if you weredealing with Arrays or OrderedCollections.Concatenate two collections by sending “,” to the first with the second as an argument.You may need a Concatenating Stream if you are putting together lots of collections.<strong>Coding</strong> <strong>Patterns</strong> page 104 of 147 9/30/2006