| Store | Cart

Re: [TCLCORE] TIP 457: [eatargs] vs [proc] extensions; A third way?

From: Florent Merlet <post...@florentmerlet.com>
Sun, 18 Jun 2017 11:40:45 +0200

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
Recent Messages in this Thread
Florent Merlet Jun 05, 2017 09:36 am
Mathieu Lafon Jun 10, 2017 10:15 am
Brad Lanam Jun 10, 2017 01:22 pm
Peter da Silva Jun 12, 2017 11:49 am
Mathieu Lafon Jun 13, 2017 07:41 pm
Peter da Silva Jun 13, 2017 07:55 pm
Mathieu Lafon Jun 13, 2017 08:25 pm
Peter da Silva Jun 13, 2017 08:33 pm
Kevin Kenny Jun 13, 2017 08:46 pm
Peter da Silva Jun 13, 2017 08:55 pm
Colin McCormack Jun 14, 2017 02:09 am
Martin Lemburg Jun 14, 2017 12:35 pm
Venks Izod Jun 14, 2017 09:44 pm
Florent Merlet Jun 18, 2017 09:40 am
fred...@free.fr May 26, 2017 12:56 pm
Peter da Silva May 26, 2017 01:05 pm
Messages in this thread