Hello, working through the 'Programming with Robots' book, the next annoyance I've come to is on setting colors for objects/robots (p64 in the book). In the following - simplified - example:
| pica | pica := Bot new. pica color: Color red. # all well so far pica color: Color r:1 g:1 b:0 .
-this is as per the book but throws up a message 'MessageNotUnderstood: Bot>>color:r:g:b' Trying various syntax changes doesn't help. The text in the book reads: "For example, the expression Color r: 1 g: 0 b: 0 creates the same pure red color that you get from Color red." Maybe I'm missing something obvious, and I know I can use names for the colo(u)rs, but it's annoying to hit a bump like this. Any suggestions?
-- Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
pica color: Color r:1 g:1 b:0 .
-this is as per the book but throws up a message 'MessageNotUnderstood: Bot>>color:r:g:b'
I would expect this to work
pica color: ( Color r: 1 g: 1 b: 0 ).
this sends the message #r:g:b: to the class Color and then the result of that is used as the argument to the message #color: to the object pica.
Without the parenthesis you will be sending the message #color:r:g:b: which, as the message informed you, pica doesn't understand.
There is a variation of Smalltalk called Self which changed the syntax slightly to reduce this confusion a bit. In Self the first element of a keyword message starts with a lower case letter while the second and following parts start with capital letter. This allows you to get by with fewer parenthesis since this code could be written in Self as
pica color: Color r: 1 G: 1 B: 0.
Of course, this causes its own set of confusions. So in Squeak we just have to put in the parenthesis to make it clear what we mean. Note that this has been this way since 1976, so it seems strange that the book would get it wrong.
-- Jecel
OK, thanks for that, the solution works fine.
-- Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
beginners@lists.squeakfoundation.org