1Nov 30, 1979:
2
3Awk has been modified yet again, in an attempt to make
4its behavior more rational and predictable in the areas
5of initialization, comparison, and type coercion.
6Herewith what we believe the current truth to be:
7
81. Each variable and field can potentially be a string
9or a number or both at any time.
10When a variable is set by the assignment
11	v = expr
12its type is set to that of expr.  (This includes +=, ++, etc.)
13An arithmetic expression is of type number, a
14concatenation is of type string,  and so on.
15
16If the assignment is a simple copy, as in
17	v1 = v2
18then the type of v1 becomes that of v2.
19
202. In comparisons, if both operands are numeric,
21the comparison is made numerically.  Otherwise,
22operands are coerced to string if necessary, and
23the comparison is made on strings.
24
253. The type of any expression can be coerced to
26numeric by subterfuges (kludges?) such as
27	expr + 0
28and to string by
29	expr ""
30(i.e., concatenation with a null string).
31
324. Uninitialized variables have the numeric value
330 and the string value "".  Accordingly, if x is
34uninitialized,
35	if (x) ...
36is false, and
37	if (!x) ...
38	if (x == 0) ...
39	if (x == "") ...
40are all true.  But note that
41	if (x == "0") ...
42is false.
43
445. The type of a field is determined by context
45when possible; for example,
46	$1++
47clearly implies that $1 is to be numeric, and
48	$1 = $1 "," $2
49implies that $1 and $2 are both to be strings.
50Coercion will be done as needed.
51
52In contexts where types cannot be reliably determined, e.g.,
53	if ($1 == $2) ...
54the type of each field is determined on input by
55inspection.  All fields are strings; in addition,
56each field that contains only a number (in the
57sense of Fortran, say) is also considered numeric.
58This ensures (for better or worse) that the test
59	if ($1 == $2) ...
60will succeed on the inputs
61	0	0.0
62	100	1e2
63	+100	100
64	1e-3	1e-3
65and fail on the inputs
66	(null)	0
67	(null)	0.0
68	2E-518	6E-427
69as we believe it should.
70
71Fields which are explicitly null have the string
72value ""; they are not numeric.
73Non-existent fields (i.e., fields past NF) are
74treated this way too.
75
76As it is for fields, so it is for array elements
77created by split(...).
78
796. There is no warranty of merchantability nor any warranty
80of fitness for a particular purpose nor any other warranty,
81either express or implied, as to the accuracy of the
82enclosed materials or as to their suitability for any
83particular purpose.  Accordingly, the AWK Development
84Task Force assumes no responsibility for their use by the
85recipient.   Further, the Task Force assumes no obligation
86to furnish any assistance of any kind whatsoever, or to
87furnish any additional information or documentation.
88