• How do I correctly access this variable?

    From Luc@luc@sep.invalid to comp.lang.tcl on Fri Oct 4 03:36:48 2024
    From Newsgroup: comp.lang.tcl

    I am stumped by this:

    array set CONTROL {
    InitialStartUpDir "$env(HOME)"
    }

    puts $env(HOME)
    /home/luc

    OK.

    Now,

    oo::define NewTab {
    constructor {} {
    blah blah blah...
    $newtab configure -text "$::CONTROL(InitialStartUpDir)"
    }
    }

    The button label becomes "$env(HOME)" instead of /home/luc.

    What am I doing wrong?
    --
    Luc


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Colin Macleod@user7@cmacleod.me.uk.invalid to comp.lang.tcl on Fri Oct 4 08:15:02 2024
    From Newsgroup: comp.lang.tcl

    Luc <luc@sep.invalid> posted:

    I am stumped by this:

    array set CONTROL {
    InitialStartUpDir "$env(HOME)"
    }

    puts $env(HOME)
    /home/luc

    OK.

    Now,

    oo::define NewTab {
    constructor {} {
    blah blah blah...
    $newtab configure -text "$::CONTROL(InitialStartUpDir)"
    }
    }

    The button label becomes "$env(HOME)" instead of /home/luc.

    What am I doing wrong?

    Variable references do not get expanded inside braces {}.
    Try:
    array set CONTROL "
    InitialStartUpDir $env(HOME)
    "
    --
    Colin Macleod.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Fri Oct 4 11:01:35 2024
    From Newsgroup: comp.lang.tcl

    * Colin Macleod <user7@cmacleod.me.uk.invalid>
    | Luc <luc@sep.invalid> posted:

    | > I am stumped by this:
    | >
    | > array set CONTROL {
    | > InitialStartUpDir "$env(HOME)"
    | > }
    --<snip-snip>--
    | > What am I doing wrong?

    | Variable references do not get expanded inside braces {}.
    | Try:
    | array set CONTROL "
    | InitialStartUpDir $env(HOME)
    | "

    Or safer, in case the expanded value contains spaces:

    array set CONTROL [list InitialStartUpDir $env(HOME)]

    HTH
    R'
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From et99@et99@rocketship1.me to comp.lang.tcl on Fri Oct 4 12:17:33 2024
    From Newsgroup: comp.lang.tcl

    On 10/4/2024 2:01 AM, Ralf Fassel wrote:
    * Colin Macleod <user7@cmacleod.me.uk.invalid>
    | Luc <luc@sep.invalid> posted:

    | > I am stumped by this:
    | >
    | > array set CONTROL {
    | > InitialStartUpDir "$env(HOME)"
    | > }
    --<snip-snip>--
    | > What am I doing wrong?

    | Variable references do not get expanded inside braces {}.
    | Try:
    | array set CONTROL "
    | InitialStartUpDir $env(HOME)
    | "

    Or safer, in case the expanded value contains spaces:

    array set CONTROL [list InitialStartUpDir $env(HOME)]

    HTH
    R'

    One wonders why Luc wouldn't just simply use array notation:

    set ::CONTROL(InitialStartUpDir) $env(HOME)

    [array set] with a list is useful when the list has more than one key/value pair, while with just a single pair takes about twice the time (as determined with [time]} to run.


    BTW I have one little nitpick with the docs on this one. It states:

    "Each odd-numbered element in list is treated as an element name within arrayName ..."

    In Tcl, list indices invariably begin at 0, and yet odd-numbered here would indicate beginning at 1, and oddity in itself :)

    --- Synchronet 3.20a-Linux NewsLink 1.114