Last updated at 2:08 pm UTC on 16 January 2006
Part of the solutions – based on an email by Bert Freudenberg to the German Smalltalk users group
- How many words are there in a aString?"
('a sample string' findTokens: ' ') size
- How many different words are there in aString?
('a a sample sample string' findTokens: ' ') asSet size
- How many appearances are there of each kind of word in aString?
long answer (OK but does not take in account that there is already a class just for doing this)
| aDictionary aCollection aValue |
aDictionary _ Dictionary new.
aCollection _ ('a a sample string' findTokens: ' ').
aCollection do: [:each |
aValue _ aDictionary at: each ifAbsent: .
aValue _ aValue + 1.
aDictionary at: each put: aValue].
('a a sample string' findTokens: ' ') asBag inspect
You may as well send #sortedElements or #sortedCounts to the result.
- see Display
- What are the concrete collection classes?
- What are Dictionaries? See Dictionary
- What is a SystemDictionary? what is it's name? what does it include?
- Why is the method gcd: important? what is the best way of finding out the answer to this question?
- Look at some source. Right click on it. choose more until you see explain, format, and such. Explain what they and the other menu choices do. Some of them offer you a menu of possibilities. Play with them, explain what they do in general.
- What are the control structures in Squeak? (hint: what is similar about #ifTrue:ifFalse:, #whileTrue:, #do:, #inject:into:..... ? what is it that allows them to be control structures? look for that in other messages.)
17: My suggestion:
thisContext method tempNames
where's the rest gone?