Deutsch English Français Italiano |
<v5dn8v$1e3fd$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Christian Gollwitzer <auriocus@gmx.de> Newsgroups: comp.lang.tcl Subject: Re: support for built-in -opt style options for proc Date: Tue, 25 Jun 2024 08:14:55 +0200 Organization: A noiseless patient Spider Lines: 29 Message-ID: <v5dn8v$1e3fd$1@dont-email.me> References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 25 Jun 2024 08:14:56 +0200 (CEST) Injection-Info: dont-email.me; posting-host="284a6f9efc4a31593a83dd6c55522a7a"; logging-data="1510893"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tqllGQBlWs/Yd4xkagJxU1/YjMIehD6A=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:EkNdCm/f24pRYeSDUi8q2yLmJDI= In-Reply-To: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk> Bytes: 2082 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