Michael said <<
Hi Andy,
why would the message have to be binary anyway? If you want the k-th Fibonacci number, why don't you just send #fib to k?
Regarding symbols vs. not symbols: all selectors are symbols, internally. I might get something in your e-mail wrong - could you restate the question?
Hi Michael Thanks very much for your thoughts. Let me try to explain myself, slightly more clearly!
First, this was just an experiment. I was reading a book on Python, saw how they did it, and thought I would try in Squeak. So, I hadn't really thought about how I was going to use it. I like your suggestion about implementing is as: anInteger #fib. However, thinking about implementing it as a binary message made me curious about why I couldn't do that.
The specific problem I am having is: If I define an Integer method such as
<<<*** aNumber
Squeak is quite happy to let me create it. However, if I do something like fib aNumber, the compiler complains that aNumber is a unknown variable, which I need to define. So, what I was really trying to understand was what it was about the e.g. <<< symbol which allowed it to have an undeclared argument.
I think that, based on your last message, it is just that <<< etc have been defined as special characters. Is that correct?
Cheers Andy
Hi Andy,
On Sun, Nov 15, 2009 at 11:19 PM, Andy Burnett andy.burnett@knowinnovation.com wrote:
The specific problem I am having is: If I define an Integer method such as
<<<*** aNumber
Squeak is quite happy to let me create it. However, if I do something like fib aNumber, the compiler complains that aNumber is a unknown variable, which I need to define.
this is simpler than you may have thought. :-)
It's all about syntaaaaaaaaaaaaaaaaaaax. If you want to implement the method as a binary message (with special characters), everything is fine - as you yourself noticed. But if you want to implement it as a so-called keyword message (i.e., where the selector consists of alphanumeric characters), you have to insert a colon (:) after each of the keywords.
The solution would be not to write
fib aNumber
but
fib: aNumber
instead. That way, the parser knows where to look for parameters. ;-)
(((And if you have keyword messages with multiple parameters, use a colon wherever a parameter needs to be placed, e.g., fib: aNumber fob: anotherNumber fub: whatever - just browse the image to see how the different things are done. But I assume you actually know that.)))
So, what I was really trying to understand was what it was about the e.g. <<< symbol which allowed it to have an undeclared argument.
The argument to a binary message is not undeclared; the simple fact that the message is binary *implies* there will be a parameter.
Am I making sense?
Best,
Michael
beginners@lists.squeakfoundation.org