Re: support for built-in -opt style options for proc

Liste des GroupesRevenir à cl tcl 
Sujet : Re: support for built-in -opt style options for proc
De : auriocus (at) *nospam* gmx.de (Christian Gollwitzer)
Groupes : comp.lang.tcl
Date : 25. Jun 2024, 07:14:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5dn8v$1e3fd$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
Am 24.06.24 um 10:11 schrieb Mark Summerfield:
I want to create a couple of procs with these usages:
 dialog::prepare ?-parent .? ?-modal true? window
 
Here is another very simple argument parser: Use "dict merge".
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

Date Sujet#  Auteur
24 Jun 24 * support for built-in -opt style options for proc21Mark Summerfield
24 Jun 24 +* Re: support for built-in -opt style options for proc3et99
24 Jun 24 i`* Re: support for built-in -opt style options for proc2et99
24 Jun 24 i `- Re: support for built-in -opt style options for proc1et99
25 Jun 24 +- Re: support for built-in -opt style options for proc1Scott Pitcher
25 Jun 24 +* Re: support for built-in -opt style options for proc6Christian Gollwitzer
25 Jun 24 i+- Re: support for built-in -opt style options for proc1Harald Oehlmann
25 Jun 24 i`* Re: support for built-in -opt style options for proc4Harald Oehlmann
25 Jun 24 i `* Re: support for built-in -opt style options for proc3Mark Summerfield
25 Jun 24 i  +- Re: support for built-in -opt style options for proc1Harald Oehlmann
27 Jun 24 i  `- Re: support for built-in -opt style options for proc1Andreas Leitgeb
25 Jun 24 `* Re: support for built-in -opt style options for proc10Mark Summerfield
25 Jun 24  +- Re: support for built-in -opt style options for proc1Harald Oehlmann
25 Jun 24  `* Re: support for built-in -opt style options for proc8et99
25 Jun 24   `* Re: support for built-in -opt style options for proc7Rich
25 Jun 24    +* Re: support for built-in -opt style options for proc3et99
25 Jun 24    i+- Re: support for built-in -opt style options for proc1ted@loft.tnolan.com (Ted Nolan
25 Jun 24    i`- Re: support for built-in -opt style options for proc1Rich
26 Jun 24    `* Re: support for built-in -opt style options for proc3Mark Summerfield
26 Jun 24     `* Re: support for built-in -opt style options for proc2Rich
27 Jun 24      `- Re: support for built-in -opt style options for proc1Mark Summerfield

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal