Le 13/06/2017 à 21:55, Peter da Silva a écrit :
> The current alternate proposals are:> 1. TIP 457> 2. getargs/parseargs/eatargs/somethingargs as a separate command within the proc> 3. TIP 457 plus an encapsulation of the same parsing as a standalone command> 4. The previous proposal a modified proc with 2 arguments, with kind of an “implicit args”> 5. This proposal with 4 arguments, with the extra interstitial argument>> My preference would of course be #1 or #3, but #2 is a far better alternative than either of #4 or #5.Consider, for #4, an « args » command, as an namespace ensemble command.
1 ° kind of argument parsing of proc.
The args command take 3 arguments,
First is the proc name (parameter)
Second is a subcommand
Third is an argument for the subcommand.
It returns the proc name
The proc command then recieve 2 arguments
a) as usal -> subcommand set
proc [args /*MyProc*/ set {
# usual argument parsing
a b c args
}] {
... body ...
}
b) via a script -> subcommand apply
proc [args /*MyProc*/ apply {
# script argument parsing
foreach e $args {
...
}
}] {
... body ...
}
c) via a command -> subcommand eval
proc [args MyProc eval MyParseCmd] {
... body ...
}
2 ° kind of argument parsing of a lambda :
args command take 3 arguments
First is an empty string as parameter
Second is a subcommand
Third is an argument for the subcommand.
It returns an args with a default (third way of frederic bonnet)
a) as usual
apply [list [args {} set {a b c args}] {
... lambda body ...
} /*namespace*/]
-> apply {{a b c args} {... lambda body ...} */namespace}
b) with a script
apply [list [args {} apply {# script to parse}] {
... lambda body ...
} /*namespace*/]
-> apply { {{args {apply {#script}}}} {... lambda body ...} */namespace}
c) with a command
apply [list [args {} eval MyParseCmd] {
... lambda body ...
} /*namespace]
-> apply { {{args {eval MyParseCmd}}} {... lambda body ...} */namespace}
3° As a standalone command :
---------------------------------------
args command takes then 4 arguments or more
args {} subcommand /*SubcommandArg*/ /*valueToBeParsed*/
/*valueToBeParsed*/ ...
Then it assign arguments, in the caller context, beyond the subcommand
specification
4° Finaly, for a coroutine :
proc coro {} {
set args {}
while 1 {
args {} set {a b c args} [yieldto lindex $result]
args {} apply {# script to parse} [yieldto lindex $result]
args {} eval MyParseCmd [yieldto lindex $result]
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
Tcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-core