blob: 8e24c2b544976ca30ec463f36d075699955fe1a3 (
plain)
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
|
Thu Mar 18 21:05:29 IST 2021
============================
Design Notes for a Boolean Type in Gawk
1. A new function bool(val) converts val to bool, returning Boolean TRUE
or FALSE. This is the generator for boolean values and is enough to have
instead of predefining new variables TRUE and FALSE.
2. Assigning from a boolean value copies the bool type.
3. Boolean variables have numeric values 1 and 0 respectively, and string
values "TRUE" and "FALSE". Thus they differ from other variables where a
"false" value must be zero and null.
Given:
true = bool(1)
false = bool(0)
this implies all of the following:
print(true) --> "TRUE"
print(false) --> "FALSE"
Same for %s in printf
Same for bool_var ""
printf %d gives 0/1
4. typeof() returns "bool".
5. Numeric operators treat booleans as numbers. asort() sorts booleans before
numbers, and false before true.
6. These string function generate a runtime fatal error
if given an argument / target of boolean type:
gsub sub
These functions merely treat the value as a string
but issue a lint warning.
substr match index gensub
length split patsplit
tolower toupper
7. Updates to API needed for an additional type, and the table
for requested vs. returns.
8. The following extensions need revising:
- JSON extension
- dump / read array extensions
- what else?
|