Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #215: High nuclear activity in your area.


comp / comp.lang.tcl / Re: support for built-in -opt style options for proc

SubjectAuthor
* support for built-in -opt style options for procMark Summerfield
+* Re: support for built-in -opt style options for procGerald Lester
|`* Re: support for built-in -opt style options for procMark Summerfield
| +- Re: support for built-in -opt style options for procHarald Oehlmann
| `* Re: support for built-in -opt style options for procet99
|  `* Re: support for built-in -opt style options for procRich
|   +* Re: support for built-in -opt style options for procet99
|   |+- Re: support for built-in -opt style options for procted@loft.tnolan.com (Ted Nolan
|   |`- Re: support for built-in -opt style options for procRich
|   `* Re: support for built-in -opt style options for procMark Summerfield
|    `* Re: support for built-in -opt style options for procRich
|     `- Re: support for built-in -opt style options for procMark Summerfield
+* Re: support for built-in -opt style options for procet99
|`* Re: support for built-in -opt style options for procet99
| `- Re: support for built-in -opt style options for procet99
+- Re: support for built-in -opt style options for procScott Pitcher
`* Re: support for built-in -opt style options for procChristian Gollwitzer
 +- Re: support for built-in -opt style options for procHarald Oehlmann
 `* Re: support for built-in -opt style options for procHarald Oehlmann
  `* Re: support for built-in -opt style options for procMark Summerfield
   +- Re: support for built-in -opt style options for procHarald Oehlmann
   `- Re: support for built-in -opt style options for procAndreas Leitgeb

1
Subject: support for built-in -opt style options for proc
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Mon, 24 Jun 2024 08:11 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 24 Jun 2024 08:11:18 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: support for built-in -opt style options for proc
Newsgroups: comp.lang.tcl
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
Date: Mon, 24 Jun 2024 08:11:18 +0000
Lines: 11
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-zNcmgol53JaZxeKKM9PpQebLNVnBojWBY2BG3TgRCh/v3BAe/kf0SpCHk8SxthMPhB4MhI6K5g8BrN7!yG+pDH8U1P9pGDCsqxX7bZ5Ajm76Q0l6FHJck8Ln8R1ZScATORY3uwGguUB3SnxXx/Ed5OAqddux!fxDcXqdTv9WKfoRlCZHhgRugHw==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

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.

Subject: Re: support for built-in -opt style options for proc
From: Gerald Lester
Newsgroups: comp.lang.tcl
Organization: fastusenet - www.fastusenet.org
Date: Mon, 24 Jun 2024 13:13 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!nntp.terraraq.uk!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: support for built-in -opt style options for proc
Newsgroups: comp.lang.tcl
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
Content-Language: en-US
From: Gerald.Lester@gmail.com (Gerald Lester)
In-Reply-To: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 15
Message-ID: <FheeO.155841$eX68.67721@fx18.iad>
X-Complaints-To: abuse@fastusenet.org
NNTP-Posting-Date: Mon, 24 Jun 2024 13:13:09 UTC
Organization: fastusenet - www.fastusenet.org
Date: Mon, 24 Jun 2024 08:13:09 -0500
X-Received-Bytes: 1287
View all headers

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

Subject: Re: support for built-in -opt style options for proc
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 19:49 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Mon, 24 Jun 2024 12:49:01 -0700
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <v5cijd$135c0$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: Mon, 24 Jun 2024 21:49:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cba25b13d3f809f3186ba2ca9015f260";
logging-data="1152384"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GQSl/EovONcYBTeLIN4RB"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:6kkGRBGXGFPdcOdr5lj8dW3clB0=
Content-Language: en-US
In-Reply-To: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
View all headers

On 6/24/2024 1:11 AM, 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.

You can use an argument processor or if you just want an ad-hoc parser, something like this (partially written by chatGPT):

proc parseit {args} {
puts "\nargs= |$args| "
lassign {. true } parent modal ;# set default values
while {1} {
set args [lassign $args option value] ;# peel off 2 args and shift rest back to args
if { [string index $option 0] ne "-" } {
if { $value ne "" } {
error "too many arguments, should be: ?-parent .? ?-modal true? window"
}
set window $option ;# not an option, so must be the window
break
}
# allow abbreviations
switch -glob $option {
-par* { set parent $value }
-mod* { set modal $value }
default { error "Invalid option: $option" }

}
if { $value eq "" } {
error "missing value for argument $option"
}

puts "option= |$option| value= |$value| "
}

# ... validate options and required window argument here ...

if { $window eq "" } {
error "missing window argument"
} elseif { [string index $window 0] ne "." } {
error "window must begin with a ."
}


puts "parent= |$parent| modal= |$modal| window= |$window| "
}

parseit -par .par .window
parseit .justwindow
parseit -mod false .mywindow
parseit -mod 0 -par .parent .thewindow

output:

args= |-par .par .window|
option= |-par| value= |.par|
parent= |.par| modal= |true| window= |.window|

args= |.justwindow|
parent= |.| modal= |true| window= |.justwindow|

args= |-mod false .mywindow|
option= |-mod| value= |false|
parent= |.| modal= |false| window= |.mywindow|

args= |-mod 0 -par .parent .thewindow|
option= |-mod| value= |0|
option= |-par| value= |.parent|
parent= |.parent| modal= |0| window= |.thewindow|

Subject: Re: support for built-in -opt style options for proc
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 21:02 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Mon, 24 Jun 2024 14:02:36 -0700
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <v5cmtc$146ls$1@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<v5cijd$135c0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 23:02:37 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cba25b13d3f809f3186ba2ca9015f260";
logging-data="1186492"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19s/hrIW0vXXxCJWqKxfXnw"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:rh0LibczkjtzQDdNAVC7fsPMdRk=
Content-Language: en-US
In-Reply-To: <v5cijd$135c0$1@dont-email.me>
View all headers

On 6/24/2024 12:49 PM, et99 wrote:
snip
>
> You can use an argument processor or if you just want an ad-hoc parser, something like this (partially written by chatGPT):
>

For fun, I just tried it this way with chatGPT (before I was too wordy):

"can you write a tcl procedure that processes variable arguments of the standard form with: ?-parent .? ?-modal true? window"

And got this which worked first time, but doesn't do the defaults or any error checking:

proc processArgs {args} {
# Default values
set parent ""
set modal false
set window ""

# Parse the arguments
while {[llength $args] > 0} {
switch -- [lindex $args 0] {
-parent {
set parent [lindex $args 1]
set args [lrange $args 2 end]
}
-modal {
set modal [string equal -nocase [lindex $args 1] "true"]
set args [lrange $args 2 end]
}
default {
set window [lindex $args 0]
set args [lrange $args 1 end]
}
}
}

# Print the results (or do whatever processing is needed)
puts "Parent: $parent"
puts "Modal: $modal"
puts "Window: $window"
}

# Example usage
processArgs -parent . -modal true myWindow
processArgs -modal false myWindow
processArgs myWindow

Subject: Re: support for built-in -opt style options for proc
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 21:06 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Mon, 24 Jun 2024 14:06:12 -0700
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <v5cn44$146ls$2@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<v5cijd$135c0$1@dont-email.me> <v5cmtc$146ls$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 23:06:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cba25b13d3f809f3186ba2ca9015f260";
logging-data="1186492"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Mk2QPN6/3GRlYpH5ayAts"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:1Q+Xsu7PHazBUcHdCwklj0s0Y2w=
In-Reply-To: <v5cmtc$146ls$1@dont-email.me>
Content-Language: en-US
View all headers

On 6/24/2024 2:02 PM, et99 wrote:
> 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:

Actually I just noticed it does do the defaults but gets them wrong. However, easy to fix.

Subject: Re: support for built-in -opt style options for proc
From: Scott Pitcher
Newsgroups: comp.lang.tcl
Organization: SVP TECHNICAL SERVICES
Date: Mon, 24 Jun 2024 23:56 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: scotty@svptechnicalservices.com.au (Scott Pitcher)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 09:56:31 +1000
Organization: SVP TECHNICAL SERVICES
Lines: 142
Message-ID: <20240625095603.266e83c2@officepc>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Jun 2024 01:56:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7ebf253f52f30212db79b3f32b2f011e";
logging-data="1239945"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XGIiN05OOEo7OU59Tkidv1YhRwf8y2yU="
Cancel-Lock: sha1:ny9RIIGLScjaqOZe1Vd4vvRT6Yo=
X-Newsreader: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu)
View all headers

On Mon, 24 Jun 2024 08:11:18 +0000
Mark Summerfield <mark@qtrac.eu> 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.

With Tcl you can do quite good option and argument processing inline
with no dependencies.

If you have a single option you can do something like this.

# Takes a single binary option "-big"
proc name {arg1 arg2 {opt ""}} {
set opts(-big) 0
if {$opt == "-big"} {
set $opts($opt) 1
} elseif {$opt != ""} {
error "name: unknown option \"$opt\""
}

...
if {$opts(-big)} {
# Some special activity when big
...
}
}

To handle multiple options both binary and with arguments:

# Takes several options
proc name {args} {
set opts(-big) 0
set opts(-small) 0
set opts(-filename) ""
set opts(-title) ""

while {[llength $args] > 0} {
set args [lassign $args opt]
switch -glob -- $opt {
-filename - -title {
# Handle any option with argument
set args [lassign $args param]
set opts($opt) $param
}
-big - -small {
# Handle any binary option.
set opts($opt) 1
}
-* {
error "name: unknown option \"$opt\""
}
default {
error "name: unknown argument \"$opt\""
}
}
}

# Check arguments here.
if {$opts(-big) == 0 && $opts(-small)} {
# Must be medium ....
}
.....
}

To handle one or more arguments (non options in other words) you can
either add them as fixed arguments to the function -

proc name {arg1 arg2 args} ....

Or, you can add argument processing to the option processor. This is
more useful when you may have a variable number of arguments -

proc name {args} {
set opts(n) 0 ; # Count of non option arguments
set opts(-big) 0
....

while {[llength $args] > 0} {
set args [lassign $args opt]
switch -glob -- $opt {
....
-* {
error "name: unknown option \"$opt\""
}
default {
set opts([incr opts(n)]) $opt
}
}
}

# Check arguments here.
if {$opts(n) == 1} {
# Special case with only single argument
} elseif {$opts(n) == 2} {
# Special case with two arguments
} else {
error "name: invalid arguments, must be name arg1 \[arg2\]
?options?"
}
.....
}

Or -

proc name {args} {
....
# Check arguments here.
if {$opts(n) != 3} {
error "name: invalid arguments, must be name arg1 arg2 arg3
?options?"
}
.....
}

You can also leave out the defaults and check for the existence of
an opt(...) variable.

By using an opts array I can share it where necessary. I've taken to
calling the global application arguments, those passed to the program,
"Opts" and making that a variable or global to be accessed by other
parts of the code. They are global options after all.

It was designed to be inline and have no dependencies, and be simple
enough to handle special cases e.g. sometimes I need to collect
arguments and lappend them to a list. It also handles short options
with an OptsMap array mapping short to long, but I won't go into that.

Kind regards,
Scott

--

Subject: Re: support for built-in -opt style options for proc
From: Christian Gollwitzer
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 06:14 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
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>
View all headers

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

Subject: Re: support for built-in -opt style options for proc
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 07:01 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 09:01:20 +0200
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <v5dpvv$1ecjj$1@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<v5dn8v$1e3fd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 09:01:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b24cd5d786704820dd35efc7fd9bdba0";
logging-data="1520243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/w10LAolwU4rF5l09GRiCE"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:hkoNLeaWvJsvLN7BjKJFrokHtwM=
In-Reply-To: <v5dn8v$1e3fd$1@dont-email.me>
Content-Language: en-GB
View all headers

Am 25.06.2024 um 08:14 schrieb Christian Gollwitzer:
> 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
>

Great solution, Christian, I appreciate. I use that often, but the "dict
size" trick is great.

dialog::prepare ?-parent .? ?-modal true? window

What magic Christian writes about "to the reader", withoput error checking:

set window [lindex $args end]
set args [lrange $args 0 end-1]

Thanks,
Harald

Subject: Re: support for built-in -opt style options for proc
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Tue, 25 Jun 2024 07:01 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-4.nntp.ord.giganews.com!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 25 Jun 2024 07:01:31 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: support for built-in -opt style options for proc
Newsgroups: comp.lang.tcl
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<FheeO.155841$eX68.67721@fx18.iad>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk>
Date: Tue, 25 Jun 2024 07:01:31 +0000
Lines: 24
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-jp6rywdJmnE+tDFNHEvgbU/jLv+xjol2vIvZPXLQg5LY0AmQjngi32eK4dNuCfuL6GvbwGk1xj6lCGg!wKpvyC+2oKkxh19fMvFlPpdxmrC/ZydWEiLZfIv1xakmth2ZdLqeRCd7thbLkZLRGQHEVHZ+1e32!oikRo3tLbX0A6M7mQJtJ6fSO/g==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

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.

Subject: Re: support for built-in -opt style options for proc
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 07:05 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 09:05:02 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <v5dq6u$1ecjj$2@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<v5dn8v$1e3fd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 09:05:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b24cd5d786704820dd35efc7fd9bdba0";
logging-data="1520243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H7jGXTkOuQ3qrgK9zgT4o"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:RA1qaa41PfFvCYhWCT3uZSJpNIc=
In-Reply-To: <v5dn8v$1e3fd$1@dont-email.me>
Content-Language: en-GB
View all headers

Am 25.06.2024 um 08:14 schrieb Christian Gollwitzer:
> 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
>

Yes, TIP 457 was one of the dark ages of the TCL community with the
"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

Subject: Re: support for built-in -opt style options for proc
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 07:11 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 09:11:56 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <v5dqjr$1ecjj$3@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<FheeO.155841$eX68.67721@fx18.iad>
<eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@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 09:11:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b24cd5d786704820dd35efc7fd9bdba0";
logging-data="1520243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IAap2tWE5mX4V7A2swMas"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:u23ymxM8FNrf4NSf1R9+blXjhmo=
In-Reply-To: <eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk>
Content-Language: en-GB
View all headers

Am 25.06.2024 um 09:01 schrieb Mark Summerfield:
> 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.

Yes, see my comment on the TIP which may bring us this functionality.
All is practically there, but we frightened the people...

Sorry,
Harald

Subject: Re: support for built-in -opt style options for proc
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Tue, 25 Jun 2024 07:23 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 25 Jun 2024 07:23:59 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: support for built-in -opt style options for proc
Newsgroups: comp.lang.tcl
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<v5dn8v$1e3fd$1@dont-email.me> <v5dq6u$1ecjj$2@dont-email.me>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <7QCdnYCwDJUS7ef7nZ2dnZfqnPGdnZ2d@brightview.co.uk>
Date: Tue, 25 Jun 2024 07:23:59 +0000
Lines: 23
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-ubQQ/gsCXncMCb/NEd6kNmeQIZrnOcEQqu08AcCta1W3RnBrnjoJKQPlVPtbb1awl31EahkKNpDdjNG!tNCaIbfvAo69DD08D52eBT5V+875bTjffGEat6GRgF+VielAqP3KpSEOSS8A3FD8OKd+pXWhCMgI!OFJGycM9WvcrQ7wihxzP7TiN1g==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

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 Tcl
>> around the discussion of TIP 457
>> https://core.tcl-lang.org/tips/doc/trunk/tip/457.md
>>
>>     Christian
>>
>>
> Yes, TIP 457 was one of the dark ages of the TCL community with the
> "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?

Subject: Re: support for built-in -opt style options for proc
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 07:26 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 09:26:21 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <v5dret$1ecjj$4@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<v5dn8v$1e3fd$1@dont-email.me> <v5dq6u$1ecjj$2@dont-email.me>
<7QCdnYCwDJUS7ef7nZ2dnZfqnPGdnZ2d@brightview.co.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 09:26:21 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b24cd5d786704820dd35efc7fd9bdba0";
logging-data="1520243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H6lCTq5WeVpL2GkUfVtOE"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:C7JPYftB2Ycr60Gmg1Vxkbco/jE=
Content-Language: en-GB
In-Reply-To: <7QCdnYCwDJUS7ef7nZ2dnZfqnPGdnZ2d@brightview.co.uk>
View all headers

Am 25.06.2024 um 09:23 schrieb Mark Summerfield:
> 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 Tcl
>>> around the discussion of TIP 457
>>> https://core.tcl-lang.org/tips/doc/trunk/tip/457.md
>>>
>>>     Christian
>>>
>>>
>> Yes, TIP 457 was one of the dark ages of the TCL community with the
>> "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?

I have no idea, sorry... If someone would try it, the battle will
restart, so I don't think, this will work... TCL community is very very
difficult...

Take care,
Harald

Subject: Re: support for built-in -opt style options for proc
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 15:21 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 08:21:27 -0700
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <v5en9n$1jqp3$1@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<FheeO.155841$eX68.67721@fx18.iad>
<eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@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 17:21:27 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ee7cf873a2cc42fb6db07c0cf7676dba";
logging-data="1698595"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HMl2cpjIV7a8li4w7Otbt"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:sqtm2I9J39M4JFX5stieBENPr0w=
Content-Language: en-US
In-Reply-To: <eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk>
View all headers

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

Subject: Re: support for built-in -opt style options for proc
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 16:20 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 16:20:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <v5eqoj$1kk24$1@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk> <FheeO.155841$eX68.67721@fx18.iad> <eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk> <v5en9n$1jqp3$1@dont-email.me>
Injection-Date: Tue, 25 Jun 2024 18:20:35 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="684fc8bdfef5318ebf79539c1e731936";
logging-data="1724484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tg360KlOcQm/G1M0cIrzj"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:Ql6JWUugkUNOTCZJZ8JCRZXksDY=
View all headers

et99 <et99@rocketship1.me> wrote:
> 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.

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.

Subject: Re: support for built-in -opt style options for proc
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 21:19 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 14:19:52 -0700
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <v5fc9o$1nlts$1@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<FheeO.155841$eX68.67721@fx18.iad>
<eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk>
<v5en9n$1jqp3$1@dont-email.me> <v5eqoj$1kk24$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Jun 2024 23:19:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ee7cf873a2cc42fb6db07c0cf7676dba";
logging-data="1824700"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0Br0tyJMmbo+hNeAKoLHl"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:LGcpD819eCkSvzVI+Lr6tKm+ydw=
In-Reply-To: <v5eqoj$1kk24$1@dont-email.me>
Content-Language: en-US
View all headers

On 6/25/2024 9:20 AM, Rich wrote:
> et99 <et99@rocketship1.me> 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.

>
> 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.
>

I suggested that one could "parse" a Tcl command spec a-la the manual's standard, because it should be familiar to all Tcl programmers, or at least those that RTM :)

Also it was quite easy to build a working ad-hoc program using chatGPT from just such a spec. If it becomes so complex that it can't do it, then it's likely going to be too complex for humans as well.

Subject: Re: support for built-in -opt style options for proc
From: ted@loft.tnolan.com
Newsgroups: comp.lang.tcl
Organization: loft
Date: Tue, 25 Jun 2024 21:25 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: @ednolan (ted@loft.tnolan.com (Ted Nolan)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: 25 Jun 2024 21:25:47 GMT
Organization: loft
Lines: 27
Message-ID: <le0qurF3hmoU1@mid.individual.net>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk> <v5en9n$1jqp3$1@dont-email.me> <v5eqoj$1kk24$1@dont-email.me> <v5fc9o$1nlts$1@dont-email.me>
X-Trace: individual.net +EJ5LaYppKQmfJl4VuOY+Qqd09tbdPO4+kZ7ozX+AXz//qs0Au
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:nKhDrfmco3PfjWhVmGOy0iwVTss= sha256:35DYCe4ZZZsmvW+la2Biy9yhNYtsy3ooe0fnprfl1iI=
X-Newsreader: trn 4.0-test76 (Apr 2, 2001)
View all headers

In article <v5fc9o$1nlts$1@dont-email.me>, et99 <et99@rocketship1.me> wrote:
>On 6/25/2024 9:20 AM, Rich wrote:
>> et99 <et99@rocketship1.me> 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.
>

Yes. I recently put together a number of Tcl command line programs
using cmdline getopt into one Tcl program, keeping the parsing.

It looked... really weird.

(Love getopt for command line stuff though)
--
columbiaclosings.com
What's not in Columbia anymore..

Subject: Re: support for built-in -opt style options for proc
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 22:21 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Tue, 25 Jun 2024 22:21:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <v5ffso$1oiln$1@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk> <FheeO.155841$eX68.67721@fx18.iad> <eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk> <v5en9n$1jqp3$1@dont-email.me> <v5eqoj$1kk24$1@dont-email.me> <v5fc9o$1nlts$1@dont-email.me>
Injection-Date: Wed, 26 Jun 2024 00:21:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f1f0464a150e143234d52dfb8b591d5a";
logging-data="1854135"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180bmkneoH3W/qY+XHwqyWM"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:wQfujAunfPpNzrUkWTpS6p/m3Ls=
View all headers

et99 <et99@rocketship1.me> wrote:
> On 6/25/2024 9:20 AM, Rich wrote:
>> et99 <et99@rocketship1.me> 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.

That is likely its intent, but one can use it to parse the "args" list
of a proc in the same way one can use it to parse the argv list of CLI
options. Quite a few other tcllib modules use it for their "command
arguments" parsing (all of which are not unix cli commands, but various
Tcl procs).

Subject: Re: support for built-in -opt style options for proc
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Wed, 26 Jun 2024 07:36 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 26 Jun 2024 07:36:19 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: support for built-in -opt style options for proc
Newsgroups: comp.lang.tcl
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<FheeO.155841$eX68.67721@fx18.iad>
<eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk>
<v5en9n$1jqp3$1@dont-email.me> <v5eqoj$1kk24$1@dont-email.me>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <eYecnddfv-BuWeb7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
Date: Wed, 26 Jun 2024 07:36:19 +0000
Lines: 24
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-BxszgZkTgTUBPDWOjjMLETzPr9fP/eQX5cd/VonxC78tJ730IaHU7q4ieCUr/Y9KvRMgZj0wO9jXPEx!5LywE1ax1J/qXdPUVUeImYU8FOXR+pOOJsTgL4MeH1uRWDttQR2qUngxMp1isWq3ipPcv8SWgK/p!G71GumuKA4YFkdsiMC87h0Fj5w==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

In the end I used teapam. For example:

package require tepam

namespace eval dialog {}

tepam::procedure {dialog prepare} {
-named_arguments_first 0
-args {
{-modeless -type none}
{-parent -default .}
{window}
}
} {
wm withdraw $window
wm attributes $window -type dialog
if {!$modeless} { wm transient $window $parent }
}

I also used it for show and hide functions so that 'dialog' is an ensemble
command.

It is a pity the docs lack egs but in the end I found it fairly easy to
use.

Subject: Re: support for built-in -opt style options for proc
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 26 Jun 2024 16:29 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Wed, 26 Jun 2024 16:29:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <v5hflu$279i8$1@dont-email.me>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk> <FheeO.155841$eX68.67721@fx18.iad> <eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk> <v5en9n$1jqp3$1@dont-email.me> <v5eqoj$1kk24$1@dont-email.me> <eYecnddfv-BuWeb7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
Injection-Date: Wed, 26 Jun 2024 18:29:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f1f0464a150e143234d52dfb8b591d5a";
logging-data="2336328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OAtO5n5x4dHPqI4Exrkd2"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:8PO9sH5uQz2I3pJ/IciFk1le6WA=
View all headers

Mark Summerfield <mark@qtrac.eu> 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.

Subject: Re: support for built-in -opt style options for proc
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Thu, 27 Jun 2024 05:36 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 27 Jun 2024 05:36:10 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: support for built-in -opt style options for proc
Newsgroups: comp.lang.tcl
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<FheeO.155841$eX68.67721@fx18.iad>
<eaqdnbi7vrXW9uf7nZ2dnZfqn_WdnZ2d@brightview.co.uk>
<v5en9n$1jqp3$1@dont-email.me> <v5eqoj$1kk24$1@dont-email.me>
<eYecnddfv-BuWeb7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
<v5hflu$279i8$1@dont-email.me>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <utudneW1LKbXZ-H7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
Date: Thu, 27 Jun 2024 05:36:10 +0000
Lines: 13
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-REEhiBH6AKI3APILKOOT1VREmosDnkEvlOgBlJIT57zqPLYgHr4PbEdK356JGriXXKblGNxti/4bnPx!fG1IyQQHIzNoFGob1Yli495nNGrs3RG5rlfmVqj4fSY+kMeCTZpcDjQ1Al0clto5eJvsTDXlD5rB!xY4b/gQc20ZstJvxc1TgVxvV9Q==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

On Wed, 26 Jun 2024 16:29:50 -0000 (UTC), Rich wrote:

> Mark Summerfield <mark@qtrac.eu> 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.

I have often made small contributions to projects on github but I never do
for sourceforge which I don't like.

Subject: Re: support for built-in -opt style options for proc
From: Andreas Leitgeb
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 27 Jun 2024 15:59 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: avl@logic.at (Andreas Leitgeb)
Newsgroups: comp.lang.tcl
Subject: Re: support for built-in -opt style options for proc
Date: Thu, 27 Jun 2024 15:59:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <slrnv7r33r.3gvbf.avl@logic.at>
References: <aF6dnUGPYfu7t-T7nZ2dnZfqnPadnZ2d@brightview.co.uk>
<v5dn8v$1e3fd$1@dont-email.me> <v5dq6u$1ecjj$2@dont-email.me>
<7QCdnYCwDJUS7ef7nZ2dnZfqnPGdnZ2d@brightview.co.uk>
Reply-To: avl@logic.at
Injection-Date: Thu, 27 Jun 2024 17:59:55 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8e74ff785fe80015af8937dfca316e6e";
logging-data="2930263"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UzfslPOsuxGyR1jAuzDg0"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:vTCNao1vopkG/+WJMaFobL6nClc=
View all headers

Mark Summerfield <mark@qtrac.eu> wrote:
> 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?

Not exactly reference code, but you may have a look at my
pure-Tcl implementation of something "rather close to tip457"

https://wiki.tcl-lang.org/page/TclImplForNamedArguments

There are a few examples there, but those also cover some corner cases,
so just look for the things you may actually need.

1

rocksolid light 0.9.8
clearnet tor