Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 25f2c8680a65e732448e1c74d985eb9993d98196
Ticket: 871387ffffffffffffffffffffffffffffffffff
dict exists throws unexpected error
User & Date: mic42 on 2004-01-06 02:22:24
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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
    
    
    
    
    
    
    
  4. foundin changed to: "obsolete: 8.5a0"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "mic42"
  9. subsystem changed to: "15. Dict Object"
  10. title changed to: "dict exists throws unexpected error"
  11. type changed to: "Bug"