Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2004-01-15
05:10 • Ticket [871387ffff] dict exists throws unexpected error status still Closed ... artifact: cd4caae548 user: dkf
05:10 • Add attachment dict.patch to ticket [871387ffff] artifact: 5a94ba4f1c user: dkf
05:10 • Closed ticket [871387ffff]: dict exists throws unexpected error plus 7 other... artifact: 671afd5f4d user: dkf
04:13 • Ticket [871387ffff]: 4 changes artifact: f0a6aa9fba user: dkf
2004-01-06
02:22 • New ticket [871387ffff]. artifact: 25f2c8680a user: mic42

dict exists throws unexpected error

Closed / Fixed871387ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2004-01-06 02:22:24
The dict exists subcommand shows a behaviour that is
not clearly documented but unexpected, so either this
is a documentation bug or a misfeature/real bug.

I tried to update msgcat.tcl to dicts and stumbled
accross the following:

set Msgs [dict create]
# create a subdict for a locale
dict set Msgs de [dict create]
# create a subdict for a namespace
dict set Msgs de "" [dict create]
# create an entry there
dict set Msgs de "" hello Hallo

# check if a translation exists
dict exists $Msgs fr "" hello

This throws an error if the subdict fr and fr "" does
not exist. I would expect it to simply return 0. 

It would be better if it simply returned 0, as there is
no good (and fast) workaround.

The only alternatives are:

set ok 0
set path ""
foreach key {fr "" hello} {
   lappend path $key 
   if {[dict exists $Msgs {expand}$path]} {
        set ok 1
   } else {
        break
   }
}

or:

if {[catch {dict exists $Msgs fr "" hello} val]} { ... }

As i think a check for element existance is a common
operation it should not need such complex workarounds
to be useful for nested dicts.

The current behaviour would be more appropriate for
something like a dict exists -strict command variant.

Michael
dkfplain2004-01-15 04:13:52
Logged In: YES 
user_id=79902

Hmm.  Is it a bug or a misfeature?  I've a test (dict-9.5)
checking for exactly this behaviour...

Review of documentation indicates bug.  :^/
dkfplain2004-01-15 05:10:42
Logged In: YES 
user_id=79902

I attach the patch I used to fix the fault.
dkfplain2004-01-15 05:10:43
File Added - 73469: dict.patch
Log in (anonymous is fine) to add a comment.

Attachments: