[Newbies] Re: Defining a binary message selector

Louis LaBrunda Lou at Keystone-Software.com
Mon Nov 16 19:07:41 UTC 2009


Hi Andy,

I may be way off in my understanding of what you are trying to do, if so I
apologize ahead of time.

It looks to me like you want to create a method that will answer the
Fibonacci value for a given number.  Hence your first attempt
Integer>>fibonacci: aNumber.  Where I expect you returned the Fibonacci
value of aNumber.  I think you then moved on to wanting to just a message
and not having to pass aNumber.

This lead to the next attempt with '+'.  This is where I think you went a
little wrong, '+' actually has a parameter.  It normally looks like
someNumber + aNumber or 2 + 3.  Others have suggested using something like
#fib, but didn't explain much more.  This is the way to go, unless you
really want to use some single character, which you could.

If you extend Integer with the #fib method (without the # and no parameter)
you should have what you want.  All you need to do is use the code you had
for Integer>>fibonacci: aNumber and everywhere you had aNumber, replace it
with "self", you will be able to send the #fib message to any integer (like
5 fib) and get the Fibonacci value of the integer the #fib message was sent
to.

I will leave it to others to tell you how to use some special character to
replace #fib, if that is really what you want to do.

Have fun!

Lou

>As an experiment, I tried to create a Fibonacci method for Integer.
>Initially, I defined it as Integer>>fibonacci: aNumber. However, having
>thought about it a bit more I realised that it should probably be a binary
>message like '+'. I tried to create it as such, but Squeak wouldn't let me -
>even when I copied the code from the '+' method.
>
>After a bit of head scratching, I decided that '+' was probably a symbol,
>and that binary messages are probably limited to using symbols as selectors.
>However, I once arrived late to a baseball game (never having seen it played
>before), got confused about which team was which, and invented an entirely
>new scoring system that pretty much explained the results on the
>scoreboard.  So, I may be completely wrong about binary selectors!
>
>If I am right about them requiring to be symbols.  Would it be a good idea
>for meto make 'fibonacci' a symbol as well? Or would that lead to unintended
>problems down the road?
>
>Cheers
>Andy
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou at Keystone-Software.com http://www.Keystone-Software.com



More information about the Beginners mailing list