• Re: A TclOO question (for =?UTF-8?B?ZXhwZXJ0cz8p?=

    From r.zaumseil@r.zaumseil@freenet.de (rene) to comp.lang.tcl on Tue Apr 8 06:01:42 2025
    From Newsgroup: comp.lang.tcl

    Hello Helmut

    AFAIK the varaible statement in the class context will fill a list.
    This list is used to "upvar" your variables in the context of newly
    created methods.
    But beware. When you create new method in the object context with
    oo::objdefine the list is not used. This means you have to manually call
    the variable command.

    HTH
    rene

    --
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Helmut Giese@hgiese@ratiosoft.com to comp.lang.tcl on Wed Apr 9 15:59:35 2025
    From Newsgroup: comp.lang.tcl

    Hello Rene,
    thanks for your answer , it was really helpful
    Helmut
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From aotto1968@aotto1968@t-online.de to comp.lang.tcl on Fri Apr 11 19:08:27 2025
    From Newsgroup: comp.lang.tcl

    On 07.04.25 18:34, Helmut Giese wrote:
    Hello out there,
    look at the following sample:
    ---
    catch {Sample destroy}

    oo::class create Sample {
    variable classVar ;# automatically exists in every instance
    constructor {someVar} {
    my variable objVar
    set classVar $someVar
    set objVar 99
    }
    destructor {
    my variable objVar classVar
    puts "classVar: $classVar, objVar: $objVar"
    }
    }

    Sample create s1 100
    Sample create s2 200
    s1 destroy ;# -> classVar: 100, objVar: 99
    s2 destroy ;# -> classVar: 200, objVar: 99
    ---
    My question is: What happens, if I add 'classVar', although not
    needed, to a 'my variable' statement - like I did in the destructor
    above. Is it just superfluous or can it have consequences in a more
    complex situation than the above example.
    Thank you for any enlightenment
    Helmut

    a very good source for all kind of programming questions is the KI
    for example the GROK from X(twitter)

    https://x.com/i/grok

    it is really impressive, here is your answer:

    https://x.com/i/grok/share/Wo4XKUycnscf3WNTbpMoms93f

    mfg
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Helmut Giese@hgiese@ratiosoft.com to comp.lang.tcl on Fri Apr 11 21:35:07 2025
    From Newsgroup: comp.lang.tcl

    Hi aotto.
    that's really cool: a complete, detailed analysis which even I
    understood. Many thanks for this link
    Helmut
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Mon Apr 14 11:08:05 2025
    From Newsgroup: comp.lang.tcl

    * Helmut Giese <hgiese@ratiosoft.com>
    | | → https://x.com/i/grok/share/Wo4XKUycnscf3WNTbpMoms93f
    | that's really cool: a complete, detailed analysis which even I
    | understood. Many thanks for this link

    The text created by the AI contains a subtle error: it makes a
    difference between "variable foo" at class level and "my variable foo"
    at method level as the former being a "class-wide" variable (shared
    across instances, 'static' in C++, 'common' in itcl) and the latter "instance-specific" ones (specific to one object):

    [Complex situations, p2]
    ...
    ["my variable classVar" in method without previous "variable classVar" at class level]
    ...
    In this case, classVar becomes an instance-specific variable, not a
    class-wide one, which could lead to unexpected behavior if the
    intent was to share classVar across instances.

    As far as I understand it, this is not the case. Also the code you
    posted cleary shows that classVar is *not* shared between instances
    (each object has it's own value).

    Maybe someone with more knowlegde on this can share some insight?

    R'
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From aldo.w.buratti@aldo.w.buratti@gmail.com (abu) to comp.lang.tcl on Mon Apr 14 16:05:04 2025
    From Newsgroup: comp.lang.tcl

    Grok was very clever explaining the current code, but it was wrong
    trying to depict a more complex case.

    "classVar" is not a class-variable (despite its name).
    Simply Tcloo has not (yet) a concept of class-variables. All the
    variables are instance-variables,
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Ashok@apnmbx-public@yahoo.com to comp.lang.tcl on Mon Apr 14 21:51:55 2025
    From Newsgroup: comp.lang.tcl

    Not seen Grok's example but Tcl 9 does have class variables. See https://www.tcl-lang.org/man/tcl9.0/TclCmd/classvariable.html.


    On 4/14/2025 9:35 PM, abu wrote:
    Grok was very clever explaining the current code, but it was wrong
    trying to depict a more complex case.

    "classVar" is not a class-variable (despite its name).
    Simply Tcloo has not (yet) a concept of class-variables. All the
    variables are instance-variables,

    --- Synchronet 3.20c-Linux NewsLink 1.2