Method Calling Inside Nested Blocks

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

Method Calling Inside Nested Blocks

Mohammad Al Houssami (Alumni)

Hello everyone

 

I was trying to save my method which has the below piece of code

 

anythingElseBoolean = false ifFalse: [

                doctypeString := reader next: 6

                doctypeString asLowercase =  'public'     ifTrue: [

                                AfterDOCTYPEPublicKeywordState value: currentCharacter

                                ]

 

I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name.
If I move the method call outside outside the ifTrue block to the ifFalse block it doesn’t complain.

Is the problem because of nested blocks ? If that’s the case then what would be a good work around ?

 

Thanks

Mohammad

Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

Camillo Bruni-3
I think you just have a missing dot (.) after `reader next: 6`? ;)


On 2013-03-23, at 12:31, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:

> Hello everyone
>
> I was trying to save my method which has the below piece of code
>
> anythingElseBoolean = false ifFalse: [
>                doctypeString := reader next: 6
>                doctypeString asLowercase =  'public'     ifTrue: [
>                                AfterDOCTYPEPublicKeywordState value: currentCharacter
>                                ]
>
> I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name.
> If I move the method call outside outside the ifTrue block to the ifFalse block it doesn't complain.
>
> Is the problem because of nested blocks ? If that's the case then what would be a good work around ?
>
>
> Thanks
> Mohammad


Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

Mohammad Al Houssami (Alumni)
I only use dots at the end of blocks usually but I tried it and it still doesn't work. :/
Its weird..

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Camillo Bruni
Sent: Saturday, March 23, 2013 1:38 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks

I think you just have a missing dot (.) after `reader next: 6`? ;)


On 2013-03-23, at 12:31, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:

> Hello everyone
>
> I was trying to save my method which has the below piece of code
>
> anythingElseBoolean = false ifFalse: [
>                doctypeString := reader next: 6
>                doctypeString asLowercase =  'public'     ifTrue: [
>                                AfterDOCTYPEPublicKeywordState value: currentCharacter
>                                ]
>
> I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name.
> If I move the method call outside outside the ifTrue block to the ifFalse block it doesn't complain.
>
> Is the problem because of nested blocks ? If that's the case then what would be a good work around ?
>
>
> Thanks
> Mohammad





Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

EstebanLM
In reply to this post by Mohammad Al Houssami (Alumni)
you miss a dot:

On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:

anythingElseBoolean = false ifFalse: [
                doctypeString := reader next: 6. "Your dot HERE"
                doctypeString asLowercase =  'public'     ifTrue: [
                                AfterDOCTYPEPublicKeywordState value: currentCharacter
]
 

Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

stephane ducasse
In reply to this post by Mohammad Al Houssami (Alumni)
the following in syntactically valid.
May be you pasted a strange character in your method.

> anythingElseBoolean = false ifFalse: [
>               doctypeString := reader next: 6.
>               doctypeString asLowercase =  'public'     ifTrue: [
>                               AfterDOCTYPEPublicKeywordState value: currentCharacter
>                               ]
]

Now I think that building a HTML parser by hand in 2012 is a strange exercise when
there are compiler compiler or cool framework for parsing like PetitParser.

Stef
Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

EstebanLM
In reply to this post by Mohammad Al Houssami (Alumni)
<base href="x-msg://5763/">
On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:

Hello everyone
 
I was trying to save my method which has the below piece of code
 
anythingElseBoolean = false ifFalse: [
                doctypeString := reader next: 6
                doctypeString asLowercase =  'public'     ifTrue: [
                                AfterDOCTYPEPublicKeywordState value: currentCharacter
                                ]
 
I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name. 

AfterDOCTYPEPublicKeywordState is a METHOD????
then, you are missing some points:

1) it does not conforms conventions (it should start with lowercase)
2) you need a self call

so, it would be like this:

self afterDOCTYPEPublicKeywordState value: currentCharacter. 

but that is also wrong from a design point of view (anti demeters law). So, you better create a (perhaps private) method who does the assignment. And then you have something like this:

self afterDOCTYPEPublicKeywordState: currentCharacter.

Esteban

If I move the method call outside outside the ifTrue block to the ifFalse block it doesn’t complain.

Is the problem because of nested blocks ? If that’s the case then what would be a good work around ?

 
Thanks
Mohammad

Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

Mohammad Al Houssami (Alumni)
<base href="x-msg://5763/">

So the method declaration should be self afterDOCTYPEPublicKeywordState: currentCharacter. ?

 

But I have been doing the same for quite some time and I wasn’t getting any complains. This is the first time and the only thing that changed is that I have two blocks in this case. As I said earlier if I move the method call outside the block it works with no complains J

 

I'll change the names of all my methods to camel case. Thanks for that

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 2:52 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks

 

 

On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:



Hello everyone

 

I was trying to save my method which has the below piece of code

 

anythingElseBoolean = false ifFalse: [

                doctypeString := reader next: 6

                doctypeString asLowercase =  'public'     ifTrue: [

                                AfterDOCTYPEPublicKeywordState value: currentCharacter

                                ]

 

I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name. 

 

AfterDOCTYPEPublicKeywordState is a METHOD????

then, you are missing some points:

 

1) it does not conforms conventions (it should start with lowercase)

2) you need a self call

 

so, it would be like this:

 

self afterDOCTYPEPublicKeywordState value: currentCharacter. 

 

but that is also wrong from a design point of view (anti demeters law). So, you better create a (perhaps private) method who does the assignment. And then you have something like this:

 

self afterDOCTYPEPublicKeywordState: currentCharacter.

 

Esteban



If I move the method call outside outside the ifTrue block to the ifFalse block it doesn’t complain.

Is the problem because of nested blocks ? If that’s the case then what would be a good work around ?


 

Thanks

Mohammad

 

Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

Mohammad Al Houssami (Alumni)
In reply to this post by stephane ducasse
I will be using petit parser at some point. Im currently doing it by hand to learn smalltalk and to get used to the requirements and all the things that come up. I think when I have a good grip on these I can move on to PetitParser.

I made sure no weird characters are there but still doesn't work.
Attached is the whole thing.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of stephane ducasse
Sent: Saturday, March 23, 2013 2:51 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks

the following in syntactically valid.
May be you pasted a strange character in your method.

> anythingElseBoolean = false ifFalse: [
>               doctypeString := reader next: 6.
>               doctypeString asLowercase =  'public'     ifTrue: [
>                               AfterDOCTYPEPublicKeywordState value: currentCharacter
>                               ]
]

Now I think that building a HTML parser by hand in 2012 is a strange exercise when there are compiler compiler or cool framework for parsing like PetitParser.

Stef


AfterDOCTYPENameState.txt (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

EstebanLM
In reply to this post by Mohammad Al Houssami (Alumni)
<base href="x-msg://5763/">if it is a method, it needs the receiver, in this case "self" (remember, any call in smalltalk is: receiver+message).
If for some weird reason you did not need it before (like some chained call effect), that was just by chance... you just were lucky before :)

Esteban

On Mar 23, 2013, at 1:58 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:

So the method declaration should be self afterDOCTYPEPublicKeywordState: currentCharacter. ?
 
But I have been doing the same for quite some time and I wasn’t getting any complains. This is the first time and the only thing that changed is that I have two blocks in this case. As I said earlier if I move the method call outside the block it works with no complains J
 
I'll change the names of all my methods to camel case. Thanks for that
 
 
From: [hidden email] [mailto:pharo-[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 2:52 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks
 
 
On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:


Hello everyone
 
I was trying to save my method which has the below piece of code
 
anythingElseBoolean = false ifFalse: [
                doctypeString := reader next: 6
                doctypeString asLowercase =  'public'     ifTrue: [
                                AfterDOCTYPEPublicKeywordState value: currentCharacter
                                ]
 
I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name. 
 
AfterDOCTYPEPublicKeywordState is a METHOD????
then, you are missing some points:
 
1) it does not conforms conventions (it should start with lowercase)
2) you need a self call
 
so, it would be like this:
 
self afterDOCTYPEPublicKeywordState value: currentCharacter. 
 
but that is also wrong from a design point of view (anti demeters law). So, you better create a (perhaps private) method who does the assignment. And then you have something like this:
 
self afterDOCTYPEPublicKeywordState: currentCharacter.
 
Esteban


If I move the method call outside outside the ifTrue block to the ifFalse block it doesn’t complain.

Is the problem because of nested blocks ? If that’s the case then what would be a good work around ?


 
Thanks
Mohammad


Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

Mohammad Al Houssami (Alumni)
<base href="x-msg://5763/">

Probably because I am not using dots except at the end of blocks which I think is wrong.
This is a sample of what I had earlier:

currentCharacter = CHARACTERTABULATION  ifTrue: [anythingElseBoolean:= false

                AfterDOCTYPENameState value: currentCharacter ].

There should be a dot after false right ? Once I add the dot I get a complain.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 3:09 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks

 

if it is a method, it needs the receiver, in this case "self" (remember, any call in smalltalk is: receiver+message).

If for some weird reason you did not need it before (like some chained call effect), that was just by chance... you just were lucky before :)

 

Esteban

 

On Mar 23, 2013, at 1:58 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:



So the method declaration should be self afterDOCTYPEPublicKeywordState: currentCharacter. ?

 

But I have been doing the same for quite some time and I wasn’t getting any complains. This is the first time and the only thing that changed is that I have two blocks in this case. As I said earlier if I move the method call outside the block it works with no complains J

 

I'll change the names of all my methods to camel case. Thanks for that

 

 

From: [hidden email] [mailto:pharo-[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 2:52 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks

 

 

On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:




Hello everyone

 

I was trying to save my method which has the below piece of code

 

anythingElseBoolean = false ifFalse: [

                doctypeString := reader next: 6

                doctypeString asLowercase =  'public'     ifTrue: [

                                AfterDOCTYPEPublicKeywordState value: currentCharacter

                                ]

 

I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name. 

 

AfterDOCTYPEPublicKeywordState is a METHOD????

then, you are missing some points:

 

1) it does not conforms conventions (it should start with lowercase)

2) you need a self call

 

so, it would be like this:

 

self afterDOCTYPEPublicKeywordState value: currentCharacter. 

 

but that is also wrong from a design point of view (anti demeters law). So, you better create a (perhaps private) method who does the assignment. And then you have something like this:

 

self afterDOCTYPEPublicKeywordState: currentCharacter.

 

Esteban




If I move the method call outside outside the ifTrue block to the ifFalse block it doesn’t complain.

Is the problem because of nested blocks ? If that’s the case then what would be a good work around ?



 

Thanks

Mohammad

 

Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

EstebanLM
<base href="x-msg://5763/">yes, you need to end the statement (with a dot), then add the receiver.

btw... the compiler will not complain if you do not put a dot, but your code will not work, because the compiler will interpret that you are sending the message AfterDOCTYPENameState to the object "false"... and then when you reach that place in your execution, you will have a doesNotUnderstand error :)

Esteban

On Mar 23, 2013, at 2:14 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:

Probably because I am not using dots except at the end of blocks which I think is wrong. 
This is a sample of what I had earlier:
currentCharacter = CHARACTERTABULATION  ifTrue: [anythingElseBoolean:= false
                AfterDOCTYPENameState value: currentCharacter ].
There should be a dot after false right ? Once I add the dot I get a complain.

 
From: [hidden email] [mailto:pharo-[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 3:09 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks
 
if it is a method, it needs the receiver, in this case "self" (remember, any call in smalltalk is: receiver+message).
If for some weird reason you did not need it before (like some chained call effect), that was just by chance... you just were lucky before :)
 
Esteban
 
On Mar 23, 2013, at 1:58 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:


So the method declaration should be self afterDOCTYPEPublicKeywordState: currentCharacter. ?
 
But I have been doing the same for quite some time and I wasn’t getting any complains. This is the first time and the only thing that changed is that I have two blocks in this case. As I said earlier if I move the method call outside the block it works with no complains J
 
I'll change the names of all my methods to camel case. Thanks for that
 
 
From: [hidden email] [mailto:pharo-[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 2:52 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks
 
 
On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:



Hello everyone
 
I was trying to save my method which has the below piece of code
 
anythingElseBoolean = false ifFalse: [
                doctypeString := reader next: 6
                doctypeString asLowercase =  'public'     ifTrue: [
                                AfterDOCTYPEPublicKeywordState value: currentCharacter
                                ]
 
I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name. 
 
AfterDOCTYPEPublicKeywordState is a METHOD????
then, you are missing some points:
 
1) it does not conforms conventions (it should start with lowercase)
2) you need a self call
 
so, it would be like this:
 
self afterDOCTYPEPublicKeywordState value: currentCharacter. 
 
but that is also wrong from a design point of view (anti demeters law). So, you better create a (perhaps private) method who does the assignment. And then you have something like this:
 
self afterDOCTYPEPublicKeywordState: currentCharacter.
 
Esteban



If I move the method call outside outside the ifTrue block to the ifFalse block it doesn’t complain.

Is the problem because of nested blocks ? If that’s the case then what would be a good work around ?



 
Thanks
Mohammad


Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

Mohammad Al Houssami (Alumni)
<base href="x-msg://5763/">

This makes sense now.
Thanks for clarifying the issue Esteban. Much appreciated
J

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 3:23 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks

 

yes, you need to end the statement (with a dot), then add the receiver.

 

btw... the compiler will not complain if you do not put a dot, but your code will not work, because the compiler will interpret that you are sending the message AfterDOCTYPENameState to the object "false"... and then when you reach that place in your execution, you will have a doesNotUnderstand error :)

 

Esteban

 

On Mar 23, 2013, at 2:14 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:



Probably because I am not using dots except at the end of blocks which I think is wrong. 
This is a sample of what I had earlier:

currentCharacter = CHARACTERTABULATION  ifTrue: [anythingElseBoolean:= false

                AfterDOCTYPENameState value: currentCharacter ].

There should be a dot after false right ? Once I add the dot I get a complain.


 

From: [hidden email] [mailto:pharo-[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 3:09 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks

 

if it is a method, it needs the receiver, in this case "self" (remember, any call in smalltalk is: receiver+message).

If for some weird reason you did not need it before (like some chained call effect), that was just by chance... you just were lucky before :)

 

Esteban

 

On Mar 23, 2013, at 1:58 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:




So the method declaration should be self afterDOCTYPEPublicKeywordState: currentCharacter. ?

 

But I have been doing the same for quite some time and I wasn’t getting any complains. This is the first time and the only thing that changed is that I have two blocks in this case. As I said earlier if I move the method call outside the block it works with no complains J

 

I'll change the names of all my methods to camel case. Thanks for that

 

 

From: [hidden email] [mailto:pharo-[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 2:52 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks

 

 

On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:





Hello everyone

 

I was trying to save my method which has the below piece of code

 

anythingElseBoolean = false ifFalse: [

                doctypeString := reader next: 6

                doctypeString asLowercase =  'public'     ifTrue: [

                                AfterDOCTYPEPublicKeywordState value: currentCharacter

                                ]

 

I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name. 

 

AfterDOCTYPEPublicKeywordState is a METHOD????

then, you are missing some points:

 

1) it does not conforms conventions (it should start with lowercase)

2) you need a self call

 

so, it would be like this:

 

self afterDOCTYPEPublicKeywordState value: currentCharacter. 

 

but that is also wrong from a design point of view (anti demeters law). So, you better create a (perhaps private) method who does the assignment. And then you have something like this:

 

self afterDOCTYPEPublicKeywordState: currentCharacter.

 

Esteban





If I move the method call outside outside the ifTrue block to the ifFalse block it doesn’t complain.

Is the problem because of nested blocks ? If that’s the case then what would be a good work around ?




 

Thanks

Mohammad

 

Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

Ben Coman
In reply to this post by Mohammad Al Houssami (Alumni)
Hi Mohammad,

It seems you are trying to learn Smalltalk by leaping straight into
experimenting with your own code, and seems you have missed a few
fundamentals that may end up being very frustrating for you.  Sometimes
when things "seem to work" this only reinforces your misconceptions.

I think you would benefit a lot from stepping back a moment and working
through the excellent (and free) Pharo By Example book [1] -
particularly Chapter 4 "Understanding message syntax" - but don't skip
the rest of it or you will miss a lot of useful stuff.  You will get
best results if you use the image revision [2] matching the one the book
was written for.

[1] http://gforge.inria.fr/frs/download.php/25599/PBE1-2009-10-28.pdf
[2] http://gforge.inria.fr/frs/download.php/31048/PBE-OneClick-1.1.app.zip

regards -ben

Mohammad Al Houssami (Alumni) wrote:

> Probably because I am not using dots except at the end of blocks which I think is wrong.
> This is a sample of what I had earlier:
> currentCharacter = CHARACTERTABULATION  ifTrue: [anythingElseBoolean:= false
>                 AfterDOCTYPENameState value: currentCharacter ].
> There should be a dot after false right ? Once I add the dot I get a complain.
>
>
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Esteban Lorenzano
> Sent: Saturday, March 23, 2013 3:09 PM
> To: A friendly place where any question about pharo is welcome
> Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks
>
> if it is a method, it needs the receiver, in this case "self" (remember, any call in smalltalk is: receiver+message).
> If for some weird reason you did not need it before (like some chained call effect), that was just by chance... you just were lucky before :)
>
> Esteban
>
> On Mar 23, 2013, at 1:58 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]<mailto:[hidden email]>> wrote:
>
>
> So the method declaration should be self afterDOCTYPEPublicKeywordState: currentCharacter. ?
>
> But I have been doing the same for quite some time and I wasn't getting any complains. This is the first time and the only thing that changed is that I have two blocks in this case. As I said earlier if I move the method call outside the block it works with no complains :)
>
> I'll change the names of all my methods to camel case. Thanks for that
>
>
> From: [hidden email]<mailto:[hidden email]> [mailto:[hidden email]<mailto:[hidden email]>] On Behalf Of Esteban Lorenzano
> Sent: Saturday, March 23, 2013 2:52 PM
> To: A friendly place where any question about pharo is welcome
> Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks
>
>
> On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]<mailto:[hidden email]>> wrote:
>
>
>
> Hello everyone
>
> I was trying to save my method which has the below piece of code
>
> anythingElseBoolean = false ifFalse: [
>                 doctypeString := reader next: 6
>                 doctypeString asLowercase =  'public'     ifTrue: [
>                                 AfterDOCTYPEPublicKeywordState value: currentCharacter
>                                 ]
>
> I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name.
>
> AfterDOCTYPEPublicKeywordState is a METHOD????
> then, you are missing some points:
>
> 1) it does not conforms conventions (it should start with lowercase)
> 2) you need a self call
>
> so, it would be like this:
>
> self afterDOCTYPEPublicKeywordState value: currentCharacter.
>
> but that is also wrong from a design point of view (anti demeters law). So, you better create a (perhaps private) method who does the assignment. And then you have something like this:
>
> self afterDOCTYPEPublicKeywordState: currentCharacter.
>
> Esteban
>
>
>
> If I move the method call outside outside the ifTrue block to the ifFalse block it doesn't complain.
>
> Is the problem because of nested blocks ? If that's the case then what would be a good work around ?
>
>
>
>
> Thanks
> Mohammad
>
>
>  


Reply | Threaded
Open this post in threaded view
|

Re: Method Calling Inside Nested Blocks

stephane ducasse
In reply to this post by Mohammad Al Houssami (Alumni)
<base href="x-msg://5763/">you should really read the syntax chapter of the Pharo by example because it explains all these points really precisely.
I'm sure that you will get a ahhhhha effect once you read it.

Stef

On Mar 23, 2013, at 2:14 PM, Mohammad Al Houssami (Alumni) <[hidden email]> wrote:

Probably because I am not using dots except at the end of blocks which I think is wrong. 
This is a sample of what I had earlier:
currentCharacter = CHARACTERTABULATION  ifTrue: [anythingElseBoolean:= false
                AfterDOCTYPENameState value: currentCharacter ].
There should be a dot after false right ? Once I add the dot I get a complain.

 
From: [hidden email] [mailto:pharo-[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 3:09 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks
 
if it is a method, it needs the receiver, in this case "self" (remember, any call in smalltalk is: receiver+message).
If for some weird reason you did not need it before (like some chained call effect), that was just by chance... you just were lucky before :)
 
Esteban
 
On Mar 23, 2013, at 1:58 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:


So the method declaration should be self afterDOCTYPEPublicKeywordState: currentCharacter. ?
 
But I have been doing the same for quite some time and I wasn’t getting any complains. This is the first time and the only thing that changed is that I have two blocks in this case. As I said earlier if I move the method call outside the block it works with no complains J
 
I'll change the names of all my methods to camel case. Thanks for that
 
 
From: [hidden email] [mailto:pharo-[hidden email]] On Behalf Of Esteban Lorenzano
Sent: Saturday, March 23, 2013 2:52 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Method Calling Inside Nested Blocks
 
 
On Mar 23, 2013, at 12:31 PM, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:



Hello everyone
 
I was trying to save my method which has the below piece of code
 
anythingElseBoolean = false ifFalse: [
                doctypeString := reader next: 6
                doctypeString asLowercase =  'public'     ifTrue: [
                                AfterDOCTYPEPublicKeywordState value: currentCharacter
                                ]
 
I get a complain that the AfterDOCTYPEPublicKeywordState is unknown even though I have a method with this name. 
 
AfterDOCTYPEPublicKeywordState is a METHOD????
then, you are missing some points:
 
1) it does not conforms conventions (it should start with lowercase)
2) you need a self call
 
so, it would be like this:
 
self afterDOCTYPEPublicKeywordState value: currentCharacter. 
 
but that is also wrong from a design point of view (anti demeters law). So, you better create a (perhaps private) method who does the assignment. And then you have something like this:
 
self afterDOCTYPEPublicKeywordState: currentCharacter.
 
Esteban



If I move the method call outside outside the ifTrue block to the ifFalse block it doesn’t complain.

Is the problem because of nested blocks ? If that’s the case then what would be a good work around ?



 
Thanks
Mohammad