EXPLAIN revision 7c478bd95313f5f23a4c958a745db2134aa03244
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
4fe198d6f302c883b3edf100a6990b2ee4923494vboxsync#ident "%Z%%M% %I% %E% SMI"
9b5bf00cddef78a2e5ab748a141ea830ce47abe2vboxsyncCDDL HEADER START
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncThe contents of this file are subject to the terms of the
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncCommon Development and Distribution License, Version 1.0 only
c58f1213e628a545081c70e26c6b67a841cff880vboxsync(the "License"). You may not use this file except in compliance
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncwith the License.
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncYou can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncSee the License for the specific language governing permissions
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncand limitations under the License.
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncWhen distributing Covered Code, include this CDDL HEADER in each
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncfile and include the License file at usr/src/OPENSOLARIS.LICENSE.
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncIf applicable, add the following below this CDDL HEADER, with the
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncfields enclosed by brackets "[]" replaced with your own identifying
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncinformation: Portions Copyright [yyyy] [name of copyright owner]
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncCDDL HEADER END
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncNov 30, 1979:
7519a1c4323fa86fbb19a36a91cd25abfd7af714vboxsyncAwk has been modified yet again, in an attempt to make
7519a1c4323fa86fbb19a36a91cd25abfd7af714vboxsyncits behavior more rational and predictable in the areas
7519a1c4323fa86fbb19a36a91cd25abfd7af714vboxsyncof initialization, comparison, and type coercion.
84d79169f58a3fa9b00b3fea89d1878d4dbac68cvboxsyncHerewith what we believe the current truth to be:
84d79169f58a3fa9b00b3fea89d1878d4dbac68cvboxsync1. Each variable and field can potentially be a string
84d79169f58a3fa9b00b3fea89d1878d4dbac68cvboxsyncor a number or both at any time.
84d79169f58a3fa9b00b3fea89d1878d4dbac68cvboxsyncWhen a variable is set by the assignment
7870a295fdec1b57c4546425f2e591fd3091a7b3vboxsyncits type is set to that of expr. (This includes +=, ++, etc.)
5ffb8839e755b3d3d6a45131c530ea13f8e9a2b9vboxsyncAn arithmetic expression is of type number, a
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncconcatenation is of type string, and so on.
5ffb8839e755b3d3d6a45131c530ea13f8e9a2b9vboxsyncIf the assignment is a simple copy, as in
4faf92053d9cec5599c0ab8577231df0f7d615b3vboxsyncthen the type of v1 becomes that of v2.
0575222e3e7455c3ea1fb8f5aa7c4b58aea40a08vboxsync2. In comparisons, if both operands are numeric,
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsyncthe comparison is made numerically. Otherwise,
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsyncoperands are coerced to string if necessary, and
5f78e8e2cc5ea1e52a14f9a18277cd3c5c89dd5cvboxsyncthe comparison is made on strings.
7870a295fdec1b57c4546425f2e591fd3091a7b3vboxsync3. The type of any expression can be coerced to
2caae01fb624524a93d8322500214c42d9038b74vboxsyncnumeric by subterfuges (kludges?) such as
0be659b1e32246489fa133d069bb619ad43647e7vboxsyncand to string by
0be659b1e32246489fa133d069bb619ad43647e7vboxsync(i.e., concatenation with a null string).
0be659b1e32246489fa133d069bb619ad43647e7vboxsync4. Uninitialized variables have the numeric value
69a69b3e1e0b45a026827f12961e809082f2ed52vboxsync0 and the string value "". Accordingly, if x is
69a69b3e1e0b45a026827f12961e809082f2ed52vboxsyncuninitialized,
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncis false, and
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsync if (!x) ...
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsync if (x == 0) ...
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsync if (x == "") ...
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncare all true. But note that
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsync if (x == "0") ...
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsync5. The type of a field is determined by context
e3d1df74cd5c2d182013559f64184fdea625b8e2vboxsyncwhen possible; for example,
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncclearly implies that $1 is to be numeric, and
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsync $1 = $1 "," $2
b2b3dd040e6419db8733be1dca655675d3c60e04vboxsyncimplies that $1 and $2 are both to be strings.
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncCoercion will be done as needed.
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncIn contexts where types cannot be reliably determined, e.g.,
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsync if ($1 == $2) ...
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncthe type of each field is determined on input by
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncinspection. All fields are strings; in addition,
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsynceach field that contains only a number (in the
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncsense of Fortran, say) is also considered numeric.
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncThis ensures (for better or worse) that the test
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsync if ($1 == $2) ...
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncwill succeed on the inputs
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncand fail on the inputs
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsync 2E-518 6E-427
ad27e1d5e48ca41245120c331cc88b50464813cevboxsyncas we believe it should.
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncFields which are explicitly null have the string
7480f639b6e81e4f5583e2dded360b77d3ad58a8vboxsyncvalue ""; they are not numeric.
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncNon-existent fields (i.e., fields past NF) are
7480f639b6e81e4f5583e2dded360b77d3ad58a8vboxsynctreated this way too.
b2b3dd040e6419db8733be1dca655675d3c60e04vboxsyncAs it is for fields, so it is for array elements
b2b3dd040e6419db8733be1dca655675d3c60e04vboxsynccreated by split(...).
08a41bf1ab08daa44e2875740ccd1ec50c6b8becvboxsync6. There is no warranty of merchantability nor any warranty
08a41bf1ab08daa44e2875740ccd1ec50c6b8becvboxsyncof fitness for a particular purpose nor any other warranty,
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsynceither express or implied, as to the accuracy of the
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncenclosed materials or as to their suitability for any
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncparticular purpose. Accordingly, the AWK Development
a6e469c8c56849f9391fd5f420ddc2205f6492a1vboxsyncTask Force assumes no responsibility for their use by the
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncrecipient. Further, the Task Force assumes no obligation
7a61a5714b9a39ac3bd59e52b0843ef498350a35vboxsyncto furnish any assistance of any kind whatsoever, or to
69a69b3e1e0b45a026827f12961e809082f2ed52vboxsyncfurnish any additional information or documentation.