template::util::lnest (public)

 template::util::lnest listref value next [ args... ]

Defined in packages/acs-templating/tcl/util-procs.tcl

Recursive procedure for building a hierarchical or multidimensional data structure in a list.

Parameters:
listref (required)
value (required)
Either a list or scalar value to store in the list.
next (required)
A key value that determines the next node to traverse outward in the data structure.

Partial Call Graph (max 5 caller/called nodes):
%3 template::query::nestedlist template::query::nestedlist (private) template::util::lnest template::util::lnest template::query::nestedlist->template::util::lnest

Testcases:
No testcase defined.
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
[ hide source ] | [ make this the default ]
Show another procedure: