Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Research is what I'm doing when I don't know what I'm doing. -- Wernher von Braun


devel / comp.lang.tcl / Question to dict set

SubjectAuthor
* Question to dict setgreg
`* Re: Question to dict setRich
 `- Re: Question to dict setgreg

1
Question to dict set

<urcs0p$17dk6$1@dont-email.me>

  copy mid

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

  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: gregor.e...@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Question to dict set
Date: Sat, 24 Feb 2024 14:47:05 +0100
Organization: A noiseless patient Spider
Lines: 135
Message-ID: <urcs0p$17dk6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 24 Feb 2024 13:47:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8f20ff6b2982ebbb4ed73a4c7c25755b";
logging-data="1291910"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vfd6rBXWomD+lthrOQqM1nhezi6fiiPM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:33WinFLiLyd3akXy+Pf0dpONOik=
Content-Language: de-DE, en-US
 by: greg - Sat, 24 Feb 2024 13:47 UTC

I don't understand why the error occurs in my script, or where exactly.

missing value to go with key

Why does an error occur in Scenario 4 when I try to use dict set on a
variable initially defined as a list with the same keys and values I
want to add?
Why does no error occur in Scenario 5 when the initial list contains
different keys and values?
The script;

#! /usr/bin/env tclsh

package require dicttool

puts "info patchlevel [info patchlevel]"
puts "tclplatform(os) $tcl_platform(os)"
puts "tclplatform(osVersion) $tcl_platform(osVersion)"

#1.
puts "\n1. without error different variable names dvar1 and dvar2"
set dvar1 [dict create k1 v1 k2 v2]
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"

dict set dvar2 k3 v3 k4 v4
puts "dvar2: $dvar2 is: [dict is_dict $dvar2]"

#2.
unset dvar1
unset dvar2
puts "\n2. with error same variable name dvar1"
set dvar1 [dict create k1 v1 k2 v2]
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"

catch {dict set dvar1 k3 v3 k4 v4} err
puts "err: $err"
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"

#3.
unset dvar1
unset err
puts "\n3. with error same variable name dvar1 but same keys and values
dict create"
set dvar1 [dict create k1 v1 k2 v2]
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
puts "length dvar1: [llength $dvar1]"
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
set dvar1 [list k1 v1 k2 v2]
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
puts "length dvar1: [llength $dvar1]"

catch {dict set dvar1 k3 v3 k4 v4} err
puts "err: $err"
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"

#4.
unset dvar1
unset err
puts "\n4. with error same variable name dvar1 but same keys and values
dict set"
set dvar1 [dict create k1 v1 k2 v2]
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
puts "length dvar1: [llength $dvar1]"
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
set dvar1 [list k3 v3 k4 v4]
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
puts "length dvar1: [llength $dvar1]"

catch {dict set dvar1 k3 v3 k4 v4} err
puts "err: $err"
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"

#5.
unset dvar1
unset err
puts "\n5. without error same variable name dvar1 but different keys and
values"
set dvar1 [dict create k1 v1 k2 v2]
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
puts "length dvar1: [llength $dvar1]"
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
set dvar1 [list k5 v5 k6 v6]
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"
puts "length dvar1: [llength $dvar1]"

catch {dict set dvar1 k3 v3 k4 v4} err
puts "err: $err"
puts "dvar1: $dvar1 is: [dict is_dict $dvar1]"

if {0} {
output:

info patchlevel 8.6.13
tclplatform(os) Linux
tclplatform(osVersion) 6.6.15-amd64

1. without error different variable names dvar1 and dvar2
dvar1: k1 v1 k2 v2 is: 1
dvar2: k3 {v3 {k4 v4}} is: 1

2. with error same variable name dvar1
dvar1: k1 v1 k2 v2 is: 1
err: k1 v1 k2 v2 k3 {v3 {k4 v4}}
dvar1: k1 v1 k2 v2 k3 {v3 {k4 v4}} is: 1

3. with error same variable name dvar1 but same keys and values dict create
dvar1: k1 v1 k2 v2 is: 1
length dvar1: 4
dvar1: k1 v1 k2 v2 is: 1
dvar1: k1 v1 k2 v2 is: 1
length dvar1: 4
err: k1 v1 k2 v2 k3 {v3 {k4 v4}}
dvar1: k1 v1 k2 v2 k3 {v3 {k4 v4}} is: 1

4. with error same variable name dvar1 but same keys and values dict set
dvar1: k1 v1 k2 v2 is: 1
length dvar1: 4
dvar1: k1 v1 k2 v2 is: 1
dvar1: k3 v3 k4 v4 is: 1
length dvar1: 4
err: missing value to go with key
dvar1: k3 v3 k4 v4 is: 1

5. without error same variable name dvar1 but different keys and values
dvar1: k1 v1 k2 v2 is: 1
length dvar1: 4
dvar1: k1 v1 k2 v2 is: 1
dvar1: k5 v5 k6 v6 is: 1
length dvar1: 4
err: k5 v5 k6 v6 k3 {v3 {k4 v4}}
dvar1: k5 v5 k6 v6 k3 {v3 {k4 v4}} is: 1

}

Re: Question to dict set

<urdmus$1d9q8$1@dont-email.me>

  copy mid

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

  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: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Question to dict set
Date: Sat, 24 Feb 2024 21:26:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <urdmus$1d9q8$1@dont-email.me>
References: <urcs0p$17dk6$1@dont-email.me>
Injection-Date: Sat, 24 Feb 2024 21:26:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9cefb03772d79cd5861bdf003130d424";
logging-data="1484616"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Fg4A/Lp28m8fshTHKDz76"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:rJnvS4YeHr176iSj66Ac4B8wqUE=
 by: Rich - Sat, 24 Feb 2024 21:26 UTC

greg <gregor.ebbing@gmx.de> wrote:
> I don't understand why the error occurs in my script, or where exactly.
>
> missing value to go with key
>
> Why does an error occur in Scenario 4 when I try to use dict set on a
> variable initially defined as a list with the same keys and values I
> want to add?

> #4.
> set dvar1 [list k3 v3 k4 v4]

Creates a list of four elements, which when shimmered to a dict will
produce a dict with two keys (k3, k4) each containing one value (v3,
v4) respectively.

> dict set dvar1 k3 v3 k4 v4

Attempts to set the chain of keys k3->v3->k4 to the value v4. See the
'dict set' subcommand in the dict manpage, the above is not two keys
with two values but a three level nested dict.

When [dict] looks at dvar1, it finds a k3 key at the top level, it then
looks at the value of k3, finds only "v3" (not a dict) and errors out
because "v3" is not a key.

> Why does no error occur in Scenario 5 when the initial list contains
> different keys and values?

> #5.
> set dvar1 [list k5 v5 k6 v6]

Creates a list containing four elements, which when shimmered to a
dict, is a dict with two keys (k5, k6) with one value each (v5, v6).

> dict set dvar1 k3 v3 k4 v4

Attempts to set the chain of nested keys k3->v3->k4 to the value v4.

When [dict] looks at dvar1, it finds no key "k3", so it creates a new
key "k3", then inside "k3" it creates a new nested dict with a key of
"v3", then inside "v3" it creates a new nested dict with a key of "k4"
and a value of "v4". No error because everything created was all new.

Your test key/value names imply that you think that this:

dict set d1 k1 v1 k2 v2

produces this:

{k1 v1} {k2 v2}

When in fact it produces this:

{k1 {v1 {k2 v2}}}

Those two are two very different dicts. One is a flat dict with two
keys, the other is a three level deep hierarchical dict.

Re: Question to dict set

<urelk9$1mrml$1@dont-email.me>

  copy mid

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

  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: gregor.e...@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Re: Question to dict set
Date: Sun, 25 Feb 2024 07:10:16 +0100
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <urelk9$1mrml$1@dont-email.me>
References: <urcs0p$17dk6$1@dont-email.me> <urdmus$1d9q8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 25 Feb 2024 06:10:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2b6a830a51cf070d18c4a59af88211c5";
logging-data="1797845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+C8ZZC7dreWAtae1he39f705CZJq7OJpE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:x+G/HdJQGRabP8qgi3T94uXacHI=
In-Reply-To: <urdmus$1d9q8$1@dont-email.me>
Content-Language: de-DE
 by: greg - Sun, 25 Feb 2024 06:10 UTC

Am 24.02.24 um 22:26 schrieb Rich:
> ..
> When [dict] looks at dvar1, it finds a k3 key at the top level, it then
> looks at the value of k3, finds only "v3" (not a dict) and errors out
> because "v3" is not a key.
>

Ok, now I understand,
thanks
Greg

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor