Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Live long and prosper. -- Spock, "Amok Time", stardate 3372.7


devel / comp.lang.tcl / Re: can't create namespace variable that refers to procedure variable

SubjectAuthor
* can't create namespace variable that refers to procedure variableLuc
`* can't create namespace variable that refers to procedure variableRich
 `* can't create namespace variable that refers to procedure variableLuc
  `* can't create namespace variable that refers to procedure variableRich
   `* can't create namespace variable that refers to procedure variableLuc
    `* can't create namespace variable that refers to procedure variableRich
     `- can't create namespace variable that refers to procedure variableet99

1
can't create namespace variable that refers to procedure variable

<20240108151159.0bff5ffe@lud1.home>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13122&group=comp.lang.tcl#13122

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: can't create namespace variable that refers to procedure variable
Date: Mon, 8 Jan 2024 15:11:59 -0300
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <20240108151159.0bff5ffe@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="99cfb12da70c4565ae569c7143cf6cfb";
logging-data="1718273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eWHKLfmfLn9MDkvE6iwPSzHnKDb8+6vo="
Cancel-Lock: sha1:AnBC2GXMuEzXNM4KA36Dm8EuWgM=
 by: Luc - Mon, 8 Jan 2024 18:11 UTC

There isn't much about this on Google.

This doesn't work:

proc do {} {
set adjective "good"
namespace eval ns {
upvar 1 adjective quality
puts $quality
}
} do

error: bad variable name "quality": can't create namespace variable
that refers to procedure variable

I understand the words but not what the message is trying to tell me.

And then this kludge works:

proc do {} {
namespace eval ns {}
set ns::quality "good"
namespace eval ns {
puts $quality
}
} do

output: good

I feel like I just cheated to do somethinhg I was not supposed to.
What exactly happened here?

--
Luc
>>

Re: can't create namespace variable that refers to procedure variable

<unhtb5$1mo4j$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13124&group=comp.lang.tcl#13124

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: can't create namespace variable that refers to procedure variable
Date: Mon, 8 Jan 2024 22:35:17 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <unhtb5$1mo4j$1@dont-email.me>
References: <20240108151159.0bff5ffe@lud1.home>
Injection-Date: Mon, 8 Jan 2024 22:35:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="362e4ed0701982492d30bdaa94481307";
logging-data="1794195"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+c/PmuwEVi1O+pDeNGmORZ"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:eFk6lAm9DRLcgDjSROhk+LKqGCY=
 by: Rich - Mon, 8 Jan 2024 22:35 UTC

Luc <luc@sep.invalid> wrote:
> There isn't much about this on Google.
>
> This doesn't work:
>
> proc do {} {
> set adjective "good"
> namespace eval ns {
> upvar 1 adjective quality
> puts $quality
> }
> }
> do
>
> error: bad variable name "quality": can't create namespace variable
> that refers to procedure variable
>
>
> I understand the words but not what the message is trying to tell me.

The message is trying to tell you what it plainly says. You can't do
what you tried to do.

upvar is used to refer to variables in the procedure call stack.

namespaces are not procedures (and do not have a 'position' in the
procedure call stack).

upvar (when used in a procedure) makes a variable in the current
procedure be a reference to another one in the call stack.

upvar used in a namespace is nonsense, as namespaces exist separate
from the call stack. You can't create a "reference" in a namespace to
a local variable in a proc, because while the reference would be valid
while the current proc invocation exists, the moment the proc returns,
the 'reference' in the namespace would be pointing to a variable that
no longer exists (proc locals only exist while the proc is running,
once the proc returns, all of the proc locals go away).

> And then this kludge works:
>
> proc do {} {
> namespace eval ns {}
> set ns::quality "good"
> namespace eval ns {
> puts $quality
> }
> }
> do

That's not a kluge, that is one valid way to create, and set, a
variable in a namespace.

> I feel like I just cheated to do somethinhg I was not supposed to.
> What exactly happened here?

You tried to do something that is nonsensical. upvar connects together
local variables in different procs. Namespaces are not procs,
therefore, trying to connect a namespace variable to a proc local is
nonsense.

Re: can't create namespace variable that refers to procedure variable

<20240108203533.3171b9f7@lud1.home>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13125&group=comp.lang.tcl#13125

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: can't create namespace variable that refers to procedure
variable
Date: Mon, 8 Jan 2024 20:35:33 -0300
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <20240108203533.3171b9f7@lud1.home>
References: <20240108151159.0bff5ffe@lud1.home>
<unhtb5$1mo4j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="0bc67b280207f0740eb3a1cb6d10db3e";
logging-data="1809309"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187zKDeolgMhUz8dDmXhU2NJmekEFFEsBw="
Cancel-Lock: sha1:7ciBWUkhJWukyl0svlBtwGak3Ew=
 by: Luc - Mon, 8 Jan 2024 23:35 UTC

On Mon, 8 Jan 2024 22:35:17 -0000 (UTC), Rich wrote:

>You tried to do something that is nonsensical. upvar connects together
>local variables in different procs. Namespaces are not procs,
>therefore, trying to connect a namespace variable to a proc local is
>nonsense.

Thank you.

Your explanation makes a lot of sense, but can you really blame me for
the mixup when there is a 'namespace upvar' command? Does that command
qualify as 'nonsense' too?

--
Luc
>>

Re: can't create namespace variable that refers to procedure variable

<uni8o6$1o2t6$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13126&group=comp.lang.tcl#13126

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: can't create namespace variable that refers to procedure variable
Date: Tue, 9 Jan 2024 01:49:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <uni8o6$1o2t6$1@dont-email.me>
References: <20240108151159.0bff5ffe@lud1.home> <unhtb5$1mo4j$1@dont-email.me> <20240108203533.3171b9f7@lud1.home>
Injection-Date: Tue, 9 Jan 2024 01:49:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d56598f3b7168a3df823f9e67148e2d0";
logging-data="1837990"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1867UCBim9egndjP0kWy60d"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:q1Q7IcjmiaNfCjfZYaPaoIN5LCY=
 by: Rich - Tue, 9 Jan 2024 01:49 UTC

Luc <luc@sep.invalid> wrote:
> On Mon, 8 Jan 2024 22:35:17 -0000 (UTC), Rich wrote:
>
>>You tried to do something that is nonsensical. upvar connects
>>together local variables in different procs. Namespaces are not
>>procs, therefore, trying to connect a namespace variable to a proc
>>local is nonsense.
>
>
> Thank you.
>
> Your explanation makes a lot of sense, but can you really blame me for
> the mixup when there is a 'namespace upvar' command? Does that command
> qualify as 'nonsense' too?

No, because it is defined as linking namespace variables into the
current proc as locals for that proc.

Both are for creating proc local variables that link to other places.

You were trying to create a "namespace variable" that was a link
referring to a proc local variable. Which link would (if it could be
created in the first place) become invalid as soon as the proc returns.

Re: can't create namespace variable that refers to procedure variable

<20240109024931.4d3055e6@lud1.home>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13127&group=comp.lang.tcl#13127

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: can't create namespace variable that refers to procedure
variable
Date: Tue, 9 Jan 2024 02:49:31 -0300
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <20240109024931.4d3055e6@lud1.home>
References: <20240108151159.0bff5ffe@lud1.home>
<unhtb5$1mo4j$1@dont-email.me>
<20240108203533.3171b9f7@lud1.home>
<uni8o6$1o2t6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="0bc67b280207f0740eb3a1cb6d10db3e";
logging-data="2010961"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184rJfVNGhwMdTfEbCXoJ734UzeOvhWre8="
Cancel-Lock: sha1:kW6mKZcva8nRjU/XEp0U6v8FWIE=
 by: Luc - Tue, 9 Jan 2024 05:49 UTC

On Tue, 9 Jan 2024 01:49:58 -0000 (UTC), Rich wrote:

>No, because it is defined as linking namespace variables into the
>current proc as locals for that proc.

OK. Though still weird that someone might prefer

namespace upvar ns var localvar
set localvar 125

to a much simpler

set ns::var 125

Anyway, I wish I had used namespaces sooner. I spent so much time
worrying about keeping track of the tabs, like

set tabID [dict get $::FlowControl ActiveTabID]

then using tons of [dict get] here and there to access multiple values
in complicated ways.

Now I just get the ID then run everything inside

namespace eval $tabID {}

and everything just works with much simpler syntax and all the context
separation I always meant in the first place. Even that thread thing
is working with simpler code.

--
Luc
>>

Re: can't create namespace variable that refers to procedure variable

<unk98e$24p6t$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13128&group=comp.lang.tcl#13128

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: can't create namespace variable that refers to procedure variable
Date: Tue, 9 Jan 2024 20:10:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <unk98e$24p6t$1@dont-email.me>
References: <20240108151159.0bff5ffe@lud1.home> <unhtb5$1mo4j$1@dont-email.me> <20240108203533.3171b9f7@lud1.home> <uni8o6$1o2t6$1@dont-email.me> <20240109024931.4d3055e6@lud1.home>
Injection-Date: Tue, 9 Jan 2024 20:10:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d56598f3b7168a3df823f9e67148e2d0";
logging-data="2254045"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180xVSS1yng7AEiILm9M5C6"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:Nnlm+oYB1Iirl6xkC0JiNTd1zTo=
 by: Rich - Tue, 9 Jan 2024 20:10 UTC

Luc <luc@sep.invalid> wrote:
> On Tue, 9 Jan 2024 01:49:58 -0000 (UTC), Rich wrote:
>
>>No, because it is defined as linking namespace variables into the
>>current proc as locals for that proc.
>
>
> OK. Though still weird that someone might prefer
>
> namespace upvar ns var localvar
> set localvar 125
>
> to a much simpler
>
> set ns::var 125
>
>
> Anyway, I wish I had used namespaces sooner. I spent so much time
> worrying about keeping track of the tabs, like
>
> set tabID [dict get $::FlowControl ActiveTabID]
>
> then using tons of [dict get] here and there to access multiple values
> in complicated ways.
>
> Now I just get the ID then run everything inside
>
> namespace eval $tabID {}
>
> and everything just works with much simpler syntax and all the context
> separation I always meant in the first place. Even that thread thing
> is working with simpler code.

You've simply created a "poor man's object".

I.e., you've recreated "objects" from the existing primitives, but
without some of the niceties that tcloo provides for objects.

Each tab has a backing 'object' and that 'object' holds all the state
data for the tab (which is one of the benefits of objects, easier
'separation of concerns' like this).

Re: can't create namespace variable that refers to procedure variable

<unkc7s$25957$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13129&group=comp.lang.tcl#13129

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: can't create namespace variable that refers to procedure variable
Date: Tue, 9 Jan 2024 13:01:46 -0800
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <unkc7s$25957$1@dont-email.me>
References: <20240108151159.0bff5ffe@lud1.home> <unhtb5$1mo4j$1@dont-email.me>
<20240108203533.3171b9f7@lud1.home> <uni8o6$1o2t6$1@dont-email.me>
<20240109024931.4d3055e6@lud1.home> <unk98e$24p6t$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 9 Jan 2024 21:01:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0a95b34333111544b59f7698d89d0882";
logging-data="2270375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qByEHul4cOv6XZINA7Zl0"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:nR0ua8TeBMAwva9XeIGqwe6V4nc=
Content-Language: en-US
In-Reply-To: <unk98e$24p6t$1@dont-email.me>
 by: et99 - Tue, 9 Jan 2024 21:01 UTC

On 1/9/2024 12:10 PM, Rich wrote:
> Luc <luc@sep.invalid> wrote:
>> On Tue, 9 Jan 2024 01:49:58 -0000 (UTC), Rich wrote:
>>
>>> No, because it is defined as linking namespace variables into the
>>> current proc as locals for that proc.
>>
>>
>> OK. Though still weird that someone might prefer
>>
>> namespace upvar ns var localvar
>> set localvar 125
>>
>> to a much simpler
>>
>> set ns::var 125
>>
>>
>> Anyway, I wish I had used namespaces sooner. I spent so much time
>> worrying about keeping track of the tabs, like
>>
>> set tabID [dict get $::FlowControl ActiveTabID]
>>
>> then using tons of [dict get] here and there to access multiple values
>> in complicated ways.
>>
>> Now I just get the ID then run everything inside
>>
>> namespace eval $tabID {}
>>
>> and everything just works with much simpler syntax and all the context
>> separation I always meant in the first place. Even that thread thing
>> is working with simpler code.
>
> You've simply created a "poor man's object".
>
> I.e., you've recreated "objects" from the existing primitives, but
> without some of the niceties that tcloo provides for objects.
>
> Each tab has a backing 'object' and that 'object' holds all the state
> data for the tab (which is one of the benefits of objects, easier
> 'separation of concerns' like this).

Ashok's book has a very good introduction to tclOO. An online draft chapter can be found here:

https://www.magicsplat.com/articles/oo.html

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor