• Question: is "test2" a "varname" or a "command/object"

    From aotto1968@21:1/5 to All on Sat Jun 8 22:57:12 2024
    # Hi tricky tcl OO stuff
    #
    # → the "OtherC create test2" create the "test2" instance in the namespace of the calling instance (test1).
    # → the advantage is, if the calling-instance is delete the test2-instance is delete too because the
    # calling-instance namespace is deleted.
    #
    # and now the question:
    #
    # is the "test2" now a "variable" or a "command" ? → the reason I ask is because the "my varname test2"
    # return the string with absolute ns-path of the "test2-command" bus BUT it is a command and *not*
    # a variable. the test with "info exists $varname" say 0, not a variable.
    #
    # → I check the result from "my varname test2" later with "$varname test"

    oo::class create OtherC {
    constructor {} {
    puts "create OtherC→[self]"
    }

    destructor {
    puts "delete OtherC→[self]"
    }

    method test {} {
    puts "I'm [self]"
    }

    }

    oo::class create OttoC {
    constructor {} {
    puts "create OttoC→[self]"
    OtherC create test2
    }

    destructor {
    puts "delete OttoC→[self]"
    }

    method get {} {
    my varname test2
    }

    }

    OttoC create test1

    set varname [test1 get]

    $varname test

    puts "varname = $varname"
    puts "varname exists = [info exists $varname]"

    test1 destroy


    result…

    create OttoC→::test1
    create OtherC→::oo::Obj13::test2
    I'm ::oo::Obj13::test2
    varname = ::oo::Obj13::test2
    varname exists = 0
    delete OttoC→::test1
    delete OtherC→::oo::Obj13::test2

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to [email protected] on Sat Jun 8 22:56:50 2024
    I don't know how Tcl's oo package works (I use the SNIT framework, which works differently), but I'm guessing you are seeing some sort of scope "magic".

    At Sat, 8 Jun 2024 22:57:12 +0200 aotto1968 <[email protected]> wrote:



    # Hi tricky tcl OO stuff
    #
    # the "OtherC create test2" create the "test2" instance in the namespace of the calling instance (test1).
    # the advantage is, if the calling-instance is delete the test2-instance is delete too because the
    # calling-instance namespace is deleted.
    #
    # and now the question:
    #
    # is the "test2" now a "variable" or a "command" ? the reason I ask is because the "my varname test2"
    # return the string with absolute ns-path of the "test2-command" bus BUT it is a command and *not*
    # a variable. the test with "info exists $varname" say 0, not a variable.
    #
    # I check the result from "my varname test2" later with "$varname test"

    oo::class create OtherC {
    constructor {} {
    puts "create OtherC→[self]"
    }

    destructor {
    puts "delete OtherC→[self]"
    }

    method test {} {
    puts "I'm [self]"
    }

    }

    oo::class create OttoC {
    constructor {} {
    puts "create OttoC→[self]"
    OtherC create test2
    }

    destructor {
    puts "delete OttoC→[self]"
    }

    method get {} {
    my varname test2
    }

    }

    OttoC create test1

    set varname [test1 get]

    $varname test

    puts "varname = $varname"
    puts "varname exists = [info exists $varname]"

    test1 destroy


    result…

    create OttoC→::test1
    create OtherC→::oo::Obj13::test2
    I'm ::oo::Obj13::test2
    varname = ::oo::Obj13::test2
    varname exists = 0
    delete OttoC→::test1
    delete OtherC→::oo::Obj13::test2



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

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