writing my own method problem .

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

writing my own method problem .

Roelof
Hello,

I have to make my own method but when I enter this:

testShout
   self.assert: ( 'Do not panic' shout = "DO NO PANIC")

The editor makes this :

testShout
   self. Nothing more expected ->assert: ( 'Do not panic' shout = "DO NO
PANIC")

And I do not get a message that shout does not exist.

Roelof


Reply | Threaded
Open this post in threaded view
|

Re: writing my own method problem .

EstebanLM
you are using a dot:

self DOT assert: is wrong syntax.

you need just a space:

self assert:

Esteban

On 30 Mar 2014, at 11:26, Roelof Wobben <[hidden email]> wrote:

> Hello,
>
> I have to make my own method but when I enter this:
>
> testShout
>  self.assert: ( 'Do not panic' shout = "DO NO PANIC")
>
> The editor makes this :
>
> testShout
>  self. Nothing more expected ->assert: ( 'Do not panic' shout = "DO NO PANIC")
>
> And I do not get a message that shout does not exist.
>
> Roelof
>
>


Reply | Threaded
Open this post in threaded view
|

Re: writing my own method problem .

Roelof
Esteban Lorenzano schreef op 30-3-2014 16:31:

> you are using a dot:
>
> self DOT assert: is wrong syntax.
>
> you need just a space:
>
> self assert:
>
> Esteban
>
> On 30 Mar 2014, at 11:26, Roelof Wobben <[hidden email]> wrote:
>
>> Hello,
>>
>> I have to make my own method but when I enter this:
>>
>> testShout
>>   self.assert: ( 'Do not panic' shout = "DO NO PANIC")
>>
>> The editor makes this :
>>
>> testShout
>>   self. Nothing more expected ->assert: ( 'Do not panic' shout = "DO NO PANIC")
>>
>> And I do not get a message that shout does not exist.
>>
>> Roelof
>>
>>
>
>

Thanks,
it worked,
Now a problem with the arrow above.
According to the manual I have to type ^).
But then I see the same error message as above.

Roelof

Reply | Threaded
Open this post in threaded view
|

Re: writing my own method problem .

Sergi Reyner
In reply to this post by Roelof
2014-03-30 15:26 GMT+01:00 Roelof Wobben <[hidden email]>:
testShout
  self. Nothing more expected ->assert: ( 'Do not panic' shout = "DO NO PANIC")

There are some things wrong with the second line:
  • there´s a period after self, you must remove it
  • you wrote NO instead of NOT, so the the assert will fail
  • the sentence in capitals is surrounded by double quotes $" which are for comments; strings are surrounded by single quotes $' , this makes your code actually be:
( 'Do not panic' shout = )


To write the return operator, ^, I can use one of these two combinations in my linux box (which has a slightly weird US international keyboard layout):
  • press shift+6 twice
  • press shift+6, then press space

As an additional note, you don´t actually need the parentheses there, because the order of evaluation is:
  • unary messages (#shout)
  • binary messages (#=)
  • keyword messages (#assert:)
So you can write:

testShout
^ self assert: 'do not panic' shout = 'DO NOT PANIC'


Hope this helps in getting a better grasp of Smalltalk syntax. I found it really easy and fun to learn :)

Cheers,
Sergi
Reply | Threaded
Open this post in threaded view
|

Re: writing my own method problem .

Ben Coman
In reply to this post by Roelof
Roelof Wobben wrote:

> Esteban Lorenzano schreef op 30-3-2014 16:31:
>> you are using a dot:
>>
>> self DOT assert: is wrong syntax.
>>
>> you need just a space:
>>
>> self assert:
>>
>> Esteban
>>
>> On 30 Mar 2014, at 11:26, Roelof Wobben <[hidden email]> wrote:
>>
>>> Hello,
>>>
>>> I have to make my own method but when I enter this:
>>>
>>> testShout
>>>   self.assert: ( 'Do not panic' shout = "DO NO PANIC")
>>>
>>> The editor makes this :
>>>
>>> testShout
>>>   self. Nothing more expected ->assert: ( 'Do not panic' shout = "DO
>>> NO PANIC")
>>>
>>> And I do not get a message that shout does not exist.
>>>
>>> Roelof
>>>
>>>
>>
>>
>
> Thanks,
> it worked,
> Now a problem with the arrow above.
> According to the manual I have to type ^).
> But then I see the same error message as above.
>
> Roelof
>
>
Happy to help*  if you can give the whole line, or a page and a line
number from PBE.  Otherwise its shooting in the dark trying to guess
what you need.

cheers -ben

*except I'm off to bed right now - but I'm sure that with that info
someone else can chime in.