Search the web
Sign In
New User? Sign Up
squeak
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Re: power of a number   Message List  
Reply | Forward Message #94852 of 145391 < Prev |
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




Mon May 23, 2005 1:05 pm

corny@...
Send Email Send Email

Forward
Message #94852 of 145391 < Prev |
Expand Messages Author Sort by Date

... my suggestion would be to implement a method called power: in the category Number power: aNumber ... aNumber timesRepeat: [result := result * self]. ...
Cornelius Huber
corny@...
Send Email
May 23, 2005
1:05 pm

Hi ! If you want ABSOLUTELY a #power: or a #** method you should alias #raisedTo: Number>>power: aNumber ^ (self raisedTo:aNumber) The #raisedTo: method is...
Julien Bourdon
bourdux@...
Send Email
May 23, 2005
1:18 pm

... Others have answered the question. Just so you know, though, Ted Kaehler's method finder is excellent for finding these answers. If you start up Squeak,...
Lex Spoon
lex@...
Send Email
May 23, 2005
2:47 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help