Re: Best way to set up a dict of defaults?
- From: suchenwi <richard.suchenwirth-bauersachs@xxxxxxxxxxx>
- Date: Tue, 04 Sep 2007 08:01:47 -0700
On 4 Sep., 16:50, Twylite <twylite.cr...@xxxxxxxxx> wrote:
But some of the default values are calculated/derived rather than
static (say based on the name of the application, $argv0). What is
the best way for me to set up these defaults?
I current use list, which is ugly because of line continuation:
set app_path [file dirname $argv0]
set app_base_name [file tail [file rootname $argv0]]
set prefs_defaults [list \
log.file [file join $app_path "data" "${app_base_name}.log"] \
log.level WARN \
]
Subst appears to be a solution, but can trick the unwary:
set prefs_defaults [subst {
log.file [file join $app_path "data" "${app_base_name}.log"]
log.level WARN
}]
Notice that this will work correctly only so long as the resulting
file path contains no spaces, otherwise you will get e.g.
log.file C:/Program Files/MyApp/data/myapp.log
which is 3 elements instead of 2 ;(
Yes - one advantage of [list] is that it braces properly.
Am I missing something obvious; is there a better way?
How about building the list that will become the dict in multiple
steps:
set prefs_defaults {
log.level WARN
foo BAR
} ;# initially: all the simple constant cases
#--- then add those that need variables and commands:
lappend prefs_defaults log.file [file join $app_path "data" "$
{app_base_name}.log"]
...
.
- Follow-Ups:
- Re: Best way to set up a dict of defaults?
- From: Twylite
- Re: Best way to set up a dict of defaults?
- References:
- Best way to set up a dict of defaults?
- From: Twylite
- Best way to set up a dict of defaults?
- Prev by Date: Best way to set up a dict of defaults?
- Next by Date: Re: tcllib: smtp date generation broken?
- Previous by thread: Best way to set up a dict of defaults?
- Next by thread: Re: Best way to set up a dict of defaults?
- Index(es):
Relevant Pages
|