Setters for instance variables

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

Setters for instance variables

Mohammad Al Houssami (Alumni)

Hello again,


If I have an instance variable A in ClassA and I want to use it in ClassB.

If I do the following  in ClassB

objectA := ClassA new.

 

objectA  A: "new value for A".


Why doesn’t this work? Isnt this calling the setter of A on the objectA ?  Pharo doesn’t understand it for some reason .

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Luc Fabresse
Hi,

2013/4/24 Mohammad Al Houssami (Alumni) <[hidden email]>

Hello again,


If I have an instance variable A in ClassA and I want to use it in ClassB.

If I do the following  in ClassB

objectA := ClassA new.

 

objectA  A: "new value for A".


Why doesn’t this work? Isnt this calling the setter of A on the objectA ?  Pharo doesn’t understand it for some reason .


yes.
but a setter is regular method.
did you defined the method in ClassA.
also, by convention method names start with a lowercase.
Example:

Object subclass: #ClassA
  iv: 'a'

ClassA>>a: newValue
   a := newValue

objA := ClassA new.
objA a: 1

Cheers,

Luc 

 

 


Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Mohammad Al Houssami (Alumni)

Yes I do have them but without the ">>" signs
This is what I have inside the CharacterToken Class

characterData: anObject

                characterData := anObject

 

This is where pharo complains

characterToken :=  CharacterToken new.

characterToken characterData: AMPERSAND.


It says it doesn’t understand characterData though it is defined in the CharacterToken class

The setters and getters were generated by pharo. So im not sure about what the >> is for




 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Luc Fabresse
Sent: Wednesday, April 24, 2013 8:10 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Setters for instance variables

 

Hi,

 

2013/4/24 Mohammad Al Houssami (Alumni) <[hidden email]>

Hello again,


If I have an instance variable A in ClassA and I want to use it in ClassB.

If I do the following  in ClassB

objectA := ClassA new.

 

objectA  A: "new value for A".

Why doesn’t this work? Isnt this calling the setter of A on the objectA ?  Pharo doesn’t understand it for some reason .

 

yes.

but a setter is regular method.

did you defined the method in ClassA.

also, by convention method names start with a lowercase.

Example:

 

Object subclass: #ClassA

  iv: 'a'

 

ClassA>>a: newValue

   a := newValue

 

objA := ClassA new.

objA a: 1

 

Cheers,

 

Luc 

 

 

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Igor Stasenko
Class>>method
.....

simply a way to show code snippet for a method and to which class it
should belong to.
Note that this notation is not syntactically correct in smalltalk.


On 24 April 2013 21:24, Mohammad Al Houssami (Alumni)
<[hidden email]> wrote:

> Yes I do have them but without the ">>" signs
> This is what I have inside the CharacterToken Class
>
> characterData: anObject
>
>                 characterData := anObject
>
>
>
> This is where pharo complains
>
> characterToken :=  CharacterToken new.
>
> characterToken characterData: AMPERSAND.
>
>
> It says it doesn’t understand characterData though it is defined in the
> CharacterToken class
>
> The setters and getters were generated by pharo. So im not sure about what
> the >> is for
>
>
>
>
>
>
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Luc Fabresse
> Sent: Wednesday, April 24, 2013 8:10 PM
> To: A friendly place where any question about pharo is welcome
> Subject: Re: [Pharo-users] Setters for instance variables
>
>
>
> Hi,
>
>
>
> 2013/4/24 Mohammad Al Houssami (Alumni) <[hidden email]>
>
> Hello again,
>
>
> If I have an instance variable A in ClassA and I want to use it in ClassB.
>
> If I do the following  in ClassB
>
> objectA := ClassA new.
>
>
>
> objectA  A: "new value for A".
>
> Why doesn’t this work? Isnt this calling the setter of A on the objectA ?
> Pharo doesn’t understand it for some reason .
>
>
>
> yes.
>
> but a setter is regular method.
>
> did you defined the method in ClassA.
>
> also, by convention method names start with a lowercase.
>
> Example:
>
>
>
> Object subclass: #ClassA
>
>   iv: 'a'
>
>
>
> ClassA>>a: newValue
>
>    a := newValue
>
>
>
> objA := ClassA new.
>
> objA a: 1
>
>
>
> Cheers,
>
>
>
> Luc
>
>
>
>
>
>
>
>



--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Mohammad Al Houssami (Alumni)
Ok okay... im new here so I didn’t know that.
So why is pharo complaining then ?


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Igor Stasenko
Sent: Wednesday, April 24, 2013 8:40 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Setters for instance variables

Class>>method
.....

simply a way to show code snippet for a method and to which class it should belong to.
Note that this notation is not syntactically correct in smalltalk.


On 24 April 2013 21:24, Mohammad Al Houssami (Alumni) <[hidden email]> wrote:

> Yes I do have them but without the ">>" signs This is what I have
> inside the CharacterToken Class
>
> characterData: anObject
>
>                 characterData := anObject
>
>
>
> This is where pharo complains
>
> characterToken :=  CharacterToken new.
>
> characterToken characterData: AMPERSAND.
>
>
> It says it doesn’t understand characterData though it is defined in
> the CharacterToken class
>
> The setters and getters were generated by pharo. So im not sure about
> what the >> is for
>
>
>
>
>
>
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Luc
> Fabresse
> Sent: Wednesday, April 24, 2013 8:10 PM
> To: A friendly place where any question about pharo is welcome
> Subject: Re: [Pharo-users] Setters for instance variables
>
>
>
> Hi,
>
>
>
> 2013/4/24 Mohammad Al Houssami (Alumni) <[hidden email]>
>
> Hello again,
>
>
> If I have an instance variable A in ClassA and I want to use it in ClassB.
>
> If I do the following  in ClassB
>
> objectA := ClassA new.
>
>
>
> objectA  A: "new value for A".
>
> Why doesn’t this work? Isnt this calling the setter of A on the objectA ?
> Pharo doesn’t understand it for some reason .
>
>
>
> yes.
>
> but a setter is regular method.
>
> did you defined the method in ClassA.
>
> also, by convention method names start with a lowercase.
>
> Example:
>
>
>
> Object subclass: #ClassA
>
>   iv: 'a'
>
>
>
> ClassA>>a: newValue
>
>    a := newValue
>
>
>
> objA := ClassA new.
>
> objA a: 1
>
>
>
> Cheers,
>
>
>
> Luc
>
>
>
>
>
>
>
>



--
Best regards,
Igor Stasenko.


Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Luc Fabresse
In reply to this post by Mohammad Al Houssami (Alumni)

2013/4/24 Mohammad Al Houssami (Alumni) <[hidden email]>

Yes I do have them but without the ">>" signs


yes you should not see >> in the source code.
>> is used by convention in books to express that a method belongs to a class.
Example, if I write:

aMethod
  ^1

you do not know which methods is it.
But using:

MyClass>>aMethod
  ^1

you know that is the one of MyClass
 

This is what I have inside the CharacterToken Class

characterData: anObject

                characterData := anObject

 

This is where pharo complains

characterToken :=  CharacterToken new.

characterToken characterData: AMPERSAND.


It says it doesn’t understand characterData though it is defined in the CharacterToken class


ok I did not get where is your problem.
can you send a small piece of your code?

Luc
 

The setters and getters were generated by pharo. So im not sure about what the >> is for




 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Luc Fabresse
Sent: Wednesday, April 24, 2013 8:10 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Setters for instance variables

 

Hi,

 

2013/4/24 Mohammad Al Houssami (Alumni) <[hidden email]>

Hello again,


If I have an instance variable A in ClassA and I want to use it in ClassB.

If I do the following  in ClassB

objectA := ClassA new.

 

objectA  A: "new value for A".

Why doesn’t this work? Isnt this calling the setter of A on the objectA ?  Pharo doesn’t understand it for some reason .

 

yes.

but a setter is regular method.

did you defined the method in ClassA.

also, by convention method names start with a lowercase.

Example:

 

Object subclass: #ClassA

  iv: 'a'

 

ClassA>>a: newValue

   a := newValue

 

objA := ClassA new.

objA a: 1

 

Cheers,

 

Luc 

 

 

 

 


Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Camillo Bruni-3
In reply to this post by Mohammad Al Houssami (Alumni)
On 2013-04-24, at 21:46, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:
> Ok okay... im new here so I didn’t know that.
> So why is pharo complaining then ?

I'd guess you installed the method on class side, and not instance side :)


Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Mohammad Al Houssami (Alumni)
Actually CamilLo you are right I do.
I actually have everything on the class side and not on the instance side. What is the difference? And shall I assume it works if I move them to the instance side ?

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Camillo Bruni
Sent: Wednesday, April 24, 2013 9:14 PM
To: A friendly place where any question about pharo is welcome
Subject: Re: [Pharo-users] Setters for instance variables

On 2013-04-24, at 21:46, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:
> Ok okay... im new here so I didn't know that.
> So why is pharo complaining then ?

I'd guess you installed the method on class side, and not instance side :)





Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Sean P. DeNigris
Administrator
Mohammad Al Houssami (Alumni) wrote
What is the difference?
To learn the basics, read one of the excellent free Smalltalk books, like Pharo By Example [1], in which you will find the answer to your question on page 82.

[1] http://pharobyexample.org/
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

stephane ducasse
In reply to this post by Mohammad Al Houssami (Alumni)
You should read the pharo by example book :)

Stef

On Apr 24, 2013, at 11:15 PM, Mohammad Al Houssami (Alumni) <[hidden email]> wrote:

> Actually CamilLo you are right I do.
> I actually have everything on the class side and not on the instance side. What is the difference? And shall I assume it works if I move them to the instance side ?
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Camillo Bruni
> Sent: Wednesday, April 24, 2013 9:14 PM
> To: A friendly place where any question about pharo is welcome
> Subject: Re: [Pharo-users] Setters for instance variables
>
> On 2013-04-24, at 21:46, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:
>> Ok okay... im new here so I didn't know that.
>> So why is pharo complaining then ?
>
> I'd guess you installed the method on class side, and not instance side :)
>
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Esteban A. Maringolo
I like to see a RTFM from time to time in a Smalltalk mailing list :)

Regards!
Esteban A. Maringolo


2013/4/25 stephane ducasse <[hidden email]>:

> You should read the pharo by example book :)
>
> Stef
>
> On Apr 24, 2013, at 11:15 PM, Mohammad Al Houssami (Alumni) <[hidden email]> wrote:
>
>> Actually CamilLo you are right I do.
>> I actually have everything on the class side and not on the instance side. What is the difference? And shall I assume it works if I move them to the instance side ?
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Camillo Bruni
>> Sent: Wednesday, April 24, 2013 9:14 PM
>> To: A friendly place where any question about pharo is welcome
>> Subject: Re: [Pharo-users] Setters for instance variables
>>
>> On 2013-04-24, at 21:46, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:
>>> Ok okay... im new here so I didn't know that.
>>> So why is pharo complaining then ?
>>
>> I'd guess you installed the method on class side, and not instance side :)
>>
>>
>>
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

stephane ducasse

On Apr 25, 2013, at 7:20 PM, "Esteban A. Maringolo" <[hidden email]> wrote:

> I like to see a RTFM from time to time in a Smalltalk mailing list :)

:)

me too. because it means that we made progress about the Manual existence :)
I'm cleaning right the github repo of PBE and others.

Stef

>
> Regards!
> Esteban A. Maringolo
>
>
> 2013/4/25 stephane ducasse <[hidden email]>:
>> You should read the pharo by example book :)
>>
>> Stef
>>
>> On Apr 24, 2013, at 11:15 PM, Mohammad Al Houssami (Alumni) <[hidden email]> wrote:
>>
>>> Actually CamilLo you are right I do.
>>> I actually have everything on the class side and not on the instance side. What is the difference? And shall I assume it works if I move them to the instance side ?
>>>
>>> -----Original Message-----
>>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Camillo Bruni
>>> Sent: Wednesday, April 24, 2013 9:14 PM
>>> To: A friendly place where any question about pharo is welcome
>>> Subject: Re: [Pharo-users] Setters for instance variables
>>>
>>> On 2013-04-24, at 21:46, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:
>>>> Ok okay... im new here so I didn't know that.
>>>> So why is pharo complaining then ?
>>>
>>> I'd guess you installed the method on class side, and not instance side :)
>>>
>>>
>>>
>>>
>>>
>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Ben Coman
In reply to this post by Esteban A. Maringolo
Also this.... http://www.catb.org/esr/faqs/smart-questions.html

Esteban A. Maringolo wrote:

> I like to see a RTFM from time to time in a Smalltalk mailing list :)
>
> Regards!
> Esteban A. Maringolo
>
>
> 2013/4/25 stephane ducasse <[hidden email]>:
>  
>> You should read the pharo by example book :)
>>
>> Stef
>>
>> On Apr 24, 2013, at 11:15 PM, Mohammad Al Houssami (Alumni) <[hidden email]> wrote:
>>
>>    
>>> Actually CamilLo you are right I do.
>>> I actually have everything on the class side and not on the instance side. What is the difference? And shall I assume it works if I move them to the instance side ?
>>>
>>> -----Original Message-----
>>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Camillo Bruni
>>> Sent: Wednesday, April 24, 2013 9:14 PM
>>> To: A friendly place where any question about pharo is welcome
>>> Subject: Re: [Pharo-users] Setters for instance variables
>>>
>>> On 2013-04-24, at 21:46, "Mohammad Al Houssami (Alumni)" <[hidden email]> wrote:
>>>      
>>>> Ok okay... im new here so I didn't know that.
>>>> So why is pharo complaining then ?
>>>>        
>>> I'd guess you installed the method on class side, and not instance side :)
>>>
>>>
>>>
>>>
>>>
>>>      
>>    
>
>
>  


Reply | Threaded
Open this post in threaded view
|

Re: Setters for instance variables

Esteban A. Maringolo
I must admit that the instance/class "side" is a common error that has
bitten many programmers.
It still bites me from time to time.

Regards,

Esteban A. Maringolo