summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-01-31 11:32:32 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-01-31 11:32:32 (GMT)
commit677e675f822e7872ef9400cd6313238c87546558 (patch)
treeed88cfd09e8be3781c5cb48883ff22bfb2bf2959 /doc
parentf70668ffc335961a058f6a2968ad1d786b9ac78d (diff)
parent95bcc538075fc86ab77313a173e2c4ce89a38f0d (diff)
downloadtcl-677e675f822e7872ef9400cd6313238c87546558.zip
tcl-677e675f822e7872ef9400cd6313238c87546558.tar.gz
tcl-677e675f822e7872ef9400cd6313238c87546558.tar.bz2
Merge 8.7
Diffstat (limited to 'doc')
-rw-r--r--doc/expr.n133
1 files changed, 67 insertions, 66 deletions
diff --git a/doc/expr.n b/doc/expr.n
index 60dcf72..f4bb2ff 100644
--- a/doc/expr.n
+++ b/doc/expr.n
@@ -17,7 +17,7 @@ expr \- Evaluate an expression
.BE
.SH DESCRIPTION
.PP
-The \fIexpr\fR command concatenates \fIarg\fRs, separated by a space, into an expression, and evaluates
+Concatenates \fIarg\fRs, separated by a space, into an expression, and evaluates
that expression, returning its value.
The operators permitted in an expression include a subset of
the operators permitted in C expressions. For those operators
@@ -37,74 +37,34 @@ operands are specified. Expressions also support
non-numeric operands, string comparisons, and some
additional operators not found in C.
.PP
-When an expression evaluates to an integer, the value is the decimal form of
-the integer, and when an expression evaluates to a floating-point number, the
-value is the form produced by the \fB%g\fR format specifier of Tcl's
-\fBformat\fR command.
+When the result of expression is an integer, it is in decimal form, and when
+the result is a floating-point number, it is in the form produced by the
+\fB%g\fR format specifier of \fBformat\fR.
.PP
.VS "TIP 582"
-You can use \fB#\fR at any point in the expression (except inside double
-quotes or braces) to start a comment. Comments last to the end of the line or
+At any point in the expression except within double quotes or braces, \fB#\fR
+is the beginning of a comment, which lasts to the end of the line or
the end of the expression, whichever comes first.
.VE "TIP 582"
.SS OPERANDS
.PP
An expression consists of a combination of operands, operators, parentheses and
commas, possibly with whitespace between any of these elements, which is
-ignored.
+ignored. Each operand is intepreted as a numeric value if at all possible.
.PP
-An operand may be specified in any of the following ways:
-.IP [1]
-As a numeric value, either integer or floating-point.
-.IP [2]
-As a boolean value, using any form understood by \fBstring is\fR
-\fBboolean\fR.
-.IP [3]
-As a variable, using standard \fB$\fR notation.
-The value of the variable is then the value of the operand.
-.IP [4]
-As a string enclosed in double-quotes.
-Backslash, variable, and command substitution are performed as described in
-\fBTcl\fR.
-.IP [5]
-As a string enclosed in braces.
-The operand is treated as a braced value as described in \fBTcl\fR.
-.IP [6]
-As a Tcl command enclosed in brackets.
-Command substitution is performed as described in \fBTcl\fR.
-.IP [7]
-As a mathematical function such as \fBsin($x)\fR, whose arguments have any of the above
-forms for operands. See \fBMATH FUNCTIONS\fR below for
-a discussion of how mathematical functions are handled.
-.PP
-Because \fBexpr\fR parses and performs substitutions on values that have
-already been parsed and substituted by \fBTcl\fR, it is usually best to enclose
-expressions in braces to avoid the first round of substitutions by
-\fBTcl\fR.
-.PP
-Below are some examples of simple expressions where the value of \fBa\fR is 3
-and the value of \fBb\fR is 6. The command on the left side of each line
-produces the value on the right side.
-.PP
-.CS
-.ta 9c
-\fBexpr\fR {3.1 + $a} \fI6.1\fR
-\fBexpr\fR {2 + "$a.$b"} \fI5.6\fR
-\fBexpr\fR {4*[llength "6 2"]} \fI8\fR
-\fBexpr\fR {{word one} < "word $a"} \fI0\fR
-.CE
-.PP
-\fBInteger value\fR
+Each operand has one of the following forms:
+.RS
.PP
-An integer operand may be specified in decimal (the normal case, the optional
-first two characters are \fB0d\fR), binary
-(the first two characters are \fB0b\fR), octal
-(the first two characters are \fB0o\fR), or hexadecimal
-(the first two characters are \fB0x\fR) form. For
+.TP
+A \fBnumeric value\fR
.PP
-\fBFloating-point value\fR
+.RS
+.
+Either integer or floating-point. The first two characters of an integer may
+also be \fB0d\fR for decimal, \fB0b\fR for binary, \fB0o\fR for octal or
+\fB0x\fR for hexadicimal.
.PP
-A floating-point number may be specified in any of several
+A floating-point number may be take any of several
common decimal formats, and may use the decimal point \fB.\fR,
\fBe\fR or \fBE\fR for scientific notation, and
the sign characters \fB+\fR and \fB\-\fR. The
@@ -114,16 +74,9 @@ and \fBNaN\fR, in any combination of case, are also recognized as floating point
values. An operand that doesn't have a numeric interpretation must be quoted
with either braces or with double quotes.
.PP
-\fBBoolean value\fR
-.PP
-A boolean value may be represented by any of the values \fB0\fR, \fBfalse\fR, \fBno\fR,
-or \fBoff\fR and any of the values \fB1\fR, \fBtrue\fR, \fByes\fR, or \fBon\fR.
-.PP
-\fBDigit Separator\fR
-.PP
Digits in any numeric value may be separated with one or more underscore
-characters, "\fB_\fR", to improve readability. These separators may only
-appear between digits. The separator may not appear at the start of a
+characters, "\fB_\fR". A separator may only
+appear between digits, not appear at the start of a
numeric value, between the leading 0 and radix specifier, or at the
end of a numeric value. Here are some examples:
.PP
@@ -133,6 +86,54 @@ end of a numeric value. Here are some examples:
\fBexpr\fR 0xffff_ffff \fI4294967295\fR
\fBformat\fR 0x%x 0b1111_1110_1101_1011 \fI0xfedb\fR
.CE
+.RE
+
+.TP
+A \fBboolean value\fR
+.
+Using any form understood by \fBstring is\fR
+\fBboolean\fR.
+.TP
+A \fBvariable\fR
+.
+Using standard \fB$\fR notation.
+The value of the variable is the value of the operand.
+.TP
+A string enclosed in \fBdouble-quotes\fR
+.
+Backslash, variable, and command substitution are performed according to the
+rules for \fBTcl\fR.
+.TP
+A string enclosed in \fBbraces\fR.
+The operand is treated as a braced value according to the rule for braces in
+\fBTcl\fR.
+.TP
+A Tcl command enclosed in \fBbrackets\fR
+.
+Command substitution is performed as according to the command substitution rule
+for \fBTcl\fR.
+.TP
+A mathematical function such as \fBsin($x)\fR, whose arguments have any of the above
+forms for operands. See \fBMATH FUNCTIONS\fR below for
+a discussion of how mathematical functions are handled.
+.RE
+.PP
+Because \fBexpr\fR parses and performs substitutions on values that have
+already been parsed and substituted by \fBTcl\fR, it is usually best to enclose
+expressions in braces to avoid the first round of substitutions by
+\fBTcl\fR.
+.PP
+Below are some examples of simple expressions where the value of \fBa\fR is 3
+and the value of \fBb\fR is 6. The command on the left side of each line
+produces the value on the right side.
+.PP
+.CS
+.ta 9c
+\fBexpr\fR {3.1 + $a} \fI6.1\fR
+\fBexpr\fR {2 + "$a.$b"} \fI5.6\fR
+\fBexpr\fR {4*[llength {6 2}]} \fI8\fR
+\fBexpr\fR {{word one} < "word $a"} \fI0\fR
+.CE
.PP
.SS OPERATORS
.PP