SWT Related point

Stephane Ducasse ducasse at iam.unibe.ch
Mon Apr 30 08:54:38 UTC 2001


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

Hi Ned 

Seeing your solution makes me reacting, again ;)

I was browsing Array recently and I was really thinking why array
should defined methods like average?
I see no point to have it there with some others.
Because we could have quantil, 3of10Max, 3of10Min......

May be something for SWT?

This also raises the following question:
John have you thought about a mechanism that would automatically list
all the new/removed methods in comparison to SqC images. This
would be really interesting/necessary.
May be this could be a cool small project where you could ask for
contributors?

Stef







on 4/26/01 9:55 PM, Ned Konz at ned at bike-nomad.com wrote:

> On Thursday 26 April 2001 12:45, txporter at mindspring.com wrote:
>> 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].
> 
> 'squeak' collect: [ :ea | ea isVowel ifTrue: [ $- ] ifFalse: [ ea ]]
> 





More information about the Squeak-dev mailing list