template::util::lnest (public)template::util::lnest listref value next [ args... ]
Defined in packages/acs-templating/tcl/util-procs.tclRecursive procedure for building a hierarchical or multidimensional
data structure in a list.
- Parameters:
-
listref
value - Either a list or scalar value to store in the list.
next - A key value that determines the next node to
traverse outward in the data structure.
- Source code:
-
upvar $listref inlist
if { ! [info exists inlist] } {
set inlist [list]
}
# inlist represents the top level of the data structure into which
# we are inserting. We need to turn the list into an array to determine
# which branch to follow next.
array set values $inlist
# next determines the next branch to follow as we look for the proper
# location of the value. if the key is not found, create a new branch by
# adding an empty list to inlist
if { [info exists values($next)] } {
set next_list $values($next)
} else {
set next_list [list]
}
# the number of additional arguments after next determines how many
# more branches or levels we need to traverse before reaching the actual
# insertion point into the data structure.
set remaining [llength $args]
if { $remaining == 0 } {
# we have reached a leaf
lappend next_list $value
} elseif { $remaining == 1 } {
# continue for one more step to the leaf
lnest next_list $value [lindex $args 0]
} else {
# more branches to go. Call the procedure recursively starting with
# the current branch.
lnest next_list $value [lindex $args 0] [lrange $args 1 end]
}
# At this point the branch has been updated. Update the branch in the
# array.
set values($next) $next_list
# Update inlist.
set inlist [array get values]
- XQL Not present:
- Generic, PostgreSQL, Oracle
|