Liste des Groupes | Revenir à cl tcl |
Am 24.06.24 um 10:11 schrieb Mark Summerfield:Great solution, Christian, I appreciate. I use that often, but the "dict size" trick is great.I want to create a couple of procs with these usages:Here is another very simple argument parser: Use "dict merge".
>
dialog::prepare ?-parent .? ?-modal true? window
>
proc someprocwithargs {args} {
set defaults {-parent . -modal false}
set options [dict merge $defaults $args]
if {[dict size $options] != [dict size $defaults]} {
return -code error "Unknown option"
}
# now use the stuff in options
}
To extend by a mandatory argument is left as an exercise to the reader, you basically take off the last element from "args". It is advisable to do it this way, i.e. to make the mandatory argument positional, either in the beginning - then you can simple stuff it before "args" - or at the end. This way, an option can not be confused with a positional argument, and no "--" stuff is needed.
There have also been LOTS of advanced implementations in pure Tcl around the discussion of TIP 457 https://core.tcl-lang.org/tips/doc/trunk/tip/457.md
Christian
Les messages affichés proviennent d'usenet.