Animal tutorial question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Animal tutorial question

mchean
I am not clear why :

tiger name first isVowel ifTrue: ['an '] ;

ifFalse: ['a '].

evaluates, but :

tiger name first isVowel;

    ifTrue: ['an '];

    ifFalse: ['a '].

gives me a 'Must be boolean error'

Please excuse the double spaceing, Im not sure why this is happening in my
news reader.

Mike


Reply | Threaded
Open this post in threaded view
|

Re: Animal tutorial question

Wayne Johnston
Michael Chean wrote:

> tiger name first isVowel;
>     ifTrue: ['an '];
>     ifFalse: ['a '].
>
> gives me a 'Must be boolean error'

The problem is those semicolons.  Leave them out.  You are doing a
"cascade".  The object answered by #first (a character) is sent the
#isVowel message, and is also being sent the #ifTrue: message, and is also
being sent the #ifFalse: message.  Instead, you want to send the
#ifTrue:ifFalse: message to the Boolean which #isVowel answers.
--
Wayne


Reply | Threaded
Open this post in threaded view
|

Re: Animal tutorial question

mchean
I guess I'm a little unclear on the cascading, and that probably has to do
with the fact the in Foxpro, the semicolon is
used as a line extension.   I'll go back and reread the section in the
tutorial.

Thanks
Mike


Reply | Threaded
Open this post in threaded view
|

Re: Animal tutorial question

Costas Menico
On Thu, 9 Aug 2001 09:47:41 -0700, "Michael Chean"
<[hidden email]> wrote:

>I guess I'm a little unclear on the cascading, and that probably has to do
>with the fact the in Foxpro, the semicolon is
>used as a line extension.   I'll go back and reread the section in the
>tutorial.

Michael,

Unlike FP, Smalltalk does not need a line continuation since it has a
line termination. This means a "line" can be on as many lines as you
wish to express and end it with a period.

A ; is used for cascading statements. Cascading in Smalltalk is just a
shortcut to save you from repeating the object over and over when
sending messages to it.

A simple example of cascading is:

animal:= Dictionary new.

animal at: 1 put: 'cat'; at: 2 put: 'tiger';  at: 3 put: 'lion'.

otherwise you would have to do:

animal at: 1 put: 'cat'.
animal at: 2 put: 'tiger'.
animal at: 3 put: 'lion'.


costas


Reply | Threaded
Open this post in threaded view
|

Re: Animal tutorial question

mchean
Costas:

Thank-you!

"Costas Menico" <[hidden email]> wrote in message
news:[hidden email]...
> On Thu, 9 Aug 2001 09:47:41 -0700, "Michael Chean"
> <[hidden email]> wrote:
>
> >I guess I'm a little unclear on the cascading, and that probably has to
do

> >with the fact the in Foxpro, the semicolon is
> >used as a line extension.   I'll go back and reread the section in the
> >tutorial.
>
> Michael,
>
> Unlike FP, Smalltalk does not need a line continuation since it has a
> line termination. This means a "line" can be on as many lines as you
> wish to express and end it with a period.
>
> A ; is used for cascading statements. Cascading in Smalltalk is just a
> shortcut to save you from repeating the object over and over when
> sending messages to it.
>
> A simple example of cascading is:
>
> animal:= Dictionary new.
>
> animal at: 1 put: 'cat'; at: 2 put: 'tiger';  at: 3 put: 'lion'.
>
> otherwise you would have to do:
>
> animal at: 1 put: 'cat'.
> animal at: 2 put: 'tiger'.
> animal at: 3 put: 'lion'.
>
>
> costas