scripted dict

A scripted dict is a deep dict that is scripted in a manner similar to a scripted list.

See Also

ycl list deep
Provides scripted for the purpose of scripting a deep dict.

Description

Because the structure of deep dict is well-defined, it can be scripted. That is, each value can be transformed in the same way that a word in a command is transformed.

Example

Because a deep dict is also a deep list, the scripting routine comes from ycl list deep. Then the result is displayed as a deep dict using ycl dict deep pretty

#! /usr/bin/env tclsh

package require {ycl dict deep}
namespace import [yclprefix]::dict::deep
rename deep ddeep

package require {ycl list deep}
namespace import [yclprefix]::list::deep
rename deep ldeep

set root /path/to/root
set servers {one two three}

set template {
    locations {
        tmp {{$root/var/tmp/$server}}
        pub {{$root/pub}}
        scripts {{$root/scripts}}
    }
}

foreach server $servers {
    set config $template
    ldeep scripted config
    lappend configuration $server $config
}

ddeep pretty configuration indent {    }

return $configuration

output:

one {
    locations {
        tmp /path/to/root/var/tmp/one
        pub /path/to/root/pub
        scripts /path/to/root/scripts
    }
}
two {
    locations {
        tmp /path/to/root/var/tmp/two
        pub /path/to/root/pub
        scripts /path/to/root/scripts
    }
}
three {
    locations {
        tmp /path/to/root/var/tmp/three
        pub /path/to/root/pub
        scripts /path/to/root/scripts
    }
}