summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2016-06-27 13:44:40 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2016-06-27 13:44:40 (GMT)
commit039129beee818bb0aa8a756e09cb8a1b3ac68f49 (patch)
tree2392d3b6f64df6af49cfdba73cd194e3d125e9c4
parenta7534bc7ed966b9b399e86be1c6cc2004baf379c (diff)
downloadtcl-039129beee818bb0aa8a756e09cb8a1b3ac68f49.zip
tcl-039129beee818bb0aa8a756e09cb8a1b3ac68f49.tar.gz
tcl-039129beee818bb0aa8a756e09cb8a1b3ac68f49.tar.bz2
[c3d956be5b] Clearer text about positioning of optional arguments.
-rw-r--r--doc/proc.n28
1 files changed, 23 insertions, 5 deletions
diff --git a/doc/proc.n b/doc/proc.n
index 129f4df..fdccaca 100644
--- a/doc/proc.n
+++ b/doc/proc.n
@@ -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