From: Andreas K. <and...@ac...> - 2011-05-13 17:03:53
|
On 5/13/2011 12:54 AM, Lars Hellström wrote: > Andreas Kupries skrev 2011-05-13 00.08: > Besides the command name (which is nice), does this have the same syntax > as TIP#342 (http://www.tcl.tk/cgi-bin/tct/tip/342)? > > Lars Hellström Checking ... Yes. My implementation is pretty much the same as well, just an additional local variable to avoid doing the lrange twice, and explicit returns. # get value for key, with custom default if key not present. proc ::dictutil::get' {dict args} { set keys [lrange $args 0 end-1] if {[dict exists $dict {*}$keys]} { return [dict get $dict {*}$keys] } else { return [lindex $args end] } } The WUB Dict.tcl has a simimlar 'get?' method, except that it doesn't have a custom default, and always returns the empty string. Thanks to all the responses, keep them coming, in the ooutil thread too, I hope. For me, time to start digesting things ... -- Andreas Kupries Senior Tcl Developer ActiveState, The Dynamic Language Experts P: 778.786.1122 F: 778.786.1133 and...@ac... http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog |