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, 02:44:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6crt4$1nrm$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1
On 7/6/2024 1:54 AM, Mark Summerfield wrote:
On Fri, 5 Jul 2024 22:26:16 +0200, Schelte wrote:
 [snip]
So, in the constructor of your example I would use "variable", while I'd
use "my variable" in the methods:
>
oo::class create P {
      constructor {{x 0} {y 0}} {
          variable x_ $x y_ $y
      }
>
      method x {} {
          my variable x_
          return $x_
      }
}
 What I still don't understand is that in method x, _both_ "my variable"
_and_ plain "variable" seem to work.
 In fact the only time I've needed "my" so far is in a method call. (But
I'll read the web page that was recommended and am still working my way
through reading Tip 257.)
  
I don't understand this either. It appears that the my command, which comes from oo::object treats its first argument as a method, and variable like new and create are some inherited methods. The my command seems to in effect replace "my" with the obj you are currently running. The description in oo::object then treats that obj as the "obj" in its documentation.
The effect seems to be that the same sort of thing occurs, a linking of the variables from a namespace into the current context. And I've read that in several places. Syntactically, however, one takes a list of variables, while the other I don't know. The key paragraph on the wiki is:
"They differ importantly in how multiple arguments are treated, so be careful."
Unfortunately, the list of hyperlinks ends there, so I don't know how they differ. At first I guessed it meant that using variable alone, one could also set values, as in the normal variable command inside a namespace. But when I tried that, it made the 2nd argument a variable also.
I'm afraid this overloading of the variable command has me stumped.

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