summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2007-12-08 20:25:40 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2007-12-08 20:25:40 (GMT)
commitc63800fafacdbb36b826ca84d62559fda1c77485 (patch)
treedf9ed9b441e976abbde0a24e90ff16212e536ed1
parent663ddf0e85629ebc17b2b0a161119f97df0f9e97 (diff)
downloadtcl-c63800fafacdbb36b826ca84d62559fda1c77485.zip
tcl-c63800fafacdbb36b826ca84d62559fda1c77485.tar.gz
tcl-c63800fafacdbb36b826ca84d62559fda1c77485.tar.bz2
Improved the documentation of the operators. [Bug 1823622]
-rw-r--r--ChangeLog3
-rw-r--r--doc/expr.n14
-rw-r--r--doc/mathop.n164
3 files changed, 116 insertions, 65 deletions
diff --git a/ChangeLog b/ChangeLog
index 31bb962..6193b72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2007-12-08 Donal K. Fellows <dkf@users.sf.net>
+ * doc/expr.n, doc/mathop.n: Improved the documentation of the
+ operators. [Bug 1823622]
+
* generic/tclBasic.c (builtInCmds): Corrected list of hidden and
* doc/interp.n (SAFE INTERPRETERS): exposed commands so that the
documentation and reality now match. [Bug 1662436]
diff --git a/doc/expr.n b/doc/expr.n
index 928d31b..8af04ce 100644
--- a/doc/expr.n
+++ b/doc/expr.n
@@ -6,7 +6,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: expr.n,v 1.32 2007/10/30 21:38:06 dkf Exp $
+'\" RCS: @(#) $Id: expr.n,v 1.33 2007/12/08 20:25:41 dkf Exp $
'\"
.so man.macros
.TH expr n 8.5 Tcl "Tcl Built-In Commands"
@@ -89,7 +89,7 @@ The command will be executed and its result will be used as
the operand.
.IP [7]
As a mathematical function whose arguments have any of the above
-forms for operands, such as \fBsin($x)\fR. See MATH FUNCTIONS below for
+forms for operands, such as \fBsin($x)\fR. See \fBMATH FUNCTIONS\fR below for
a discussion of how mathematical functions are handled.
.LP
Where the above substitutions occur (e.g. inside quoted strings), they
@@ -114,8 +114,9 @@ will produce the value on the right side of the line:
.CE
.SS OPERATORS
.PP
-The valid operators are listed below, grouped in decreasing order
-of precedence:
+The valid operators (most of which are also available as commands in
+the \fBtcl::mathop\fR namespace; see the \fBmathop\fR(n) manual page
+for details) are listed below, grouped in decreasing order of precedence:
.TP 20
\fB\-\0\0+\0\0~\0\0!\fR
Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operators
@@ -350,6 +351,11 @@ The most expensive code is required for
unbraced expressions that contain command substitutions.
These expressions must be implemented by generating new code
each time the expression is executed.
+.VS 8.5
+When the expression is unbraced to allow the substitution of a function or
+operator, consider using the commands documented in the \fBmathfunc\fR(n) or
+\fBmathop\fR(n) manual pages directly instead.
+.VE 8.5
.SH EXAMPLES
Define a procedure that computes an
.QW interesting
diff --git a/doc/mathop.n b/doc/mathop.n
index ae01583..ad5c80d 100644
--- a/doc/mathop.n
+++ b/doc/mathop.n
@@ -4,7 +4,7 @@
.\" See the file "license.terms" for information on usage and redistribution
.\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
.\"
-.\" RCS: @(#) $Id: mathop.n,v 1.8 2007/11/13 20:41:17 dkf Exp $
+.\" RCS: @(#) $Id: mathop.n,v 1.9 2007/12/08 20:25:41 dkf Exp $
.\"
.so man.macros
.TH mathop n 8.5 Tcl "Tcl Mathematical Operator Commands"
@@ -80,41 +80,51 @@ The following operator commands are supported:
\fB!=\fR \fBne\fR \fB<\fR \fB<=\fR \fB>\fR
\fB>=\fR \fBin\fR \fBni\fR
.DE
-The behaviors of the operator commands are as follows:
-.TP
-\fB~\fR \fInumber\fR
-.
-Returns the bit-wise negation of \fInumber\fR. \fINumber\fR may be an integer
-of any size.
+.SS "MATHEMATICAL OPERATORS"
+.PP
+The behaviors of the mathematical operator commands are as follows:
.TP
-\fB!\fR \fInumber\fR
+\fB!\fR \fIboolean\fR
.
-Returns the boolean negation of \fInumber\fR. \fINumber\fR may be any numeric
-value or any other form of boolean value.
+Returns the boolean negation of \fIboolean\fR, where \fIboolean\fR may be any
+numeric value or any other form of boolean value (i.e. it returns truth if the
+argument is falsity or zero, and falsity if the argument is truth or
+non-zero).
.TP
\fB+\fR ?\fInumber\fR ...?
.
-Returns the sum of arbitrarily many arguments. Each \fInumber\fR may be any
-numeric value. If no arguments are given, the result will be zero.
+Returns the sum of arbitrarily many arguments. Each \fInumber\fR argument may
+be any numeric value. If no arguments are given, the result will be zero (the
+summation identity).
.TP
\fB\-\fR \fInumber\fR ?\fInumber\fR ...?
.
-Returns the either the negation of the first argument (if only one argument is
-given) or the result of subtracting arbitrarily many additional arguments from
-the first argument. Each \fInumber\fR may be any numeric value. At least one
-argument must be given.
+If only a single \fInumber\fR argument is given, returns the negation of that
+numeric value. Otherwise returns the number that results when all subsequent
+numeric values are subtracted from the first one. All \fInumber\fR arguments
+must be numeric values. At least one argument must be given.
.TP
\fB*\fR ?\fInumber\fR ...?
.
Returns the product of arbitrarily many arguments. Each \fInumber\fR may be
-any numeric value. If no arguments are given, the result will be one.
+any numeric value. If no arguments are given, the result will be one (the
+multiplicative identity).
.TP
\fB/\fR \fInumber\fR ?\fInumber\fR ...?
.
-Returns the either the reciprocal of the first argument (if only one argument
-is given) or the result of dividing the first argument by arbitrarily many
-additional arguments. Each \fInumber\fR may be any numeric value. At least one
-argument must be given.
+If only a single \fInumber\fR argument is given, returns the reciprocal of that
+numeric value (i.e. the value obtained by dividing 1.0 by that value).
+Otherwise returns the number that results when the first numeric argument is
+divided by all subsequent numeric arguments. All \fInumber\fR arguments must
+be numeric values. At least one argument must be given.
+.RS
+.PP
+Note that when the leading values in the list of arguments are integers,
+integer division will be used for those initial steps (i.e. the intermediate
+results will be as if the functions \fIfloor\fR and \fIint\fR are applied to
+them, in that order). If all values in the operation are integers, the result
+will be an integer.
+.RE
.TP
\fB%\fR \fInumber number\fR
.
@@ -141,35 +151,10 @@ first is negative. If no arguments are given, the result will be one, and if
only one argument is given, the result will be that argument. The
result will have an integral value only when all arguments are
integral values.
-.TP
-\fB&\fR ?\fInumber\fR ...?
-.
-Returns the bit-wise AND of each of the arbitrarily many arguments. Each
-\fInumber\fR must have an integral value. If no arguments are given, the
-result will be minus one.
-.TP
-\fB|\fR ?\fInumber\fR ...?
-.
-Returns the bit-wise OR of each of the arbitrarily many arguments. Each
-\fInumber\fR must have an integral value. If no arguments are given, the
-result will be zero..TP
-\fB^\fR ?\fInumber\fR ...?
-.
-Returns the bit-wise XOR of each of the arbitrarily many arguments. Each
-\fInumber\fR must have an integral value. If no arguments are given, the
-result will be zero.
-.TP
-\fB<<\fR \fInumber number\fR
-.
-Returns the result of bit-wise shifting the first argument left by the
-number of bits specified in the second argument. Each \fInumber\fR
-must have an integral value.
-.TP
-\fB>>\fR \fInumber number\fR
-.
-Returns the result of bit-wise shifting the first argument right by
-the number of bits specified in the second argument. Each \fInumber\fR
-must have an integral value.
+.SS "COMPARISON OPERATORS"
+.PP
+The behaviors of the comparison operator commands (most of which operate
+preferentially on numeric arguments) are as follows:
.TP
\fB==\fR ?\fIarg\fR ...?
.
@@ -187,7 +172,8 @@ operation always returns a true value.
\fB!=\fR \fIarg arg\fR
.
Returns whether the two arguments are not equal to each other, in the sense of
-the \fBexpr\fR != operator (\fIi.e.\fR, numeric comparison if possible).
+the \fBexpr\fR != operator (\fIi.e.\fR, numeric comparison if possible, exact
+string comparison otherwise).
.TP
\fBne\fR \fIarg arg\fR
.
@@ -198,37 +184,93 @@ string comparison.
.
Returns whether the arbitrarily-many arguments are ordered, with each argument
after the first having to be strictly more than the one preceding it.
-Comparisons are performed preferentially on the numeric values. If fewer than
-two arguments are present, this operation always returns a true value.
+Comparisons are performed preferentially on the numeric values, and are
+otherwise performed using UNICODE string comparison. If fewer than two
+arguments are present, this operation always returns a true value. When the
+arguments are numeric but should be compared as strings, the \fBstring
+compare\fR command should be used instead.
.TP
\fB<=\fR ?\fIarg\fR ...?
.
Returns whether the arbitrarily-many arguments are ordered, with each argument
after the first having to be equal to or more than the one preceding it.
-Comparisons are performed preferentially on the numeric values. If fewer than
-two arguments are present, this operation always returns a true value.
+Comparisons are performed preferentially on the numeric values, and are
+otherwise performed using UNICODE string comparison. If fewer than two
+arguments are present, this operation always returns a true value. When the
+arguments are numeric but should be compared as strings, the \fBstring
+compare\fR command should be used instead.
.TP
\fB>\fR ?\fIarg\fR ...?
.
Returns whether the arbitrarily-many arguments are ordered, with each argument
after the first having to be strictly less than the one preceding it.
-Comparisons are performed preferentially on the numeric values. If fewer than
-two arguments are present, this operation always returns a true value.
+Comparisons are performed preferentially on the numeric values, and are
+otherwise performed using UNICODE string comparison. If fewer than two
+arguments are present, this operation always returns a true value. When the
+arguments are numeric but should be compared as strings, the \fBstring
+compare\fR command should be used instead.
.TP
\fB>=\fR ?\fIarg\fR ...?
.
Returns whether the arbitrarily-many arguments are ordered, with each argument
after the first having to be equal to or less than the one preceding it.
-Comparisons are performed preferentially on the numeric values. If fewer than
-two arguments are present, this operation always returns a true value.
+Comparisons are performed preferentially on the numeric values, and are
+otherwise performed using UNICODE string comparison. If fewer than two
+arguments are present, this operation always returns a true value. When the
+arguments are numeric but should be compared as strings, the \fBstring
+compare\fR command should be used instead.
+.SS "BIT-WISE OPERATORS"
+.PP
+The behaviors of the bit-wise operator commands (all of which only operate on
+integral arguments) are as follows:
+.TP
+\fB~\fR \fInumber\fR
+.
+Returns the bit-wise negation of \fInumber\fR. \fINumber\fR may be an integer
+of any size. Note that the result of this operation will always have the
+opposite sign to the input \fInumber\fR.
+.TP
+\fB&\fR ?\fInumber\fR ...?
+.
+Returns the bit-wise AND of each of the arbitrarily many arguments. Each
+\fInumber\fR must have an integral value. If no arguments are given, the
+result will be minus one.
+.TP
+\fB|\fR ?\fInumber\fR ...?
+.
+Returns the bit-wise OR of each of the arbitrarily many arguments. Each
+\fInumber\fR must have an integral value. If no arguments are given, the
+result will be zero..TP
+\fB^\fR ?\fInumber\fR ...?
+.
+Returns the bit-wise XOR of each of the arbitrarily many arguments. Each
+\fInumber\fR must have an integral value. If no arguments are given, the
+result will be zero.
+.TP
+\fB<<\fR \fInumber number\fR
+.
+Returns the result of bit-wise shifting the first argument left by the
+number of bits specified in the second argument. Each \fInumber\fR
+must have an integral value.
+.TP
+\fB>>\fR \fInumber number\fR
+.
+Returns the result of bit-wise shifting the first argument right by
+the number of bits specified in the second argument. Each \fInumber\fR
+must have an integral value.
+.SS "LIST OPERATORS"
+.PP
+The behaviors of the list-oriented operator commands are as follows:
.TP
\fBin\fR \fIarg list\fR
.
-Returns whether the value \fIarg\fR is present in the list \fIlist\fR.
+Returns whether the value \fIarg\fR is present in the list \fIlist\fR
+(according to exact string comparison of elements).
.TP
\fBni\fR \fIarg list\fR
.
-Returns whether the value \fIarg\fR is not present in the list \fIlist\fR.
+Returns whether the value \fIarg\fR is not present in the list \fIlist\fR
+(according to exact string comparison of elements).
.SH EXAMPLES
The simplest way to use the operators is often by using \fBnamespace path\fR
to make the commands available. This has the advantage of not affecting the