power of a number
Cornelius Huber
corny at impara.de
Mon May 23 13:05:15 UTC 2005
Guenther Schmidt wrote:
> Hi,
>
> I can't figure this out by myself.
>
> I want to do an arithmetic expression like:
>
> 2 power 3, ie. (2 * 2 * 2).
>
> What's the right syntax in Squeak Smalltalk?
>
> Günther
>
my suggestion would be to implement a method called power: in the
category Number
power: aNumber
| result |
aNumber timesRepeat: [result := result * self].
^result.
Of Course in the case of power, there is already a method implemented
called 'raisedTo:'
Corny
More information about the Squeak-dev
mailing list
|