diff options
Diffstat (limited to 'bool.notes')
-rw-r--r-- | bool.notes | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bool.notes b/bool.notes new file mode 100644 index 00000000..51ea7268 --- /dev/null +++ b/bool.notes @@ -0,0 +1,47 @@ +Fri Mar 5 13:42:44 IST 2021 +============================ + +Design Notes for a Boolean Type in Gawk + +1. At first glance, two new variables named TRUE and FALSE would make sense +to be predefined values of boolean type. However, since it's likely that +many awk programs already use them, instead we'll add two new entries +to PROCINFO: variables PROCINFO["true"] and PROCINFO["false"] of type bool. + +Assigning from them copies the bool type, thus they are "factories" of bool +variables. + +2. They 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. + +This implies all of the following: + + print(PROCINFO["true"]) --> "TRUE" + print(PROCINFO["false"]) --> "FALSE" + Same for %s in printf + Same for bool_var "" + printf %d gives 0/1 + +3. Function bool(val) converts val to bool, returning Boolean TRUE or FALSE. + +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: + + substr match index gensub gsub + sub 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? |