Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Revision through web from Mathieu Lafon <[email protected]> update named group ending and discussion |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
9efbeccfedf4acb41df2dd0127029a50 |
User & Date: | tclhttpd 2017-05-23 23:59:25.000 |
Context
2017-05-26
| ||
15:03 | Revision through web from Gregor Cramer <[email protected]> Additional tag selection attributes. check-in: a7f1b81f58 user: tclhttpd tags: trunk | |
2017-05-23
| ||
23:59 | Revision through web from Mathieu Lafon <[email protected]> update named group ending and discussion check-in: 9efbeccfed user: tclhttpd tags: trunk | |
2017-05-18
| ||
20:57 | Revision through web from Mathieu Lafon <[email protected]> updates check-in: 4cd6b4bcab user: tclhttpd tags: trunk | |
Changes
Changes to tip/457.tip.
1 2 | TIP: 457 Title: Add Support for Named Arguments | | | 1 2 3 4 5 6 7 8 9 10 | TIP: 457 Title: Add Support for Named Arguments Version: $Revision: 1.22 $ Author: Mathieu Lafon <[email protected]> Author: Andreas Leitgeb <[email protected]> State: Draft Type: Project Vote: Pending Created: 21-Nov-2016 Post-History: |
︙ | ︙ | |||
180 181 182 183 184 185 186 | |% proc p { {a -name A} {b -name B} } { list a $a b $b } |% p -B bb -A aa |% a aa b bb * The handling of a group of contiguous named arguments (which can be only one argument) is ended on the first argument which is either | | < | > > > > > > > > > > | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |% proc p { {a -name A} {b -name B} } { list a $a b $b } |% p -B bb -A aa |% a aa b bb * The handling of a group of contiguous named arguments (which can be only one argument) is ended on the first argument which is either a parameter not starting with a dash or the special ''--'' end-of-options marker. Remaining arguments will then be assigned to following positional arguments. |% proc p { {o -name opt} args } { list o $o args $args } |% p -opt O 5 |o O args 5 |% p -opt O -1 0 |wrong # args: should be "p |-opt o| ?arg ...?" |% p -opt O -- -1 0 |o O args {-1 0} * If there is a fixed number of non-optional positional arguments and no special ''args'' variable after the named group, the handling of a named group will also be ended when the remaining arguments to assign will be equal to the number of positional arguments after the group. |% proc p { {o -name opt} posarg } { list o $o posarg $posarg } |% p -opt O -1 |o O posarg -1 ~~ Generated usage description The error message, automatically generated when the input arguments are invalid, is updated regarding new options: * Pass-by-name arguments (specified using ''-upvar level'' option) are |
︙ | ︙ | |||
250 251 252 253 254 255 256 | * anonymous functions (lambda), used with ''apply'' command ; * TclOO constructor or methods. ~~ Performance | | | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | * anonymous functions (lambda), used with ''apply'' command ; * TclOO constructor or methods. ~~ Performance The proposed modification has no significant performance impact: * existing code (and code not using extended argspec) is not impacted by the change as the current initialisation code is still available and used ; * code using extended argspec ''may'' be impacted because the initialisation code is different and is required to loop on each |
︙ | ︙ | |||
304 305 306 307 308 309 310 | The reference implementation is available in the tip-457 [http://core.tcl.tk/tcl/timeline?r=tip-457] branch. The code is licensed under the BSD license. ~ Discussion | | > | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | The reference implementation is available in the tip-457 [http://core.tcl.tk/tcl/timeline?r=tip-457] branch. The code is licensed under the BSD license. ~ Discussion This section details some of the alternate solutions for this feature or specific comments about it. Initial approaches that tried to work with unmodified procedures are not detailed here for clarity. ~~ Dedicated builtin command A dedicated command can be used to handle the named arguments, using an |
︙ | ︙ | |||
338 339 340 341 342 343 344 | |% proc myproc { varA { optB -default defB -name B } args } { .. } |% myproc a -B b zz This is the currently proposed solution in this TIP. It requires the procedures to be modified but allow additional features. | > > > > > | > | > > > > > > > > > > > > > > > > > > > > > > > > > > | 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |% proc myproc { varA { optB -default defB -name B } args } { .. } |% myproc a -B b zz This is the currently proposed solution in this TIP. It requires the procedures to be modified but allow additional features. Some people have expressed concern about the modification of the ''proc'' command, which is a core command of Tcl. A particular attention has been paid to ensure that existing code will not be impacted and that future usage could be later added by adding new specifiers. ~~ Argument Parsing command Cyan Ogilvie's paper from Tcl2016 [https://www.tcl.tk/community/tcl2016/assets/talk33/parse_args-paper.pdf] describes a C extension to provide core-like argument parsing at speed comparable to ''proc'' argument handling, in a terse and self-documenting way. Alexandre Ferrieux has proposed [http://code.activestate.com/lists/tcl-core/18447/] to use the same argument specifiers than this proposal, but with a dedicated command which can be called from the proc body. This has the advantage to not alter the ''proc'' command and could be located in an extension. Although the ''proc'' usage will not be modified, this new command will probably have to access or modify internal proc structures, for example to support introspection. Having to declare final local variables in the body, also seems confusing for users. ~~ Preventing Data-dependent bugs It has been proposed by Christian Gollwitzer [http://code.activestate.com/lists/tcl-core/18457/] to make the special '--' end-of-options marker mandatory when the number of positional arguments after the named group is not fixed. This would suppress any potential Data-Dependent bugs related to the search of the initial dash and remove any unwanted object stringification, at the expense of forcing the user to explicitely use the end-of-option marker. This proposal is currently not implemented but the documentation has been modified to list the cases for which '--' should be use. ~ Copyright This document has been placed in the public domain. |