Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

UNIX enhancements aren't.


devel / comp.lang.tcl / Re: Set a group of blank vars to a reset value.

SubjectAuthor
* Set a group of blank vars to a reset value.snosniv
+* Set a group of blank vars to a reset value.Arjen Markus
|`* Set a group of blank vars to a reset value.snosniv
| `* Set a group of blank vars to a reset value.Arjen Markus
|  `- Set a group of blank vars to a reset value.snosniv
+* Set a group of blank vars to a reset value.Ralf Fassel
|`* Set a group of blank vars to a reset value.snosniv
| `- Set a group of blank vars to a reset value.Rich
`* Set a group of blank vars to a reset value.saitology9
 `* Set a group of blank vars to a reset value.Andreas Leitgeb
  `- Set a group of blank vars to a reset value.saitology9

1
Set a group of blank vars to a reset value.

<9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10659&group=comp.lang.tcl#10659

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:13e3:b0:6fb:a5cc:208a with SMTP id h3-20020a05620a13e300b006fba5cc208amr715850qkl.231.1675420846127;
Fri, 03 Feb 2023 02:40:46 -0800 (PST)
X-Received: by 2002:a05:6902:1881:b0:80f:4da9:df24 with SMTP id
cj1-20020a056902188100b0080f4da9df24mr1328080ybb.64.1675420845868; Fri, 03
Feb 2023 02:40:45 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 3 Feb 2023 02:40:45 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=82.1.128.13; posting-account=gstOigoAAADV9pmzZL58qQ436SKV3SBu
NNTP-Posting-Host: 82.1.128.13
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
Subject: Set a group of blank vars to a reset value.
From: nivpars...@gmail.com (snosniv)
Injection-Date: Fri, 03 Feb 2023 10:40:46 +0000
Content-Type: text/plain; charset="UTF-8"
 by: snosniv - Fri, 3 Feb 2023 10:40 UTC

I have some time entry data as mins0, secs0, mins1, secs1 etc etc, my script detects if both are unset and raises a warning, but if say mins is set but secs is blank, I set the secs to 0 (and vice-versa):

if {($mins0 == "")} { set mins0 0}
but rather than doing all the mins individually, I'd prefer a loop, but
something like;
for {set i 0} {$i < $max} {incr i} {
{if $mins$i == ""} {set $mins$i 0}
} obviously won't work.
How do I do get a loop method to work please? (history means I can't really convert to an array easily).

Re: Set a group of blank vars to a reset value.

<bf9c9ef1-b49e-49b8-bec4-a78b32c9c213n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10660&group=comp.lang.tcl#10660

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:622a:387:b0:3b8:6c16:ea5c with SMTP id j7-20020a05622a038700b003b86c16ea5cmr1015063qtx.57.1675422633840;
Fri, 03 Feb 2023 03:10:33 -0800 (PST)
X-Received: by 2002:a81:ac4d:0:b0:507:739d:e0ca with SMTP id
z13-20020a81ac4d000000b00507739de0camr1101281ywj.495.1675422633623; Fri, 03
Feb 2023 03:10:33 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 3 Feb 2023 03:10:33 -0800 (PST)
In-Reply-To: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=62.194.189.128; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 62.194.189.128
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bf9c9ef1-b49e-49b8-bec4-a78b32c9c213n@googlegroups.com>
Subject: Re: Set a group of blank vars to a reset value.
From: arjen.ma...@gmail.com (Arjen Markus)
Injection-Date: Fri, 03 Feb 2023 11:10:33 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Arjen Markus - Fri, 3 Feb 2023 11:10 UTC

On Friday, February 3, 2023 at 11:40:48 AM UTC+1, snosniv wrote:
> I have some time entry data as mins0, secs0, mins1, secs1 etc etc, my script detects if both are unset and raises a warning, but if say mins is set but secs is blank, I set the secs to 0 (and vice-versa):
>
> if {($mins0 == "")} { set mins0 0}
> but rather than doing all the mins individually, I'd prefer a loop, but
> something like;
> for {set i 0} {$i < $max} {incr i} {
> {if $mins$i == ""} {set $mins$i 0}
> }
> obviously won't work.
> How do I do get a loop method to work please? (history means I can't really convert to an array easily).

One way to achieve this is vIa [set]:
set value0 0
set oldi 0
for {set i 1} { $i < 100} {incr i} {
set value$i [expr {1 + [set value$oldi]}]
set oldi $i
} puts [set value99]

Regards,

Arjen

Re: Set a group of blank vars to a reset value.

<29e16a03-02e7-493b-bf6a-52dbd87c0a89n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10661&group=comp.lang.tcl#10661

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a37:b446:0:b0:71d:9c4c:3ed2 with SMTP id d67-20020a37b446000000b0071d9c4c3ed2mr900219qkf.11.1675426357546;
Fri, 03 Feb 2023 04:12:37 -0800 (PST)
X-Received: by 2002:a05:690c:f8d:b0:508:3e6d:8ac1 with SMTP id
df13-20020a05690c0f8d00b005083e6d8ac1mr991598ywb.207.1675426357356; Fri, 03
Feb 2023 04:12:37 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 3 Feb 2023 04:12:36 -0800 (PST)
In-Reply-To: <bf9c9ef1-b49e-49b8-bec4-a78b32c9c213n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=82.1.128.13; posting-account=gstOigoAAADV9pmzZL58qQ436SKV3SBu
NNTP-Posting-Host: 82.1.128.13
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com> <bf9c9ef1-b49e-49b8-bec4-a78b32c9c213n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <29e16a03-02e7-493b-bf6a-52dbd87c0a89n@googlegroups.com>
Subject: Re: Set a group of blank vars to a reset value.
From: nivpars...@gmail.com (snosniv)
Injection-Date: Fri, 03 Feb 2023 12:12:37 +0000
Content-Type: text/plain; charset="UTF-8"
 by: snosniv - Fri, 3 Feb 2023 12:12 UTC

I need to set ALL times that are blank i.e. entry widget has been left empty, to value 0.
i.e. mins0, mins1, mins2 etc all need to be set to 0 if they are seen as "".

Sorry for the confusion.

Re: Set a group of blank vars to a reset value.

<e48fe4f5-0b42-4e31-8a81-4097e941aa7bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10662&group=comp.lang.tcl#10662

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:580a:0:b0:3b8:6aaf:6ad with SMTP id g10-20020ac8580a000000b003b86aaf06admr1105794qtg.400.1675426856293;
Fri, 03 Feb 2023 04:20:56 -0800 (PST)
X-Received: by 2002:a81:7284:0:b0:501:a108:2178 with SMTP id
n126-20020a817284000000b00501a1082178mr1175787ywc.510.1675426855989; Fri, 03
Feb 2023 04:20:55 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 3 Feb 2023 04:20:55 -0800 (PST)
In-Reply-To: <29e16a03-02e7-493b-bf6a-52dbd87c0a89n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=62.194.189.128; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 62.194.189.128
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
<bf9c9ef1-b49e-49b8-bec4-a78b32c9c213n@googlegroups.com> <29e16a03-02e7-493b-bf6a-52dbd87c0a89n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e48fe4f5-0b42-4e31-8a81-4097e941aa7bn@googlegroups.com>
Subject: Re: Set a group of blank vars to a reset value.
From: arjen.ma...@gmail.com (Arjen Markus)
Injection-Date: Fri, 03 Feb 2023 12:20:56 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Arjen Markus - Fri, 3 Feb 2023 12:20 UTC

On Friday, February 3, 2023 at 1:12:39 PM UTC+1, snosniv wrote:
> I need to set ALL times that are blank i.e. entry widget has been left empty, to value 0.
> i.e. mins0, mins1, mins2 etc all need to be set to 0 if they are seen as "".
>
> Sorry for the confusion.
Well, I assumed you meant you did not know how to get the value of a variable whose name is constructed. You should adapt the loop I showed ;). It merely illustrates the principle, not the solution.

Regards,

Arjen

Re: Set a group of blank vars to a reset value.

<9f42221b-7ada-4409-b9e0-342ce677f9a9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10663&group=comp.lang.tcl#10663

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:ecb:b0:71d:8e0d:1280 with SMTP id x11-20020a05620a0ecb00b0071d8e0d1280mr651717qkm.399.1675427937345;
Fri, 03 Feb 2023 04:38:57 -0800 (PST)
X-Received: by 2002:a0d:c142:0:b0:51c:2eab:bc72 with SMTP id
c63-20020a0dc142000000b0051c2eabbc72mr1033930ywd.307.1675427937089; Fri, 03
Feb 2023 04:38:57 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 3 Feb 2023 04:38:56 -0800 (PST)
In-Reply-To: <e48fe4f5-0b42-4e31-8a81-4097e941aa7bn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=82.1.128.13; posting-account=gstOigoAAADV9pmzZL58qQ436SKV3SBu
NNTP-Posting-Host: 82.1.128.13
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
<bf9c9ef1-b49e-49b8-bec4-a78b32c9c213n@googlegroups.com> <29e16a03-02e7-493b-bf6a-52dbd87c0a89n@googlegroups.com>
<e48fe4f5-0b42-4e31-8a81-4097e941aa7bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9f42221b-7ada-4409-b9e0-342ce677f9a9n@googlegroups.com>
Subject: Re: Set a group of blank vars to a reset value.
From: nivpars...@gmail.com (snosniv)
Injection-Date: Fri, 03 Feb 2023 12:38:57 +0000
Content-Type: text/plain; charset="UTF-8"
 by: snosniv - Fri, 3 Feb 2023 12:38 UTC

It's the IF part I'm struggling with.
I can set all to 0 with your method, but that overwrites valid times as well.
I'm not that conversant with Tcl, or software in general, being a hardware engineer, not software.

if {($mins0 == "")} { set mins0 0}
if {($mins1 == "")} { set mins1 0}
if {($mins2 == "")} { set mins2 0} ## i.e. set to zero only if entry widget is left empty.

Re: Set a group of blank vars to a reset value.

<ygak00y9a0l.fsf@akutech.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10665&group=comp.lang.tcl#10665

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Set a group of blank vars to a reset value.
Date: Fri, 03 Feb 2023 14:03:06 +0100
Lines: 27
Message-ID: <ygak00y9a0l.fsf@akutech.de>
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net LsKGhB23qXEueHGC8fkAlA8Gc+0svIl1kKCf4j7qvLVEzUslM=
Cancel-Lock: sha1:jgWCVKx2dChKkjen3/dN82YvF8w= sha1:byO/MN9FFplnPLt5qNzBb03Rx/0=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Fri, 3 Feb 2023 13:03 UTC

* snosniv <nivparsons@gmail.com>
| I have some time entry data as mins0, secs0, mins1, secs1 etc etc, my
| script detects if both are unset and raises a warning, but if say mins
| is set but secs is blank, I set the secs to 0 (and vice-versa):
>
| if {($mins0 == "")} { set mins0 0}
| but rather than doing all the mins individually, I'd prefer a loop, but
| something like;
| for {set i 0} {$i < $max} {incr i} {
| {if $mins$i == ""} {set $mins$i 0}
| }
| obviously won't work.
| How do I do get a loop method to work please? (history means I can't
| really convert to an array easily).

If you need to stick with the individual variable approach: the key is to
use 'set' to do the lookup (and the proper TCL syntax to start with ;-)
as in:

for {set i 0} {$i < $max} {incr i} {
if {[set mins$i] eq ""} {
set mins$i 0
}
}

HTH
R'

Re: Set a group of blank vars to a reset value.

<9ed82e00-862e-4bde-8c41-618392ee55c6n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10666&group=comp.lang.tcl#10666

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:5509:0:b0:537:702d:4db8 with SMTP id pz9-20020ad45509000000b00537702d4db8mr687569qvb.47.1675430732965;
Fri, 03 Feb 2023 05:25:32 -0800 (PST)
X-Received: by 2002:a0d:dc46:0:b0:4fa:d728:aa1f with SMTP id
f67-20020a0ddc46000000b004fad728aa1fmr904427ywe.349.1675430732754; Fri, 03
Feb 2023 05:25:32 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 3 Feb 2023 05:25:32 -0800 (PST)
In-Reply-To: <ygak00y9a0l.fsf@akutech.de>
Injection-Info: google-groups.googlegroups.com; posting-host=82.1.128.13; posting-account=gstOigoAAADV9pmzZL58qQ436SKV3SBu
NNTP-Posting-Host: 82.1.128.13
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com> <ygak00y9a0l.fsf@akutech.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9ed82e00-862e-4bde-8c41-618392ee55c6n@googlegroups.com>
Subject: Re: Set a group of blank vars to a reset value.
From: nivpars...@gmail.com (snosniv)
Injection-Date: Fri, 03 Feb 2023 13:25:32 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: snosniv - Fri, 3 Feb 2023 13:25 UTC

Sorted, thanks all for the help.
I haven't dabbled in Tcl much since I retired over 5 years ago, so forgotten quite a lot,
well, that's my excuse anyway. 😃

Thanks again, Kev P.

Re: Set a group of blank vars to a reset value.

<trj4m9$1fhdk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10667&group=comp.lang.tcl#10667

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Set a group of blank vars to a reset value.
Date: Fri, 3 Feb 2023 14:11:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <trj4m9$1fhdk$1@dont-email.me>
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com> <ygak00y9a0l.fsf@akutech.de> <9ed82e00-862e-4bde-8c41-618392ee55c6n@googlegroups.com>
Injection-Date: Fri, 3 Feb 2023 14:11:22 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="70924e14971641038013a6da2bfbfcdd";
logging-data="1557940"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QvF51jzy9W8A8l5SeVJTp"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:5eTYZUIWj3zDuDgXJlqITUa6NKA=
 by: Rich - Fri, 3 Feb 2023 14:11 UTC

snosniv <nivparsons@gmail.com> wrote:
> Sorted, thanks all for the help.
> I haven't dabbled in Tcl much since I retired over 5 years ago, so
> forgotten quite a lot, well, that's my excuse anyway. ?

The key to solving these sorts of questions yourself is to remember two
things:

1) Tcl is not Perl, the variable is not named with the sigil. $xyz is
a variable named "xyz" and $ is shorthand for "retreive contents of
the given named variable".

2) That "set" does double duty of creating/changing variable contents
*and* of retreiving the contents of named variables.

3) That expansions (both "$" and "[]") occur before the command named
in the first parameter is called

What #1 and #2 above mean is that "$" plus a variable name is the
equivalent of single parameter set, i.e.:

$varname

performs the same operation as (note the lack of $ below)

set varname

What #3 means is that you can create named variables using the contents
of other variables by using "$" or "[set varname]":

If you have this:

set varname qwerty

Then both of these:

set $varname 123
set [set varname] 123

Create a variable named "qwerty" and make it contain the string "123".

And this retreives "123" as the contents of the variable "qwerty":

set qwerty

Re: Set a group of blank vars to a reset value.

<trjjtr$1hr5m$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10671&group=comp.lang.tcl#10671

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Set a group of blank vars to a reset value.
Date: Fri, 3 Feb 2023 13:31:23 -0500
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <trjjtr$1hr5m$1@dont-email.me>
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Feb 2023 18:31:23 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="3dc65f8370ae9a2ec2e5956616b22eec";
logging-data="1633462"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EVxuGJTf4zaD0O7QStwBD"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
Cancel-Lock: sha1:jdV0TCtGQqlngy9S451LcVkazGs=
In-Reply-To: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
Content-Language: en-US
 by: saitology9 - Fri, 3 Feb 2023 18:31 UTC

On 2/3/2023 5:40 AM, snosniv wrote:
> I have some time entry data as mins0, secs0, mins1, secs1 etc etc, my script detects if both are unset and raises a warning, but if say mins is set but secs is blank, I set the secs to 0 (and vice-versa):
>
> if {($mins0 == "")} { set mins0 0}
> but rather than doing all the mins individually, I'd prefer a loop, but
> something like;
> for {set i 0} {$i < $max} {incr i} {
> {if $mins$i == ""} {set $mins$i 0}
> }
> obviously won't work.
> How do I do get a loop method to work please? (history means I can't really convert to an array easily).
>

Here is a slightly different solution, especially if you have a large
number of these variables.

Here is how you use it, with an optional third argument which is the
reset value:

test_reset mins0 secs0
test_reset mins1 secs1
....
test_reset mins100 secs100

This is the implementation:

proc test_reset {minvar secvar {def 0}} {
upvar \#0 $minvar mins
upvar \#0 $secvar secs

if {[string trim $mins] eq ""} { set mins $def }
if {[string trim $secs] eq ""} { set secs $def }

return
}

Re: Set a group of blank vars to a reset value.

<slrnttqmud.pa7s.avl@logic.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10673&group=comp.lang.tcl#10673

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: avl...@logic.at (Andreas Leitgeb)
Newsgroups: comp.lang.tcl
Subject: Re: Set a group of blank vars to a reset value.
Date: Fri, 3 Feb 2023 19:09:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <slrnttqmud.pa7s.avl@logic.at>
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
<trjjtr$1hr5m$1@dont-email.me>
Reply-To: avl@logic.at
Injection-Date: Fri, 3 Feb 2023 19:09:01 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="ac29ea357d775a38849dc630b465dc2a";
logging-data="1642639"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/S2/348dfLAWtagYQ2anXD"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Jh1lbt4Ea3OLjWKdXyrEi23KHKA=
 by: Andreas Leitgeb - Fri, 3 Feb 2023 19:09 UTC

saitology9 <saitology9@gmail.com> wrote:
> On 2/3/2023 5:40 AM, snosniv wrote:
>> I have some time entry data as mins0, secs0, mins1, secs1 etc etc, my script detects if both are unset and raises a warning, but if say mins is set but secs is blank, I set the secs to 0 (and vice-versa):
>>
>> if {($mins0 == "")} { set mins0 0}
>> but rather than doing all the mins individually, I'd prefer a loop, but
>> something like;
>> for {set i 0} {$i < $max} {incr i} {
>> {if $mins$i == ""} {set $mins$i 0}
>> }
>> obviously won't work.
>> How do I do get a loop method to work please? (history means I can't really convert to an array easily).
>>
>
> Here is a slightly different solution, especially if you have a large
> number of these variables.
>
> Here is how you use it, with an optional third argument which is the
> reset value:
>
> test_reset mins0 secs0
> test_reset mins1 secs1
> ...
> test_reset mins100 secs100

My suggestion:
for {set i 0} {$i <= 100} {incr i} {
test_reset mins$i secs$i
}

>
> This is the implementation:
>
> proc test_reset {minvar secvar {def 0}} {
> upvar \#0 $minvar mins
> upvar \#0 $secvar secs

My suggestion:
In your specific case, where all the mins# and secs# variables
are global, this is fine as it is, but more generally, I'd
advise to use level 1 instead of \#0, because then you could
use the helper to also reset local variables in other procedures,
while still being able to reset global variables, by calling
the test_reset from global level. If mins# and secs# are
always global and you want to call test_reset even from
within other procedures and still reset the global ones,
then forget the paragraph, as in that case the "#0" is just right.

One more thing: the # for upvar doesn't really need escaping,
unless you use a syntax-highlighting editor that doesn't know tcl
well - then escaping the # is harmless for tcl, but may be neeeded
to get the coloring right.

In Tcl, # only starts a comment, when it appears where the start
of a command is expected, and that isn't the case after "upvar".

> if {[string trim $mins] eq ""} { set mins $def }
> if {[string trim $secs] eq ""} { set secs $def }
>
> return
> }
>

Re: Set a group of blank vars to a reset value.

<trjmub$1hr5m$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10674&group=comp.lang.tcl#10674

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Set a group of blank vars to a reset value.
Date: Fri, 3 Feb 2023 14:22:51 -0500
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <trjmub$1hr5m$2@dont-email.me>
References: <9a42832e-9457-47b8-9b99-22fcb5662aben@googlegroups.com>
<trjjtr$1hr5m$1@dont-email.me> <slrnttqmud.pa7s.avl@logic.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Feb 2023 19:22:51 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="3dc65f8370ae9a2ec2e5956616b22eec";
logging-data="1633462"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wlrbpB/MVPounODtblJWO"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
Cancel-Lock: sha1:E1jjXQUNxfpHqIVEi6dQUoEVHJg=
In-Reply-To: <slrnttqmud.pa7s.avl@logic.at>
Content-Language: en-US
 by: saitology9 - Fri, 3 Feb 2023 19:22 UTC

On 2/3/2023 2:09 PM, Andreas Leitgeb wrote:
>>
>> test_reset mins0 secs0
>> test_reset mins1 secs1
>> ...
>> test_reset mins100 secs100
>
> My suggestion:
> for {set i 0} {$i <= 100} {incr i} {
> test_reset mins$i secs$i
> }
>

True, more so if they need are named uniformly and the call to reset
them happens for all at the same time. If you imagine a GUI where the
mins/secs are placed, that is probably one or two at a time.

>>
>> This is the implementation:
>>
>> proc test_reset {minvar secvar {def 0}} {
>> upvar \#0 $minvar mins
>> upvar \#0 $secvar secs
>
> My suggestion:
> In your specific case, where all the mins# and secs# variables
> are global, this is fine as it is, but more generally, I'd
> advise to use level 1 instead of \#0, because then you could
> use the helper to also reset local variables in other procedures,
> while still being able to reset global variables, by calling

Good point. I need to revisit the man page for upvar about these magic
level numbers :-)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor