-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict.tcl
More file actions
58 lines (44 loc) · 1.93 KB
/
Copy pathdict.tcl
File metadata and controls
58 lines (44 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
proc ::tcl::dict::lappend2 {dict args} {
upvar 1 $dict d
if { ![::info exists d] || ![dict exists $d {*}[lrange $args 0 end-1]] } {
dict set d {*}[lrange $args 0 end-1] [list [lindex $args end]]
} else {
::set list [dict get $d {*}[lrange $args 0 end-1]]
::lappend list [lindex $args end]
dict set d {*}[lrange $args 0 end-1] $list
}
}
namespace ensemble configure dict -map [dict merge [namespace ensemble configure dict -map] {lappend2 ::tcl::dict::lappend2}]
proc ::tcl::dict::get? {args} {
try { ::set x [dict get {*}$args]
} on error message { ::set x {} }
return $x
}
namespace ensemble configure dict -map [dict merge [namespace ensemble configure dict -map] {get? ::tcl::dict::get?}]
proc ::tcl::dict::get@ {args} {
try { ::set x [dict get {*}[lrange $args 0 end-1]]
} on error message { ::set x [lindex $args end] }
return $x
}
namespace ensemble configure dict -map [dict merge [namespace ensemble configure dict -map] {get@ ::tcl::dict::get@}]
proc ::tcl::dict::import { dict args } {
if { [llength $args] == 0 } {
upvar $dict D
::set args [dict keys $D]
}
uplevel 1 [list dict update $dict {*}[zip $args $args] {}]
}
namespace ensemble configure dict -map [dict merge [namespace ensemble configure dict -map] {import ::tcl::dict::import}]
proc ::tcl::dict::print {dict {pattern *}} {
set longest [tcl::mathfunc::max 0 {*}[lmap key [dict keys $dict $pattern] {string length $key}]]
dict for {key value} [dict filter $dict key $pattern] {
puts [format "%-${longest}s = %s" $key $value]
}
}
namespace ensemble configure dict -map [dict merge [namespace ensemble configure dict -map] {print ::tcl::dict::print}]
proc ::tcl::dict::subst {dict text} {
dict with $dict {
return subst $text
}
}
namespace ensemble configure dict -map [dict merge [namespace ensemble configure dict -map] {subst ::tcl::dict::subst}]