Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2004-01-27
16:35 • Closed ticket [883865ffff]: Add ?-nocomplain? switch to dict get plus 8 ot... artifact: 0e0f411a91 user: dkf
2004-01-24
22:40 • New ticket [883865ffff]. artifact: f9e99c889e user: cnassau

Add ?-nocomplain? switch to [dict get]

Closed / Rejected883865ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2004-01-24 22:40:19
Currently TIP 111 declares that

   dict get $dictVal $k1 $k2 ... $kn 

throws an error if $dictVal does not contain a value
for the given key sequence. I would suggest to add a
switch ?-nocomplain? where "dict get" would simply
return an empty string in this case. 

There is a recent related discussion on the dict page
of the Tcl'ers Wiki. There I tried to make the point
that there are legitimate use cases where the
distinction between a non-existing key and a key with
an empty value is deliberately blurred.
dkfplain2004-01-27 16:35:32
Logged In: YES 
user_id=79902

No.  I (and other Core Team members and Core Maintainers)
hate "-nocomplain" options, and there's already a [dict
exists] operation to let you create your idea of defaulting
getter as a composite operation.  For example:
  proc dictgetwithdefault {dict default key args} {
     if {[dict exists $dict $key {expand}$args]} {
        return [dict get $dict $key {expand}$args]
     } else {
        return $default
     }
  }

A separate get-with-default subcommand for [dict] would have
more sympathy from me, but only if there is performance data
to justify doing it.
Log in (anonymous is fine) to add a comment.