ycl

Artifact [2752f88974]
Login

Artifact [2752f88974]

Artifact 2752f8897433de927aa5a19f49c907d388e66032:


#! /usr/bin/env tclsh


proc get {dictname args} {
	upvar $dictname dict
	::set dict [dict get $dict[::set dict {}] {*}$args]
	if {[llength $dict] == 1} {
		::set dict [lindex $dict 0]
	}
	return
}


proc merge {dictname args} {
	upvar $dictname dict
	foreach arg $args {
		upvar $arg dict2
		# [foreach] retains duplicate keys
		foreach {key val} $dict2[::set dict2 {}] {
			if {[dict exists $dict $key]} {
				if {[llength $val] > 1} {
					::set b $val
					::set val [dict get $dict $key]
					merge val b
				}
			}
			lappend dict $key $val
		}
	}
	return
}


proc set {dictname args} {
	upvar 1 $dictname dict
	::set res [lindex [dict set dict {*}[lrange $args 0 end-1] [
		list [lindex $args end]]] end]
	if {[string is list -strict $res] && [llength $res] == 1} {
		::set res [lindex $res end]
	}
	return $res
}