I have viewed TIP#457 [L1 ] and disussions with an eye towards keeping faith with the Tao of Tcl. I've thought about this general issue, and spurred by Cyan Ogilvie's paper, I have come up with the following proposal. I think this proposal is forward compatible with existing scripts and provides for the requirements for: built-in argument pre-parsing, named parameters -ish, and passing by reference or passing arrays or call by name (obviate upvar).
I'm putting this out for discussion. I am not intending to file a TIP since I do not have an implementation nor will be attempting one. The work here might even be best handled by multiple TIP's.
Expand proc arglist definition to accept additional specification details for arguments. Each argument specifier list can be expanded to have additional fields. All additional fields are optional.
argname -- name of argument variable. default -- Default value if actual is not specified. optionname -- "flag" name used when specifying argument actual by name argtype -- Type definition argclass -- Name to be used for possible db lookup, or validation, or ... flags -- Examples: NULL_OK, REQUIRED, etc. help -- Brief textual description of argument
Boolean Int Double String Flag Array List Dict Ref Script
Anchor Bitmap Border Color Cursor Font Justify Pixels Relief Synonym Window
proc test { {f "" -f Font TextFont NULL_OK "Specifies override font (optional)"} } { if {[info exists f]} { puts "Using font $f" } else { puts "Font is NULL" } }
Tcl_CreateObjCommandEx(interp, cmdName, proc, argsList, clientData, deleteProc)
proc find_flightplan_from_position {flightplan() position()} {}
Example proc with additional argument details:
proc http::register { {proto "" -protocol "" "" REQUIRED "URL protocol prefix, e.g. https"} {port "" -port Int "" REQUIRED "Default port for protocol"} {command "" -command Script "" REQUIRED "Command to use to create socket"} } { variable urlTypes set urlTypes([string tolower $proto]) [list $port $command] }
bll 2016-11-27 And it would be nice if the option processing/parsing could also be called separately so that command line parameters could be parsed (from argv, from an environment variable, from a configuration file).