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 : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tcl
Date : 25. Jun 2024, 16:21:27
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5en9n$1jqp3$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1
On 6/25/2024 12:01 AM, Mark Summerfield wrote:
On Mon, 24 Jun 2024 08:13:09 -0500, Gerald Lester wrote:
 
On 6/24/24 03:11, Mark Summerfield wrote:
I want to create a couple of procs with these usages:
>
dialog::prepare ?-parent .? ?-modal true? window
>
I can't use the parse_args package because I don't know how to install
it (and it has no INSTALL doc)
>
I can see from the wiki that there seems to be a lot of different pure
Tcl solutions, so I don't know which one to choose.
>
I'm using Tcl/Tk 9.0b2.
>
Look first to TclLib --
https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/tcllib/files/
modules/tepam/tepam_introduction.md
 I had peeked at that but was put off by there being no 'examples' section.
I'll have another look at it.
 Thanks also to the other repliers, but I want something 'standards' rather
than ad hoc. I do find it surprising that it isn't part of Tcl itself.
I too looked at tepam and also TIP 457 but found both to be impenetrable without some serious study, of which I was not motivated to expend. Maybe if Ashok were to write a chapter with his ability to simplify esp. with good examples.
However, it seems to me that a somewhat simple solution for a "standard" might be a proc say, called processArgs and hand it an argument spec similar to what was given in the first posting, then it could parse the spec, in the manner of say, YACC with a bnf spec. Using [uplevel] it could create variables in the proc.
So, for example, given:
     dialog::prepare ?-parent .? ?-modal true? window
We have our proc,
     proc processArgs {args} {...}
So, here args in this case might begin as:
     ?-parent window? ?-modal boolean? window window
Then to make it easy for processArgs itself, add braces or quotes
     processArgs {?-parent window?} {?-modal boolean?} "window window"
And to add default values for the optional arguments use =,
     processArgs {?-parent window=.?} {?-modal boolean=true?} "window window"
And by using a [foreach] and [uplevel] with some simple parsing, processArgs would in this case produce the 3 variables, parent, modal, and window in the context of the calling procedure, like so:
proc dialog::prepare {args} {
     processArgs {?-parent window=.?} {?-modal boolean=true?} "window window"
     ...
}
It could use () and ... to indicate some repeating arguments, where the result would be an array variable, with the (0) to indicate a required first argument, and () for all the optional ones to follow.
      "window(0) window" "?window() window...?"
And support the obvious types: integer, text, window, boolean, real. Maybe some others.
Simple on/off options with no value, that default to off if not used, like
     ?-optionOnly?
And resist the temptation to make this too much more complicated.
The fatal flaw I always see when beginning with something simple like this, and thinking maybe I'll write up a TIP is that after the Tcl community begins to warm up to the proposal, it grows and grows as people add their requests for their favorite features until it becomes a monster with so many options that it becomes impenetrable once again.
Often it takes a single dedicated person to create an elegant solution and just build it without input from dozens of others. But that doesn't seem to be the way of Tcl.
-et

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