Re: oo::class - my variable vs variable

Liste des GroupesRevenir à cl tcl 
Sujet : Re: oo::class - my variable vs variable
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tcl
Date : 07. Jul 2024, 23:28:06
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6f4po$h1mu$1@dont-email.me>
References : 1 2
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1
On 7/7/2024 6:21 AM, greg wrote:
Am 04.07.24 um 09:17 schrieb Mark Summerfield:
I am trying to learn TclOO. I have created two classes P and Q which
appear to have identical behavior. Class P uses "my variable" and Q uses
"variable". Can someone explain the difference between them. (I am
familiar with Python and Go if that's any help with explaining.)
>
 Hello Mark,
I have replaced your demo, hope that's OK.
Different when there are multiple variables as arguments. Originally I expected the opposite behavior. I had misunderstood that until now.
    #DemoClass1 and DemoClass2
# difference constructor with  variable individually or together
# difference output for instanceVar2, no initialization with 15 (DemoClass1)
#DemoClass3 and DemoClass4
# no difference with my variable individually or together
# in example:
# objx1 with my variable, x for DemoClass
# objx2 with variable, x for DemoClass
 oo::class create DemoClass1 {
     constructor {val1 val2} {
         variable instanceVar1 instanceVar2
         set instanceVar1 $val1
         set instanceVar2 $val2
     }
<snip>
Greg:
Just to (hopefully) clarify with my own findings (Forgive me if this is what you were trying to say in your posting) :
I've stepped this through, and what is happening is that the command in the constructor:
variable instanceVar1 instanceVar2
does indeed do what I thought it was supposed to do (but I must have messed up earlier) and both creates instanceVar1 and initializes it to the string "instanceVar2".
I had wondered why it wouldn't get an error on the increment of a non-integer, until I also saw that it is immediately overwritten by the value of $val1, which is an integer.
instanceVar2 in this constructor is thus merely a local variable that is set to $val2 and then disappears when the constructor returns.
et

Date Sujet#  Auteur
4 Jul 24 * oo::class - my variable vs variable7Mark Summerfield
5 Jul 24 +- Re: oo::class - my variable vs variable1Petro Kazmirchuk
5 Jul 24 +- Re: oo::class - my variable vs variable1greg
6 Jul 24 +* Re: oo::class - my variable vs variable2Mark Summerfield
7 Jul 24 i`- Re: oo::class - my variable vs variable1et99
7 Jul 24 `* Re: oo::class - my variable vs variable2greg
7 Jul 24  `- Re: oo::class - my variable vs variable1et99

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal