Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"...a most excellent barbarian ... Genghis Kahn!" -- _Bill And Ted's Excellent Adventure_


devel / comp.lang.tcl / Re: why is this variable not in global namespace?

SubjectAuthor
* why is this variable not in global namespace?Michael Soyka
`* Re: why is this variable not in global namespace?dave bruchie
 `* Re: why is this variable not in global namespace?Michael Soyka
  `- Re: why is this variable not in global namespace?Paul Walton

1
why is this variable not in global namespace?

<tv0cgl$1k5f1$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mssr953@gmail.com (Michael Soyka)
Newsgroups: comp.lang.tcl
Subject: why is this variable not in global namespace?
Date: Thu, 16 Mar 2023 20:33:24 -0400
Organization: self
Lines: 61
Message-ID: <tv0cgl$1k5f1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Mar 2023 00:33:25 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="8f63c92f1fb4ec2ebbb8e8be6278e95c";
logging-data="1709537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181AgVAQxyjYIvqq/TCepNF"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:h2FVW8rYEX5j5HFgrZ3PQ1mfALI=
Content-Language: en-US
 by: Michael Soyka - Fri, 17 Mar 2023 00:33 UTC

As I was investigating a "package require" issue, I came across the
following surprising, to me, behavior. Needless to say, I don't
understand it.

I expected the following code to instantiate the variable "myGlobal" in
the global namespace:

namespace eval Wrapper {
global myGlobal
if { ![info exists myGlobal] } {
set myGlobal [namespace current]
}
puts "myGlobal: $myGlobal"
foreach varName {myGlobal ::myGlobal ::Wrapper::myGlobal} {
puts "Exists? $varName: [info exists $varName]"
}
}

but the output:

myGlobal: ::Wrapper
Exists? myGlobal: 1
Exists? ::myGlobal: 0
Exists? ::Wrapper::myGlobal: 1

says that "myGlobal" instead lives in the "Wrapper" namespace.

If the above code is preceded by this statement:

set myGlobal XXX

we get this output:

myGlobal: XXX
Exists? myGlobal: 1
Exists? ::myGlobal: 1
Exists? ::Wrapper::myGlobal: 0

which shows "myGlobal" is defined in the global namespace.

Finally, if we change the namespace command in the first example to a proc:

proc Wrapper {} {
global myGlobal
set myGlobal XXX
}
Wrapper
puts "Exists? myGlobal [info exists myGlobal]"

"myGlobal" is defined in the global namespace which is expected.

I get that in examples 1 and 3 "myGlobal" does not exist initially but
the "namespace" and "proc" commands yield different results. So, the
question is why the difference?

TIA for the coming education!

-mike

Re: why is this variable not in global namespace?

<ab512ac1-cd5a-47d1-a7f2-680dedff51d1n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:92c:b0:5a2:f831:ba3c with SMTP id dk12-20020a056214092c00b005a2f831ba3cmr5049147qvb.8.1679064244392;
Fri, 17 Mar 2023 07:44:04 -0700 (PDT)
X-Received: by 2002:a81:e205:0:b0:52a:9f66:80c6 with SMTP id
p5-20020a81e205000000b0052a9f6680c6mr4467370ywl.9.1679064243935; Fri, 17 Mar
2023 07:44:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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: Fri, 17 Mar 2023 07:44:03 -0700 (PDT)
In-Reply-To: <tv0cgl$1k5f1$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=63.135.67.185; posting-account=DOTNLQoAAABT9g43GKuXRTA7JYjJG7y7
NNTP-Posting-Host: 63.135.67.185
References: <tv0cgl$1k5f1$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ab512ac1-cd5a-47d1-a7f2-680dedff51d1n@googlegroups.com>
Subject: Re: why is this variable not in global namespace?
From: jdavebr@gmail.com (dave bruchie)
Injection-Date: Fri, 17 Mar 2023 14:44:04 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1397
 by: dave bruchie - Fri, 17 Mar 2023 14:44 UTC

the first line of the global man page says: This command has no effect unless executed in the context of a proc body.

If you remove the "global myGlobal: line from your example, there should be no change in the results.
The variable is created (or not) in the normal way by the following set command.

Dave B

Re: why is this variable not in global namespace?

<tv216r$20nbv$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mssr953@gmail.com (Michael Soyka)
Newsgroups: comp.lang.tcl
Subject: Re: why is this variable not in global namespace?
Date: Fri, 17 Mar 2023 11:32:42 -0400
Organization: self
Lines: 22
Message-ID: <tv216r$20nbv$1@dont-email.me>
References: <tv0cgl$1k5f1$1@dont-email.me>
<ab512ac1-cd5a-47d1-a7f2-680dedff51d1n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Mar 2023 15:32:43 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="8f63c92f1fb4ec2ebbb8e8be6278e95c";
logging-data="2121087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nR7U+DkgOO67GY5l8ek9d"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:kJ8Y9/Hy5zhCdpli0TF167MwryE=
In-Reply-To: <ab512ac1-cd5a-47d1-a7f2-680dedff51d1n@googlegroups.com>
Content-Language: en-US
 by: Michael Soyka - Fri, 17 Mar 2023 15:32 UTC

On 03/17/2023 10:44 AM, dave bruchie wrote:
> the first line of the global man page says: This command has no effect unless executed in the context of a proc body.
>
> If you remove the "global myGlobal: line from your example, there should be no change in the results.
> The variable is created (or not) in the normal way by the following set command.
>
> Dave B
Hi Dave,

Thanks for the reply. I had seen the clear statement in that manpage
but I guess it didn't register.

So, it looks like you don't need to use a "variable" command in a
namespace in order to create that variable in the namespace. The reason
for using one, outside of a proc, is to ensure the variable is created
in the namespace just in case that variable also exists in the global
namespace.

The method used to resolve variable names is explained in the "Name
Resolution" section of the "namespace" manpage.

-mike

Re: why is this variable not in global namespace?

<482c019b-dac7-4531-be11-494f4b37ff86n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:ab4:b0:56e:a0ba:cc3e with SMTP id ew20-20020a0562140ab400b0056ea0bacc3emr5812096qvb.0.1679090121635;
Fri, 17 Mar 2023 14:55:21 -0700 (PDT)
X-Received: by 2002:a81:af63:0:b0:52e:d380:ab14 with SMTP id
x35-20020a81af63000000b0052ed380ab14mr4034338ywj.3.1679090121350; Fri, 17 Mar
2023 14:55:21 -0700 (PDT)
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: Fri, 17 Mar 2023 14:55:21 -0700 (PDT)
In-Reply-To: <tv216r$20nbv$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2605:59c8:6060:8d10:b1ab:e989:8045:8485;
posting-account=mOejMQoAAAB4Jax2kMMnh00w-BbOXpD-
NNTP-Posting-Host: 2605:59c8:6060:8d10:b1ab:e989:8045:8485
References: <tv0cgl$1k5f1$1@dont-email.me> <ab512ac1-cd5a-47d1-a7f2-680dedff51d1n@googlegroups.com>
<tv216r$20nbv$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <482c019b-dac7-4531-be11-494f4b37ff86n@googlegroups.com>
Subject: Re: why is this variable not in global namespace?
From: walton.paul@gmail.com (Paul Walton)
Injection-Date: Fri, 17 Mar 2023 21:55:21 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1681
 by: Paul Walton - Fri, 17 Mar 2023 21:55 UTC

On Friday, March 17, 2023 at 11:32:48 AM UTC-4, Michael Soyka wrote:
> just in case that variable also exists in the global

I think globals become much more manageable and readable if you just enforce a style of always referring to them with the fully qualified name, such as ::VAR and also use all caps. The global command is unnecessary and hinders readability in my opinion.


devel / comp.lang.tcl / Re: why is this variable not in global namespace?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor