Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Function reject.


devel / comp.lang.tcl / Can all variables be global?

SubjectAuthor
* Can all variables be global?Luc
+* Can all variables be global?Rich
|`* Can all variables be global?Kenny McCormack
| `* Can all variables be global?Luc
|  `* Can all variables be global?Rich
|   `* Can all variables be global?Mole Cool
|    `* Can all variables be global?Mole Cool
|     `* Can all variables be global?Rich
|      `- Can all variables be global?Andreas Leitgeb
+* Can all variables be global?saitology9
|+* Can all variables be global?saitology9
||`* Can all variables be global?Luc
|| `- Can all variables be global?heinrichmartin
|`* Can all variables be global?Ralf Fassel
| +* Can all variables be global?Christian Gollwitzer
| |+* Can all variables be global?Luc
| ||+- Can all variables be global?saitology9
| ||+- Can all variables be global?Michael Soyka
| ||+* Can all variables be global?Gerald Lester
| |||`- Can all variables be global?Luc
| ||`- Can all variables be global?Christian Gollwitzer
| |`- Can all variables be global?saitology9
| `- Can all variables be global?saitology9
`* Can all variables be global?Gerald Lester
 `- Can all variables be global?Ralf Fassel

1
Can all variables be global?

<20221217100113.67e4b9a6@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!b1sN13VacrNFVEB+WkY3nw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Can all variables be global?
Date: Sat, 17 Dec 2022 10:01:13 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221217100113.67e4b9a6@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="19364"; posting-host="b1sN13VacrNFVEB+WkY3nw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Sat, 17 Dec 2022 13:01 UTC

Tcl can do some pretty unusual and remarkable things, so it's worth asking:

Is there some way to make all variables global? Automatically? Even inside
procs? Maybe some introspection or everything-is-a-string Tcl sort of trick?

--
Luc
>>

Re: Can all variables be global?

<tnkj05$3lupf$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Sat, 17 Dec 2022 14:16:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <tnkj05$3lupf$1@dont-email.me>
References: <20221217100113.67e4b9a6@lud1.home>
Injection-Date: Sat, 17 Dec 2022 14:16:37 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="6912ce45860a03cd2d5f38b3c09f6947";
logging-data="3865391"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yY/SQIpLZLYZbOzkI6LYR"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:+vCTVHvtdfyp5gxJ5P4vCIE5lsQ=
 by: Rich - Sat, 17 Dec 2022 14:16 UTC

Luc <no@no.no> wrote:
> Tcl can do some pretty unusual and remarkable things, so it's worth asking:
>
> Is there some way to make all variables global?

What is the purpose? Do note that doing this is a recipie for
unintended consequences at a distance problems that rapidly become
nearly impossible to debug.

> Automatically?

No, there is no way to 'automatically' (as in without you, the
programmer, doing something to make it so) do so.

> Even inside procs?

Not automatically (as in without you the programmer doing something to
make it so).

> Maybe some introspection or everything-is-a-string Tcl sort of trick?

If you really want every variable to be global, then prefix all your
variables with ::

They will all be global that way. The rest of us will sit back and
watch the hilarity ensue.

Re: Can all variables be global?

<tnkpo2$1dpcl$1@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Sat, 17 Dec 2022 16:11:46 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tnkpo2$1dpcl$1@news.xmission.com>
References: <20221217100113.67e4b9a6@lud1.home> <tnkj05$3lupf$1@dont-email.me>
Injection-Date: Sat, 17 Dec 2022 16:11:46 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1500565"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sat, 17 Dec 2022 16:11 UTC

In article <tnkj05$3lupf$1@dont-email.me>, Rich <rich@example.invalid> wrote:
>Luc <no@no.no> wrote:
>> Tcl can do some pretty unusual and remarkable things, so it's worth asking:
>>
>> Is there some way to make all variables global?
>
>What is the purpose?

Usually, when you ask "Is it possible to do <X>?" and the first response is
"Why do you want to do <X>?", then you can assume that the answer to your
question is "No".

....
>If you really want every variable to be global, then prefix all your
>variables with ::

That's actually quite useful. That you can make a variable global by
prefixing the name with ::.

I've always done it the old-fashioned (hard) way - of having to declare it
global in every proc that uses it. Using :: looks like it would be a lot
easier. Thanks.

--
1/20/17: A great day for all those people who are sick of being told
they don't know how to spell "you're" (or "there").

Re: Can all variables be global?

<20221218021818.3aa9a236@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!EFnFE+FNepp+8xrLPQCDRg.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Sun, 18 Dec 2022 02:18:18 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221218021818.3aa9a236@lud1.home>
References: <20221217100113.67e4b9a6@lud1.home>
<tnkj05$3lupf$1@dont-email.me>
<tnkpo2$1dpcl$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="15259"; posting-host="EFnFE+FNepp+8xrLPQCDRg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Sun, 18 Dec 2022 05:18 UTC

On Sat, 17 Dec 2022 16:11:46 -0000 (UTC), Kenny McCormack wrote:

> >> Tcl can do some pretty unusual and remarkable things, so it's worth
> >> asking:
> >>
> >> Is there some way to make all variables global?
> >
> >What is the purpose?
>
> Usually, when you ask "Is it possible to do <X>?" and the first response
> is "Why do you want to do <X>?", then you can assume that the answer to
> your question is "No".
>
> ...
> >If you really want every variable to be global, then prefix all your
> >variables with ::
>
> That's actually quite useful. That you can make a variable global by
> prefixing the name with ::.
>
> I've always done it the old-fashioned (hard) way - of having to declare it
> global in every proc that uses it. Using :: looks like it would be a lot
> easier. Thanks.
>

I am aware of the :: method. I was rather wondering if there might be
something like, whenever a variable is created, apply this or that to it.

Maybe it doesn't exist, but sounds a lot like a feature that Tcl would have.

--
Luc
>>

Re: Can all variables be global?

<tnm9mf$3tm5m$1@dont-email.me>

  copy mid

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

  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: Can all variables be global?
Date: Sun, 18 Dec 2022 05:50:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <tnm9mf$3tm5m$1@dont-email.me>
References: <20221217100113.67e4b9a6@lud1.home> <tnkj05$3lupf$1@dont-email.me> <tnkpo2$1dpcl$1@news.xmission.com> <20221218021818.3aa9a236@lud1.home>
Injection-Date: Sun, 18 Dec 2022 05:50:07 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="04026c22628565a80eef6031ccd3530d";
logging-data="4118710"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LkrSxlSM/1NJkl8fcyK6j"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:+5VzBcsAYQVK54O9F1xUuFhn7Pw=
 by: Rich - Sun, 18 Dec 2022 05:50 UTC

Luc <no@no.no> wrote:
> On Sat, 17 Dec 2022 16:11:46 -0000 (UTC), Kenny McCormack wrote:
>
>> >> Tcl can do some pretty unusual and remarkable things, so it's worth
>> >> asking:
>> >>
>> >> Is there some way to make all variables global?
>> >
>> >What is the purpose?
>>
>> Usually, when you ask "Is it possible to do <X>?" and the first response
>> is "Why do you want to do <X>?", then you can assume that the answer to
>> your question is "No".
>>
>> ...
>> >If you really want every variable to be global, then prefix all your
>> >variables with ::
>>
>> That's actually quite useful. That you can make a variable global by
>> prefixing the name with ::.
>>
>> I've always done it the old-fashioned (hard) way - of having to declare it
>> global in every proc that uses it. Using :: looks like it would be a lot
>> easier. Thanks.
>>
>
>
> I am aware of the :: method. I was rather wondering if there might be
> something like, whenever a variable is created, apply this or that to it.
>
> Maybe it doesn't exist, but sounds a lot like a feature that Tcl would have.

Look at the documentation of the 'trace' command. You might be able to
cause every variable to be global with an execution trace attached to
the 'set' command. This will take a performance hit compared to
prefixing every access with ::. And it might very well cause some very
odd side effects with one or more loaded modules/packages (because
their own internal variables would also unexpectedly become globals and
could conflict with the same variable names in other loaded
modules/packages).

Re: Can all variables be global?

<98081468-e114-48f7-93f8-81e24734c5c8n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a0c:fe8e:0:b0:4d7:f4ef:2a7e with SMTP id d14-20020a0cfe8e000000b004d7f4ef2a7emr1603850qvs.121.1671361240798;
Sun, 18 Dec 2022 03:00:40 -0800 (PST)
X-Received: by 2002:ac8:5189:0:b0:3a9:7ab6:dea1 with SMTP id
c9-20020ac85189000000b003a97ab6dea1mr265986qtn.577.1671361240588; Sun, 18 Dec
2022 03:00:40 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sun, 18 Dec 2022 03:00:40 -0800 (PST)
In-Reply-To: <tnm9mf$3tm5m$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:ee:9724:f100:d1d5:458b:2080:ff0f;
posting-account=IpC1pwoAAACCAmF-qbg4PWxvUAd-j7Tc
NNTP-Posting-Host: 2003:ee:9724:f100:d1d5:458b:2080:ff0f
References: <20221217100113.67e4b9a6@lud1.home> <tnkj05$3lupf$1@dont-email.me>
<tnkpo2$1dpcl$1@news.xmission.com> <20221218021818.3aa9a236@lud1.home> <tnm9mf$3tm5m$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <98081468-e114-48f7-93f8-81e24734c5c8n@googlegroups.com>
Subject: Re: Can all variables be global?
From: molecool...@googlemail.com (Mole Cool)
Injection-Date: Sun, 18 Dec 2022 11:00:40 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 8
 by: Mole Cool - Sun, 18 Dec 2022 11:00 UTC

I think as well that this is not a good idea, but I see 2 Options:

1. Define you own set command like 'gset' and within that proc and with upvar you can archive that requirement (not tested by myself)
2. Rename set and use your own set command, again use upvar.

I think this will not work for everything in Tcl, 'array set' and other commands which will set a var may not do what you want.

Because of what 'Rich' has commented, your own 'set -> set' command is probably a better idea :-)

Re: Can all variables be global?

<e79a5046-a361-4963-932c-f4099a885f75n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:4792:0:b0:3a7:e606:2783 with SMTP id k18-20020ac84792000000b003a7e6062783mr13347075qtq.511.1671361888921;
Sun, 18 Dec 2022 03:11:28 -0800 (PST)
X-Received: by 2002:a05:620a:8087:b0:6fe:d320:697d with SMTP id
ef7-20020a05620a808700b006fed320697dmr12081081qkb.322.1671361888691; Sun, 18
Dec 2022 03:11:28 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sun, 18 Dec 2022 03:11:28 -0800 (PST)
In-Reply-To: <98081468-e114-48f7-93f8-81e24734c5c8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:ee:9724:f100:d1d5:458b:2080:ff0f;
posting-account=IpC1pwoAAACCAmF-qbg4PWxvUAd-j7Tc
NNTP-Posting-Host: 2003:ee:9724:f100:d1d5:458b:2080:ff0f
References: <20221217100113.67e4b9a6@lud1.home> <tnkj05$3lupf$1@dont-email.me>
<tnkpo2$1dpcl$1@news.xmission.com> <20221218021818.3aa9a236@lud1.home>
<tnm9mf$3tm5m$1@dont-email.me> <98081468-e114-48f7-93f8-81e24734c5c8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e79a5046-a361-4963-932c-f4099a885f75n@googlegroups.com>
Subject: Re: Can all variables be global?
From: molecool...@googlemail.com (Mole Cool)
Injection-Date: Sun, 18 Dec 2022 11:11:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 7
 by: Mole Cool - Sun, 18 Dec 2022 11:11 UTC

Regarding 'everything-is-a-string' I don't want to start a discussion here, but in my point of view this is a misleading statement, and not 'True' for Tcl. The Beauty of Tcl is, that you don't need a format call to display the string, due to the fact that everything is hold in a Tcl_Obj (The display value, and the 'double' in C, and this is dynamic). Even in other languages, like C, Phyton, your source code is 'TEXT', a number like '10.25' is text in your source code. A SQL select is most of the time 'Text' as well, HTML is text and so on ...

Re: Can all variables be global?

<tnn88g$3vunq$1@dont-email.me>

  copy mid

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

  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: Can all variables be global?
Date: Sun, 18 Dec 2022 14:31:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <tnn88g$3vunq$1@dont-email.me>
References: <20221217100113.67e4b9a6@lud1.home> <tnkj05$3lupf$1@dont-email.me> <tnkpo2$1dpcl$1@news.xmission.com> <20221218021818.3aa9a236@lud1.home> <tnm9mf$3tm5m$1@dont-email.me> <98081468-e114-48f7-93f8-81e24734c5c8n@googlegroups.com> <e79a5046-a361-4963-932c-f4099a885f75n@googlegroups.com>
Injection-Date: Sun, 18 Dec 2022 14:31:44 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="04026c22628565a80eef6031ccd3530d";
logging-data="4193018"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1881MR+SKib5r8Bpn+4Y7rj"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:MLW/hLcLa+IfN13axNigeEKjYtg=
 by: Rich - Sun, 18 Dec 2022 14:31 UTC

Mole Cool <molecool1058@googlemail.com> wrote:
> Regarding 'everything-is-a-string' I don't want to start a discussion
> here, but in my point of view this is a misleading statement,

More correctly, it is an "age-old" statement that has come to be Tcl's
"catchphrase" even still.

> and not 'True' for Tcl.

For Tcl prior to 8.0 it was factually true -- everything was a string
in pre 8.0 versions of Tcl.

For Tcl 8.0 and forward, they maintain the fasade of "everything is a
string" even though underlying reality differs in most cases.

> The Beauty of Tcl is, that you don't need a format call to display
> the string, due to the fact that everything is hold in a Tcl_Obj (The
> display value, and the 'double' in C, and this is dynamic).

Except it is not because of the Tcl_Obj, it is because the Tcl_Obj
system was designed to emulate the pre-8.0 Tcl 'everything is a string'
semantics. In an alternate universe, the Tcl_Obj system could have
just as easily pulled a Python and broke backwards compatibility and so
trying to do 'puts $number' would abort with "Error: $number is not a
string type" or some such error, forcing numbers to be output by "puts
[format %d $number]" instead.

> Even in other languages, like C, Phyton, your source code is 'TEXT',
> a number like '10.25' is text in your source code. A SQL select is
> most of the time 'Text' as well, HTML is text and so on
> ...

And so they are in your Tcl source, but how they are in the source, and
how they are stored at runtime, can, and likely, does differ.

Re: Can all variables be global?

<slrntpuo9q.21q.avl@logic.at>

  copy mid

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

  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: Can all variables be global?
Date: Sun, 18 Dec 2022 18:51:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <slrntpuo9q.21q.avl@logic.at>
References: <20221217100113.67e4b9a6@lud1.home>
<tnkj05$3lupf$1@dont-email.me> <tnkpo2$1dpcl$1@news.xmission.com>
<20221218021818.3aa9a236@lud1.home> <tnm9mf$3tm5m$1@dont-email.me>
<98081468-e114-48f7-93f8-81e24734c5c8n@googlegroups.com>
<e79a5046-a361-4963-932c-f4099a885f75n@googlegroups.com>
<tnn88g$3vunq$1@dont-email.me>
Reply-To: avl@logic.at
Injection-Date: Sun, 18 Dec 2022 18:51:38 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="57df5e6391526588ea6e3a6aa89a84a7";
logging-data="39245"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fMaKqAAXKq2gnZ8KjgQqP"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:LMbtkKw16AJkkE8BPtG+qN0zGhw=
 by: Andreas Leitgeb - Sun, 18 Dec 2022 18:51 UTC

Rich <rich@example.invalid> wrote:
> Mole Cool <molecool1058@googlemail.com> wrote:
>> Regarding 'everything-is-a-string' I don't want to start a discussion
>> here, but in my point of view this is a misleading statement,
> More correctly, it is an "age-old" statement that has come to be Tcl's
> "catchphrase" even still.

It is a "design principle" - still.

It describes how it works like, but not how it is actually implemented.
e.g. it says that after
set a "1 2 3"
set b [list 1 2 3]
the values of $a and $b are "indistinguishable".

And ditto do
set a [string range [expr {sqrt(2)}] 4 5]
set b [expr {6*7}]
give the "same" "indistinguishable" result.

> Except it is not because of the Tcl_Obj, it is because the Tcl_Obj
> system was designed to emulate the pre-8.0 Tcl 'everything is a string'
> semantics.

Tcl_Obj was just designed according to the "EIAS" principle.

Re: Can all variables be global?

<tnodtv$1v3c$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Uw/OCQynP0ivtNQPQQJATg.user.46.165.242.75.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Sun, 18 Dec 2022 20:14:34 -0500
Organization: Aioe.org NNTP Server
Message-ID: <tnodtv$1v3c$1@gioia.aioe.org>
References: <20221217100113.67e4b9a6@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="64620"; posting-host="Uw/OCQynP0ivtNQPQQJATg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9 - Mon, 19 Dec 2022 01:14 UTC

On 12/17/2022 8:01 AM, Luc wrote:
> Tcl can do some pretty unusual and remarkable things, so it's worth asking:
>
> Is there some way to make all variables global? Automatically? Even inside
> procs? Maybe some introspection or everything-is-a-string Tcl sort of trick?
>

Interesting question. As has been noted, ***don't do it***. Otherwise,
it throws all concepts of software development, code modularization,
abstraction, etc. into a spaghetti bowl.

However, this being Tcl, here is a solution:
First, a few examples of what becomes possible:

# example 1
% set who "you"
% proc say_hi {greeting} {
puts "$greeting, $who"
}

% say_hi "Good morning"
Good morning, you

# example 2
% set x 10
% set y 20
% proc multiply {} {
puts [expr $x * $y]
}

% multiply
200

% set x 100
% multiply
2000

# here is the code to make it possible
# the trick is to update or (create) proc arg's in the global scope
# and then evaluating the proc body with uplevel.
# I think it is possible to avoid renaming arg's

proc new_proc {name args body} {
set i 0
set add_cmd ""
set new_sig ""
foreach x $args {
# try to avoid name collusions
incr i
set new_arg "__x${i}__"

set xname [lindex $x 0]
if {[llength $x] == 1} {
append new_sig "$new_arg "

} else {
append new_sig "\{$new_arg \"$xinit\"\} "
}

append add_cmd "set ::$xname \$$new_arg \n"
}

# reconstruct the proc
set new_body "$add_cmd"
append new_body "\n"
append new_body "uplevel 1 \{$body\} \n"
orig_proc $name $new_sig $new_body
}

rename proc orig_proc
rename new_proc proc

Re: Can all variables be global?

<tnoe7s$1uh$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Uw/OCQynP0ivtNQPQQJATg.user.46.165.242.75.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Sun, 18 Dec 2022 20:19:51 -0500
Organization: Aioe.org NNTP Server
Message-ID: <tnoe7s$1uh$1@gioia.aioe.org>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="2001"; posting-host="Uw/OCQynP0ivtNQPQQJATg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9 - Mon, 19 Dec 2022 01:19 UTC

On 12/18/2022 8:14 PM, saitology9 wrote:
>
>         } else {
>              append new_sig "\{$new_arg \"$xinit\"\} "
>         }

I skipped over a command in the snippet above, please add as follows:

>
> } else {
> set xinit [lindex $x 1]
> append new_sig "\{$new_arg \"$xinit\"\} "
> }

Re: Can all variables be global?

<20221219042438.5511f916@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!HESYh6hlKWfwzlzvFPLFyA.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 04:24:38 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221219042438.5511f916@lud1.home>
References: <20221217100113.67e4b9a6@lud1.home>
<tnodtv$1v3c$1@gioia.aioe.org>
<tnoe7s$1uh$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="44958"; posting-host="HESYh6hlKWfwzlzvFPLFyA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Mon, 19 Dec 2022 07:24 UTC

Thank you for all the input. It is educational.

The idea of creating a "gset" (set global) proc is something obvious
I should have thought of. You see, Tcl always has a way.

Making ALL variables global is of course bad especially if it affects
variables that I didn't create myself. But in certain situations,
it may make things easier to manage. Don't worry, I will be careful.

Many thanks.

--
Luc
>>

Re: Can all variables be global?

<d0798100-202b-478d-9b14-c8a33bb374b6n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a37:4642:0:b0:6fc:a03e:fcdf with SMTP id t63-20020a374642000000b006fca03efcdfmr29319106qka.139.1671439850723;
Mon, 19 Dec 2022 00:50:50 -0800 (PST)
X-Received: by 2002:ad4:5349:0:b0:4b1:b025:54e6 with SMTP id
v9-20020ad45349000000b004b1b02554e6mr76612555qvs.53.1671439850601; Mon, 19
Dec 2022 00:50:50 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 19 Dec 2022 00:50:50 -0800 (PST)
In-Reply-To: <20221219042438.5511f916@lud1.home>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.227.61; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.227.61
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
<tnoe7s$1uh$1@gioia.aioe.org> <20221219042438.5511f916@lud1.home>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d0798100-202b-478d-9b14-c8a33bb374b6n@googlegroups.com>
Subject: Re: Can all variables be global?
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Mon, 19 Dec 2022 08:50:50 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1588
 by: heinrichmartin - Mon, 19 Dec 2022 08:50 UTC

On Monday, December 19, 2022 at 8:24:43 AM UTC+1, Luc wrote:
> The idea of creating a "gset" (set global) proc is something obvious

Just note that there are other procs that create/set variables.
Also, tempering with set (i.e. if you wanted to redirect built-in set) is hardly ever a good idea.

As this thread (also) is about options in Tcl: one could redirect proc and rewrite the body.

Re: Can all variables be global?

<ygav8m7o3ts.fsf@akutech.de>

  copy mid

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

  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: Can all variables be global?
Date: Mon, 19 Dec 2022 15:39:27 +0100
Lines: 16
Message-ID: <ygav8m7o3ts.fsf@akutech.de>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net azu3/cPUij5zp4MavTNbnA8xTdQp6aUE5CxFwwmMwUN7X+o34=
Cancel-Lock: sha1:Q+gV2ilmU9H8jDxB0htr9geQDUw= sha1:s9P2Xlo5+tcTo0pGMgC7Pl/grQU=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Mon, 19 Dec 2022 14:39 UTC

* saitology9 <saitology9@gmail.com>
| # the trick is to update or (create) proc arg's in the global scope
| # and then evaluating the proc body with uplevel.

I would say that the proc's args should *not* go into the global
namespace, since they do exist as locals inside the proc and cause no
problem.

At least *I* would certainly not want to override some arbitrary global
variable which just happens to have the same name as the proc arg of
some random function.

However, this certainly will help to achieve the horror Rich predicted
elsethread :-)

R'

Re: Can all variables be global?

<tnptb1$672$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!xQtVYMimCTmGN2YE7Vurrg.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.L...@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 08:43:45 -0600
Organization: KnG Consulting, LLC
Message-ID: <tnptb1$672$1@gioia.aioe.org>
References: <20221217100113.67e4b9a6@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="6370"; posting-host="xQtVYMimCTmGN2YE7Vurrg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Gerald Lester - Mon, 19 Dec 2022 14:43 UTC

On 12/17/22 07:01, Luc wrote:
> Tcl can do some pretty unusual and remarkable things, so it's worth asking:
>
> Is there some way to make all variables global? Automatically? Even inside
> procs? Maybe some introspection or everything-is-a-string Tcl sort of trick?
>

Not just NO, but HELL NO -- and for good reason as others have pointed out.

BTW, Tcl does not and will not have GOTOs either -- also for good reasons.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+

Re: Can all variables be global?

<tnptrs$c5qu$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: aurio...@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 15:52:43 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <tnptrs$c5qu$1@dont-email.me>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 19 Dec 2022 14:52:44 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="d764335055e7550fa545ba0246e0ba9c";
logging-data="399198"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H/z7tueO9Yu0q2Y/Xz2+itY59tYBEGNs="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.6.0
Cancel-Lock: sha1:UrcEDUCwEXD4yMjXlGe+5Mr7CPs=
In-Reply-To: <ygav8m7o3ts.fsf@akutech.de>
 by: Christian Gollwitzer - Mon, 19 Dec 2022 14:52 UTC

Am 19.12.22 um 15:39 schrieb Ralf Fassel:
> * saitology9 <saitology9@gmail.com>
> | # the trick is to update or (create) proc arg's in the global scope
> | # and then evaluating the proc body with uplevel.
>
> I would say that the proc's args should *not* go into the global
> namespace, since they do exist as locals inside the proc and cause no
> problem.

I think you can circumvent this by putting the vars into a special
namespace. Since all vars should be global, namespaces will not occur.

>
> At least *I* would certainly not want to override some arbitrary global
> variable which just happens to have the same name as the proc arg of
> some random function.
>
> However, this certainly will help to achieve the horror Rich predicted
> elsethread :-)

Yes it is pure hell. There are a few "programming languages" like this
(e.g. SPECS instrument control system) which have no local variables and
it becomes hell whenever you decide to import a library written by
someone else.

I think there is still a "bug", though - the "uplevel 1" will not work
when it is a nested procedure call. "uplevel #0" would do the trick to
run the code at global scope. I haven't tested it, so might be wrong ;)

Christian

Re: Can all variables be global?

<ygamt7jo21l.fsf@akutech.de>

  copy mid

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

  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: Can all variables be global?
Date: Mon, 19 Dec 2022 16:17:58 +0100
Lines: 14
Message-ID: <ygamt7jo21l.fsf@akutech.de>
References: <20221217100113.67e4b9a6@lud1.home> <tnptb1$672$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net xuALm5zGatT0PdqLrci32wOVEYEB1VO1LfhFVpP3n6UD2cS4E=
Cancel-Lock: sha1:DEvEhxYQhobKjvG/gJhywAvL8xY= sha1:KhQ35TVJcGU17NpA6lAsnGr6oDs=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Mon, 19 Dec 2022 15:17 UTC

* Gerald Lester <Gerald.Lester@KnG-Consulting.net>
| On 12/17/22 07:01, Luc wrote:
| > Tcl can do some pretty unusual and remarkable things, so it's worth asking:
| > Is there some way to make all variables global? Automatically? Even
| > inside
| > procs? Maybe some introspection or everything-is-a-string Tcl sort of trick?
| >
>
| Not just NO, but HELL NO -- and for good reason as others have pointed out.

It is FUN however, in that it produces side effects you would not have
dreamed of :-))) Would probably be a nice question in a job interview...

R'

Re: Can all variables be global?

<20221219124512.20482552@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!HESYh6hlKWfwzlzvFPLFyA.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 12:45:12 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221219124512.20482552@lud1.home>
References: <20221217100113.67e4b9a6@lud1.home>
<tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de>
<tnptrs$c5qu$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="54758"; posting-host="HESYh6hlKWfwzlzvFPLFyA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Mon, 19 Dec 2022 15:45 UTC

On Mon, 19 Dec 2022 15:52:43 +0100, Christian Gollwitzer wrote:

> Yes it is pure hell. There are a few "programming languages" like this
> (e.g. SPECS instrument control system) which have no local variables and
> it becomes hell whenever you decide to import a library written by
> someone else.

I'm pretty sure there is a very large number of programs/scripts out there
that will never ever interact with any external libraries or packages or
remote machines and will never be shared. That kind of use exists, it's very
common and cannot (and should not) be prevented.

What also cannot be prevented is that someone begins a script/program with
some kind of inventory of all variables used in the program and making them
all globals with the 'global' command. Any possible implementation of what
I asked would merely automate something that already can be done although
in a tedious manner.

--
Luc
>>

Re: Can all variables be global?

<tnq1sh$e8l$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Uw/OCQynP0ivtNQPQQJATg.user.46.165.242.75.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 11:01:16 -0500
Organization: Aioe.org NNTP Server
Message-ID: <tnq1sh$e8l$1@gioia.aioe.org>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de> <tnptrs$c5qu$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="14613"; posting-host="Uw/OCQynP0ivtNQPQQJATg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9 - Mon, 19 Dec 2022 16:01 UTC

On 12/19/2022 9:52 AM, Christian Gollwitzer wrote:
>>
>> I would say that the proc's args should *not* go into the global
>> namespace, since they do exist as locals inside the proc and cause no
>> problem.
>
> I think you can circumvent this by putting the vars into a special
> namespace. Since all vars should be global, namespaces will not occur.
>

I agree. I thought that was the intention anyway. One can certainly hide
the previous values of such variables in a list and restore them in a
try-catch block.

> I think there is still a "bug", though  - the "uplevel 1" will not work
> when it is a nested procedure call. "uplevel #0" would do the trick to
> run the code at global scope. I haven't tested it, so might be wrong ;)
>

You're probably right - I forgot that there was a deeper level than 1 :-)

Re: Can all variables be global?

<tnq20u$e8l$2@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Uw/OCQynP0ivtNQPQQJATg.user.46.165.242.75.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 11:03:38 -0500
Organization: Aioe.org NNTP Server
Message-ID: <tnq20u$e8l$2@gioia.aioe.org>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="14613"; posting-host="Uw/OCQynP0ivtNQPQQJATg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9 - Mon, 19 Dec 2022 16:03 UTC

On 12/19/2022 9:39 AM, Ralf Fassel wrote:
>
> I would say that the proc's args should *not* go into the global
> namespace, since they do exist as locals inside the proc and cause no
> problem.
>

One can circumvent this by saving/restoring them but frankly I think
this was the intended result.

> However, this certainly will help to achieve the horror Rich predicted
> elsethread :-)
>

I agree. And it is fun as you said in another post.

Re: Can all variables be global?

<tnq2a8$lv6$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!Uw/OCQynP0ivtNQPQQJATg.user.46.165.242.75.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 11:08:35 -0500
Organization: Aioe.org NNTP Server
Message-ID: <tnq2a8$lv6$1@gioia.aioe.org>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de> <tnptrs$c5qu$1@dont-email.me>
<20221219124512.20482552@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="22502"; posting-host="Uw/OCQynP0ivtNQPQQJATg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9 - Mon, 19 Dec 2022 16:08 UTC

On 12/19/2022 10:45 AM, Luc wrote:
>
> What also cannot be prevented is that someone begins a script/program with
> some kind of inventory of all variables used in the program and making them
> all globals with the 'global' command. Any possible implementation of what
> I asked would merely automate something that already can be done although
> in a tedious manner.
>
>

I haven't read all the replies in detail but perhaps it was the way you
first expressed it: make every variable global.

However, the construct to achieve a similar goal is useful and exists in
some iconic languages including Lisp.

Re: Can all variables be global?

<tnq2d1$cglg$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mssr...@gmail.com (Michael Soyka)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 11:10:07 -0500
Organization: self
Lines: 35
Message-ID: <tnq2d1$cglg$1@dont-email.me>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de> <tnptrs$c5qu$1@dont-email.me>
<20221219124512.20482552@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 19 Dec 2022 16:10:09 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="1099114eae3138e64d8e183e8a352c3d";
logging-data="410288"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vzGVoeby6cIa0APZaxHmW"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Cancel-Lock: sha1:byzR0HAl5objbuOOZjP7f7YGmWU=
In-Reply-To: <20221219124512.20482552@lud1.home>
Content-Language: en-US
 by: Michael Soyka - Mon, 19 Dec 2022 16:10 UTC

On 12/19/2022 10:45 AM, Luc wrote:
> On Mon, 19 Dec 2022 15:52:43 +0100, Christian Gollwitzer wrote:
>
>> Yes it is pure hell. There are a few "programming languages" like this
>> (e.g. SPECS instrument control system) which have no local variables and
>> it becomes hell whenever you decide to import a library written by
>> someone else.
>
>
> I'm pretty sure there is a very large number of programs/scripts out there
> that will never ever interact with any external libraries or packages or
> remote machines and will never be shared. That kind of use exists, it's very
> common and cannot (and should not) be prevented.
>
> What also cannot be prevented is that someone begins a script/program with
> some kind of inventory of all variables used in the program and making them
> all globals with the 'global' command. Any possible implementation of what
> I asked would merely automate something that already can be done although
> in a tedious manner.
>
>
How about defining a dictionary variable in the global scope whose keys
are the global variable names? Without thinking too much it seems easy
to use an editor command to then do the code modifications:

s/globalVar/g["globalVar"]/g

where "g" is the dictionary variable in global scope. It certainly
reduces the likelihood of name collisions in the global namespace at the
expense of reformatting the code.

Although, now that I've suggested it, array and dictionary variables
would be a fly in the soup. Well, for a few moments, it was an idea!

-mike

Re: Can all variables be global?

<tnq5bt$61m$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!xQtVYMimCTmGN2YE7Vurrg.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.L...@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 11:00:45 -0600
Organization: KnG Consulting, LLC
Message-ID: <tnq5bt$61m$1@gioia.aioe.org>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de> <tnptrs$c5qu$1@dont-email.me>
<20221219124512.20482552@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="6198"; posting-host="xQtVYMimCTmGN2YE7Vurrg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Gerald Lester - Mon, 19 Dec 2022 17:00 UTC

On 12/19/22 09:45, Luc wrote:
> On Mon, 19 Dec 2022 15:52:43 +0100, Christian Gollwitzer wrote:
>
>> Yes it is pure hell. There are a few "programming languages" like this
>> (e.g. SPECS instrument control system) which have no local variables and
>> it becomes hell whenever you decide to import a library written by
>> someone else.
>
>
> I'm pretty sure there is a very large number of programs/scripts out there
> that will never ever interact with any external libraries or packages or
> remote machines and will never be shared. That kind of use exists, it's very
> common and cannot (and should not) be prevented.
>
> What also cannot be prevented is that someone begins a script/program with
> some kind of inventory of all variables used in the program and making them
> all globals with the 'global' command. Any possible implementation of what
> I asked would merely automate something that already can be done although
> in a tedious manner.

The 'global' command would have to be done inside of each procedure.

Doing 'global' at the global scope level has no effect.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+

Re: Can all variables be global?

<20221219143134.24e1f4d9@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!HESYh6hlKWfwzlzvFPLFyA.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 14:31:34 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221219143134.24e1f4d9@lud1.home>
References: <20221217100113.67e4b9a6@lud1.home>
<tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de>
<tnptrs$c5qu$1@dont-email.me>
<20221219124512.20482552@lud1.home>
<tnq5bt$61m$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="32864"; posting-host="HESYh6hlKWfwzlzvFPLFyA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Mon, 19 Dec 2022 17:31 UTC

On Mon, 19 Dec 2022 11:10:07 -0500, Michael Soyka wrote:

> How about defining a dictionary variable in the global scope whose keys
> are the global variable names? Without thinking too much it seems easy
> to use an editor command to then do the code modifications:
>
> s/globalVar/g["globalVar"]/g
>
> where "g" is the dictionary variable in global scope. It certainly
> reduces the likelihood of name collisions in the global namespace at the
> expense of reformatting the code.
************************

Yes, it's an interesting idea. I probably won't use it, but I'll probably
have fun toying with it in a throwaway script. It's educational. Tcl is
full of interesting tricks.

**************************
On Mon, 19 Dec 2022 11:00:45 -0600, Gerald Lester wrote:

> The 'global' command would have to be done inside of each procedure.
> Doing 'global' at the global scope level has no effect.

Thanks. It's good to know.

Still doable though. Only *more* tedious.

--
Luc
>>

Re: Can all variables be global?

<tnq92o$dc7b$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: aurio...@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: Can all variables be global?
Date: Mon, 19 Dec 2022 19:04:08 +0100
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <tnq92o$dc7b$1@dont-email.me>
References: <20221217100113.67e4b9a6@lud1.home> <tnodtv$1v3c$1@gioia.aioe.org>
<ygav8m7o3ts.fsf@akutech.de> <tnptrs$c5qu$1@dont-email.me>
<20221219124512.20482552@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 19 Dec 2022 18:04:08 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="673412bb5b8e57e02285914e89798d66";
logging-data="438507"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OmhpBfmFfKrSlvleWghLHWU4R16HpM/o="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.6.0
Cancel-Lock: sha1:tKAHZMYHY1vJpanoWtcTuDW1Qs0=
In-Reply-To: <20221219124512.20482552@lud1.home>
 by: Christian Gollwitzer - Mon, 19 Dec 2022 18:04 UTC

Am 19.12.22 um 16:45 schrieb Luc:
> On Mon, 19 Dec 2022 15:52:43 +0100, Christian Gollwitzer wrote:
>
>> Yes it is pure hell. There are a few "programming languages" like this
>> (e.g. SPECS instrument control system) which have no local variables and
>> it becomes hell whenever you decide to import a library written by
>> someone else.
>
>
> I'm pretty sure there is a very large number of programs/scripts out there
> that will never ever interact with any external libraries or packages or
> remote machines and will never be shared. That kind of use exists, it's very
> common and cannot (and should not) be prevented.

I mentioned the SPECS thing exactly because this started as a language
for scripts which does not require external libraries etc. It is a
specialised language for driving scientific equipment to acquire data. A
colleague had written some advanced measurement procedures in it, then
wanted to integrate a new detector. The vendor of this detector provides
SPECs macros - which then, of course, used variable names which collided
with the script from my colleague. In the end, we threw everything
overboard and switched to a more sane system. That was easier then to
untangle the codes.

>
> What also cannot be prevented is that someone begins a script/program with
> some kind of inventory of all variables used in the program and making them
> all globals with the 'global' command. Any possible implementation of what
> I asked would merely automate something that already can be done although
> in a tedious manner.
>

I'm still not sure I understand WHY you would want to have something
like that. However, I'm quite sure that there are better solutions. One
of them could be the use of an object system. There, you declare
variables once, but you don't have to repeat the "variable x" or "global
x" in each and every proc.

E.g.:

oo::class create testglobals {

variable x
variable y

method setxy {x_ y_} {
set x $x_
set y $y_
}

method print {} {
puts "x: $x y: $y"
}
}

testglobals create B

B setxy 3 4
B print

As you can see here, in both methods setxy and print, you can access the
variables "x" and "y" without specially annotating them. However, since
they are marked as a variable in the class declaration, you could some
other variable "set i 7" in one of them without interfering with other
parts of the code.

Christian

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor