diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2016-06-27 13:46:15 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2016-06-27 13:46:15 (GMT) |
commit | 2d4bd7bd8e4bc730323dccbc6b659954f3d1341c (patch) | |
tree | 9e03a1df62da4ffdb2beaf095fd7112871c1edee | |
parent | 2bd38cb7b01df731a4090c6a0f82d33cec5c2ad3 (diff) | |
download | tcl-2d4bd7bd8e4bc730323dccbc6b659954f3d1341c.zip tcl-2d4bd7bd8e4bc730323dccbc6b659954f3d1341c.tar.gz tcl-2d4bd7bd8e4bc730323dccbc6b659954f3d1341c.tar.bz2 |
[c3d956be5b] Clearer text about positioning of optional arguments.
-rw-r--r-- | doc/proc.n | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -34,8 +34,9 @@ one or two fields. If there is only a single field in the specifier then it is the name of the argument; if there are two fields, then the first is the argument name and the second is its default value. Arguments with default values that are followed by non-defaulted -arguments become required arguments. In 8.6 this will be considered an -error. +arguments become required arguments; enough actual arguments must be +supplied to allow all arguments up to and including the last required +formal argument. .PP When \fIname\fR is invoked a local variable will be created for each of the formal arguments to the procedure; its @@ -48,11 +49,14 @@ actual arguments for all the formal arguments that do not have defaults, and there must not be any extra actual arguments. Arguments with default values that are followed by non-defaulted -arguments become required arguments (in 8.6 it will be considered an -error). +arguments become de-facto required arguments, though this may change +in a future version of Tcl; portable code should ensure that all +optional arguments come after all required arguments. +.PP There is one special case to permit procedures with variable numbers of arguments. If the last formal argument has the name -\fBargs\fR, then a call to the procedure may contain more actual arguments +.QW \fBargs\fR , +then a call to the procedure may contain more actual arguments than the procedure has formal arguments. In this case, all of the actual arguments starting at the one that would be assigned to \fBargs\fR are combined into a list (as if the \fBlist\fR command had been used); this combined value @@ -80,6 +84,20 @@ If an error occurs while executing the procedure body, then the procedure-as-a-whole will return that same error. .SH EXAMPLES .PP +This is a procedure that takes two arguments and prints both their sum +and their product. It also returns the string +.QW OK +to the caller as an explicit result. +.PP +.CS +\fBproc\fR printSumProduct {x y} { + set sum [expr {$x + $y}] + set prod [expr {$x * $y}] + puts "sum is $sum, product is $prod" + return "OK" +} +.CE +.PP This is a procedure that accepts arbitrarily many arguments and prints them out, one by one. .PP |