• A TclOO question

    From Helmut Giese@21:1/5 to All on Tue Jul 16 15:26:20 2024
    Hello out there ,
    I found XOTclLight (https://github.com/xdobry/xotcl-light ) which is
    an XOTcl compatible implementation via TclOO. My hope was that with it
    XOTcl's mysterious error messages would be traceable since the calls
    wouldn't be buried in XOTcl's binary.
    Alas, it errored out with
    may not change classes into an instance of themselves
    on the line
    oo::objdefine Class class Class

    While this intuitively makes sense I wonder:
    1) Maybe TclOO's syntax has changed since then (2015)? After all, a
    man who knows enough about OO systems to implement one in terms of the
    other isn't likely to release a package which is evidently unusable.
    2) What does the statement cited above try to achieve? And, most
    important, what magic can achieve it?

    I figured that it attempted to replace the XOTcl command 'Class' with
    its own definition so I changed in the script and the call above
    'Class' to 'NewClass' - but to no avail.

    Any idea or help will be greatly appreciated
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Mon Apr 7 15:03:04 2025
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Wed Apr 9 15:37:13 2025
    Sorry for this double post.When I looked it didn't show up so I posted
    again.
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Sat May 17 22:57:56 2025
    Hello out there,
    say I have a class and 2 instances like so

    oo::class create MyClass {
    constructor {someVal} {
    my variable myVar
    set myVar $someVal
    }
    method get {} {
    my variable myVar
    return $myVar
    }
    method set {val} {
    my variable myVar
    set myVar $val
    }
    }

    MyClass create obj1 33
    MyClass create obj2 99

    How can I set a trace on 'myVar' of 'obj2'?
    I found an example on the doc of the 'my' command but it sets a trace
    on a global variable during which an object is invoked - which doesn't
    fit my situation
    Any help will be greatly appreciated
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Helmut Giese on Sun May 18 01:31:06 2025
    Helmut Giese <[email protected]> wrote:
    Hello out there,
    say I have a class and 2 instances like so

    oo::class create MyClass {
    constructor {someVal} {
    my variable myVar
    set myVar $someVal
    }
    method get {} {
    my variable myVar
    return $myVar
    }
    method set {val} {
    my variable myVar
    set myVar $val
    }
    }

    MyClass create obj1 33
    MyClass create obj2 99

    How can I set a trace on 'myVar' of 'obj2'?
    I found an example on the doc of the 'my' command but it sets a trace
    on a global variable during which an object is invoked - which doesn't
    fit my situation
    Any help will be greatly appreciated
    Helmut

    From outside the object, one way is, after you create the objects:

    Get the object's namespace:

    % info object namespace obj2
    ::oo::Obj13

    Then infer the location of the variable:

    % set ::oo::Obj13::myVar
    99

    Setting a trace on ::oo::Obj13::myVar should be trivial now.

    From inside one of the object's methods, the 'my varname' gives you the
    full namespace name:

    oo::class create MyClass {
    constructor {someVal} {
    my variable myVar
    set myVar $someVal
    }
    method where {} {
    puts "myVar is at [my varname myVar]"
    }
    }
    ::MyClass
    % MyClass create obj1 33
    ::obj1
    % obj1 where
    myVar is at ::oo::Obj12::myVar
    %

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Sun May 18 19:03:23 2025
    Hello Rich,
    many thanks for this simple explanation. I knew how to access procs in
    a namespace but hadn't quite realized that the same holds for
    variables - which looks obvious now :(
    Best regards
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)