Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

He jests at scars who never felt a wound. -- Shakespeare, "Romeo and Juliet, II. 2"


comp / comp.lang.tcl / Re: How do I correctly access this variable?

SubjectAuthor
* How do I correctly access this variable?Luc
`* Re: How do I correctly access this variable?Colin Macleod
 `* Re: How do I correctly access this variable?Ralf Fassel
  `- Re: How do I correctly access this variable?et99

1
Subject: How do I correctly access this variable?
From: Luc
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 4 Oct 2024 06:36 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: How do I correctly access this variable?
Date: Fri, 4 Oct 2024 03:36:48 -0300
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <20241004033648.47f809d1@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 04 Oct 2024 08:36:48 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="15f649942e682c8a504c1d56922877be";
logging-data="152835"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19segtcL6lgkFQ9PjDCkHYwf49W9Vi7TLY="
Cancel-Lock: sha1:HwOE0E+3kxtDR5Kza8qhtxMj0Ho=
View all headers

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
>>

Subject: Re: How do I correctly access this variable?
From: Colin Macleod
Newsgroups: comp.lang.tcl
Date: Fri, 4 Oct 2024 08:15 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!cmacleod.me.uk!.POSTED!not-for-mail
From: user7@cmacleod.me.uk.invalid (Colin Macleod)
Newsgroups: comp.lang.tcl
Subject: Re: How do I correctly access this variable?
References: <20241004033648.47f809d1@lud1.home>
Date: Fri, 04 Oct 24 08:15:02 GMT
Message-ID: <1728029702-7@cmacleod.me.uk>
Injection-Info: cmacleod.me.uk; mail-complaints-to="newsgrouper@yahoo.com"; posting-account=user7
Injection-Date: Fri, 04 Oct 24 08:15:02 GMT
User-Agent: Newsgrouper/0.5
View all headers

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.

Subject: Re: How do I correctly access this variable?
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Fri, 4 Oct 2024 09:01 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: How do I correctly access this variable?
Date: Fri, 04 Oct 2024 11:01:35 +0200
Lines: 23
Message-ID: <ygay134fdhs.fsf@akutech.de>
References: <20241004033648.47f809d1@lud1.home> <1728029702-7@cmacleod.me.uk>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net j2VYi3ohqxSVvqbEAwb4bAEWiw545qYh1qQjWme6PUEHSGCLs=
Cancel-Lock: sha1:pH97OvtDT9Xy9CxvfQ52sr8F1/s= sha1:/3msCK7/Hy78rK5PEaq95KdkYGg= sha256:wzICBS4pr1BzLIhCPEhTL/7eObhX4U3EwtHXSVyUHl0=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* 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'

Subject: Re: How do I correctly access this variable?
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 4 Oct 2024 19:17 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: How do I correctly access this variable?
Date: Fri, 4 Oct 2024 12:17:33 -0700
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <vdpf0d$b0pd$1@dont-email.me>
References: <20241004033648.47f809d1@lud1.home> <1728029702-7@cmacleod.me.uk>
<ygay134fdhs.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 04 Oct 2024 21:17:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="28c088774217a6f327d659d454a08502";
logging-data="361261"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YNiJIwDaXUpYsDnDcA03k"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tYhU7cEFqjlyyzR1r6Rmmi9CAeg=
Content-Language: en-US
In-Reply-To: <ygay134fdhs.fsf@akutech.de>
View all headers

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 :)

1

rocksolid light 0.9.8
clearnet tor