Version 0 of scripted dict

Updated 2019-10-14 20:41:34 by pooryorick

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

See Also

ycl deep dict
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

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

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
    deep scripted config
    lappend configuration $server $config
}

deep pretty configuration indent {    }
puts $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
    }
}