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.
You can use an argument processor or if you just want an ad-hoc parser, something like this (partially written by chatGPT):
On 6/24/2024 12:49 PM, et99 wrote:
And got this which worked first time, but doesn't do the defaults or any error checking:
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.
I want to create a couple of procs with these usages:
dialog::prepare ?-parent .? ?-modal true? window
On 6/24/24 03:11, Mark Summerfield wrote:modules/tepam/tepam_introduction.md
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/
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.
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
Am 24.06.24 um 10:11 schrieb Mark Summerfield:
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
Am 25.06.2024 um 08:14 schrieb Christian Gollwitzer:
There have also been LOTS of advanced implementations in pure TclYes, TIP 457 was one of the dark ages of the TCL community with the
around the discussion of TIP 457
https://core.tcl-lang.org/tips/doc/trunk/tip/457.md
Christian
"debating down" culture. And at the end, we have no solution and a lot
of frustrated people...
I would love, if this gem would make it to the core, but the time of 9.0 release is now passed...
Thank you,
Harald
On Tue, 25 Jun 2024 09:05:02 +0200, Harald Oehlmann wrote:
Am 25.06.2024 um 08:14 schrieb Christian Gollwitzer:
There have also been LOTS of advanced implementations in pure TclYes, TIP 457 was one of the dark ages of the TCL community with the
around the discussion of TIP 457
https://core.tcl-lang.org/tips/doc/trunk/tip/457.md
Christian
"debating down" culture. And at the end, we have no solution and a lot
of frustrated people...
I would love, if this gem would make it to the core, but the time of 9.0
release is now passed...
Thank you,
Harald
Hi Harald,
Is there a stand-alone installable installation of the TIP-457 reference
code that could be added in to my local Tcl/Tk 9.0b2 installation?
On Mon, 24 Jun 2024 08:13:09 -0500, Gerald Lester wrote:
On 6/24/24 03:11, Mark Summerfield wrote:modules/tepam/tepam_introduction.md
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/
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.
On 6/25/2024 12:01 AM, Mark Summerfield wrote:
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.
et99 <[email protected]> wrote:snip
There is also, in tcllib, the 'cmdline' package:
https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/tcllib/files/modules/cmdline/cmdline.md
Which provides an options parser that is very similar (although not
100% identical) to the GNU C 'getopt' options parser. And the man page
has an example.
It looks like a recipe for a unix command line, not so much a tcl command.
et99 <[email protected]> wrote:snip
There is also, in tcllib, the 'cmdline' package:
https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/tcllib/files/modules/cmdline/cmdline.md
Which provides an options parser that is very similar (although not
100% identical) to the GNU C 'getopt' options parser. And the man page
has an example.
Quite a number of other tcllib modules use 'cmdline' for their options parsing, so it is 'reasonably standard' in that sense -- and being very similar to the gnulib C 'getopt' library function makes it much more 'standards like' (assuming one considers C library functions to be 'standard') than most.
On 6/25/2024 9:20 AM, Rich wrote:
et99 <[email protected]> wrote:snip
There is also, in tcllib, the 'cmdline' package:
https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/tcllib/files/modules/cmdline/cmdline.md
Which provides an options parser that is very similar (although not
100% identical) to the GNU C 'getopt' options parser. And the man
page has an example.
It looks like a recipe for a unix command line, not so much a tcl command.
It is a pity the docs lack egs but in the end I found it fairly easy to
use.
Mark Summerfield <[email protected]> wrote:
It is a pity the docs lack egs but in the end I found it fairly easy to
use.
The docs are a collabarative endeavor. Contribute an example as a patch
and it will likely be included. Then you've helped the next person who
comes along looking for examples.
Is there a stand-alone installable installation of the TIP-457 reference
code that could be added in to my local Tcl/Tk 9.0b2 installation?
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 20:10:41 |
| Calls: | 12,104 |
| Calls today: | 4 |
| Files: | 15,004 |
| Messages: | 6,518,100 |