looking for answers to exercises in Squeak book Ch 2.

txporter at mindspring.com txporter at mindspring.com
Thu Apr 26 19:45:15 UTC 2001


As a new Squeaker, I am slowly making my way through Mark's book on Squeak.

At the end of chapter 2, there are some exercises, specifically No. 3:
Write a piece of workspace code [...] to do the following:
(a) Replace all vowels in the string 'Squeak' with dashes.
(b) Compute the average of a set of integers in an array.

I did this like so, but think it is more like "procedural-language speak' and not Smalltalk.  Anyone have any more elegant solutions?  I particularly do not like the use of the aCount variable.

aString := 'squeak'.
aCount := 1.
aString do: [:element | element isVowel ifTrue:
	[aString at: aCount put: $-]. "Could aString be self?"
	aCount := aCount +1].

anArray := #(12 14 16 18 20).
aSum := 0.
aCount := 0.
anArray do: [:num | aSum := aSum + num.
	aCount := aCount +1].
anAverage := aSum / aCount.

Sorry for such a trivial start, but I really want to grok the OO way to do this.

Tom Porter





More information about the Squeak-dev mailing list