From c73b1c59e9b5da4874d95ca3484aa87891376ca3 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 26 Mar 2023 21:09:41 +0300 Subject: More doc on dynamic typing. --- doc/ChangeLog | 2 + doc/gawk.info | 695 ++++++++++++++++++++++++++++++-------------------------- doc/gawk.texi | 55 ++++- doc/gawktexi.in | 55 ++++- 4 files changed, 477 insertions(+), 330 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 8833e698..8fe0a7ca 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,8 @@ 2023-03-26 Arnold D. Robbins * texinfo.tex: Sync from GNULIB. + * gawktexi.in (Dynamic Typing): Add more explanation and another + example. 2023-03-09 Arnold D. Robbins diff --git a/doc/gawk.info b/doc/gawk.info index 9a8c59e1..26c3e58e 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -15340,8 +15340,51 @@ Here is an annotated sample program: so ‘awk’ will not report the second error. If you comment out that call, though, then ‘awk’ does report the second error. - Usually, such things aren’t a big issue, but it’s worth being aware -of them. + Here is a more extreme example: + + BEGIN { + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] + } + + function funky(arr) + { + if (A == 0) + arr = 1 + else + arr[1] = 1 + } + + Here, the function uses its parameter differently depending upon the +value of the global variable ‘A’. If ‘A’ is zero, the parameter ‘arr’ +is treated as a scalar. Otherwise it’s treated as an array. + + There are two ways this program might behave. ‘awk’ could notice +that in the main program, ‘a’ is subscripted, and so mark it as an array +before the program even begins to run. BWK ‘awk’, ‘mawk’, and possibly +others do this: + + $ nawk -v A=0 -f funky.awk + error→ nawk: can't assign to a; it's an array name. + error→ source line number 11 + $ nawk -v A=1 -f funky.awk + ⊣ 1 + + Or ‘awk’ could wait until runtime to set the type of ‘a’. In this +case, since ‘a’ was never assigned used before being passed to the +function, how the function uses it forces the type to be resolved to +either scalar or array. ‘gawk’ and the MKS ‘awk’ do this: + + $ gawk -v A=0 -f funky.awk + ⊣ <> + $ gawk -v A=1 -f funky.awk + ⊣ 1 + + POSIX does not specify the correct behavior, so be aware that +different implementations work differently.  File: gawk.info, Node: Indirect Calls, Next: Functions Summary, Prev: User-defined, Up: Functions @@ -39606,330 +39649,330 @@ Node: Function Caveats662110 Ref: Function Caveats-Footnote-1664205 Node: Return Statement664329 Node: Dynamic Typing667384 -Node: Indirect Calls668340 -Node: Functions Summary679499 -Node: Library Functions682276 -Ref: Library Functions-Footnote-1685824 -Ref: Library Functions-Footnote-2685967 -Node: Library Names686142 -Ref: Library Names-Footnote-1689936 -Ref: Library Names-Footnote-2690163 -Node: General Functions690259 -Node: Strtonum Function691453 -Node: Assert Function694535 -Node: Round Function697987 -Node: Cliff Random Function699565 -Node: Ordinal Functions700598 -Ref: Ordinal Functions-Footnote-1703707 -Ref: Ordinal Functions-Footnote-2703959 -Node: Join Function704173 -Ref: Join Function-Footnote-1705976 -Node: Getlocaltime Function706180 -Node: Readfile Function709954 -Node: Shell Quoting711983 -Node: Isnumeric Function713439 -Node: Data File Management714851 -Node: Filetrans Function715483 -Node: Rewind Function719777 -Node: File Checking721756 -Ref: File Checking-Footnote-1723128 -Node: Empty Files723335 -Node: Ignoring Assigns725402 -Node: Getopt Function726976 -Ref: Getopt Function-Footnote-1742810 -Node: Passwd Functions743022 -Ref: Passwd Functions-Footnote-1752204 -Node: Group Functions752292 -Ref: Group Functions-Footnote-1760430 -Node: Walking Arrays760643 -Node: Library Functions Summary763691 -Node: Library Exercises765115 -Node: Sample Programs765602 -Node: Running Examples766384 -Node: Clones767136 -Node: Cut Program768408 -Node: Egrep Program778849 -Node: Id Program788166 -Node: Split Program798280 -Ref: Split Program-Footnote-1808515 -Node: Tee Program808702 -Node: Uniq Program811611 -Node: Wc Program819476 -Node: Bytes vs. Characters819871 -Node: Using extensions821473 -Node: wc program822253 -Node: Miscellaneous Programs827259 -Node: Dupword Program828488 -Node: Alarm Program830551 -Node: Translate Program835464 -Ref: Translate Program-Footnote-1840205 -Node: Labels Program840483 -Ref: Labels Program-Footnote-1843924 -Node: Word Sorting844016 -Node: History Sorting848210 -Node: Extract Program850485 -Node: Simple Sed858754 -Node: Igawk Program861970 -Ref: Igawk Program-Footnote-1877217 -Ref: Igawk Program-Footnote-2877423 -Ref: Igawk Program-Footnote-3877553 -Node: Anagram Program877680 -Node: Signature Program880776 -Node: Programs Summary882028 -Node: Programs Exercises883286 -Ref: Programs Exercises-Footnote-1887602 -Node: Advanced Features887688 -Node: Nondecimal Data890182 -Node: Boolean Typed Values891812 -Node: Array Sorting893787 -Node: Controlling Array Traversal894516 -Ref: Controlling Array Traversal-Footnote-1903023 -Node: Array Sorting Functions903145 -Ref: Array Sorting Functions-Footnote-1909264 -Node: Two-way I/O909472 -Ref: Two-way I/O-Footnote-1917467 -Ref: Two-way I/O-Footnote-2917658 -Node: TCP/IP Networking917740 -Node: Profiling920920 -Node: Persistent Memory930630 -Ref: Persistent Memory-Footnote-1939588 -Node: Extension Philosophy939719 -Node: Advanced Features Summary941254 -Node: Internationalization943524 -Node: I18N and L10N945230 -Node: Explaining gettext945925 -Ref: Explaining gettext-Footnote-1952078 -Ref: Explaining gettext-Footnote-2952273 -Node: Programmer i18n952438 -Ref: Programmer i18n-Footnote-1957551 -Node: Translator i18n957600 -Node: String Extraction958436 -Ref: String Extraction-Footnote-1959614 -Node: Printf Ordering959712 -Ref: Printf Ordering-Footnote-1962574 -Node: I18N Portability962642 -Ref: I18N Portability-Footnote-1965216 -Node: I18N Example965287 -Ref: I18N Example-Footnote-1968687 -Ref: I18N Example-Footnote-2968763 -Node: Gawk I18N968880 -Node: I18N Summary969536 -Node: Debugger970937 -Node: Debugging971961 -Node: Debugging Concepts972410 -Node: Debugging Terms974236 -Node: Awk Debugging976849 -Ref: Awk Debugging-Footnote-1977826 -Node: Sample Debugging Session977966 -Node: Debugger Invocation978518 -Node: Finding The Bug980147 -Node: List of Debugger Commands986833 -Node: Breakpoint Control988210 -Node: Debugger Execution Control992042 -Node: Viewing And Changing Data995522 -Node: Execution Stack999260 -Node: Debugger Info1000941 -Node: Miscellaneous Debugger Commands1005240 -Node: Readline Support1010493 -Node: Limitations1011439 -Node: Debugging Summary1014083 -Node: Namespaces1015386 -Node: Global Namespace1016513 -Node: Qualified Names1017958 -Node: Default Namespace1018993 -Node: Changing The Namespace1019768 -Node: Naming Rules1021462 -Node: Internal Name Management1023377 -Node: Namespace Example1024447 -Node: Namespace And Features1027030 -Node: Namespace Summary1028487 -Node: Arbitrary Precision Arithmetic1030000 -Node: Computer Arithmetic1031519 -Ref: table-numeric-ranges1035336 -Ref: table-floating-point-ranges1035834 -Ref: Computer Arithmetic-Footnote-11036493 -Node: Math Definitions1036552 -Ref: table-ieee-formats1039597 -Node: MPFR features1040171 -Node: MPFR On Parole1040624 -Ref: MPFR On Parole-Footnote-11041468 -Node: MPFR Intro1041627 -Node: FP Math Caution1043317 -Ref: FP Math Caution-Footnote-11044391 -Node: Inexactness of computations1044768 -Node: Inexact representation1045799 -Node: Comparing FP Values1047182 -Node: Errors accumulate1048440 -Node: Strange values1049907 -Ref: Strange values-Footnote-11052573 -Node: Getting Accuracy1052678 -Node: Try To Round1055415 -Node: Setting precision1056322 -Ref: table-predefined-precision-strings1057027 -Node: Setting the rounding mode1058912 -Ref: table-gawk-rounding-modes1059294 -Ref: Setting the rounding mode-Footnote-11063352 -Node: Arbitrary Precision Integers1063535 -Ref: Arbitrary Precision Integers-Footnote-11066747 -Node: Checking for MPFR1066903 -Node: POSIX Floating Point Problems1068393 -Ref: POSIX Floating Point Problems-Footnote-11073257 -Node: Floating point summary1073295 -Node: Dynamic Extensions1075559 -Node: Extension Intro1077158 -Node: Plugin License1078466 -Node: Extension Mechanism Outline1079279 -Ref: figure-load-extension1079730 -Ref: figure-register-new-function1081315 -Ref: figure-call-new-function1082425 -Node: Extension API Description1084549 -Node: Extension API Functions Introduction1086278 -Ref: table-api-std-headers1088176 -Node: General Data Types1092640 -Ref: General Data Types-Footnote-11101808 -Node: Memory Allocation Functions1102123 -Ref: Memory Allocation Functions-Footnote-11106848 -Node: Constructor Functions1106947 -Node: API Ownership of MPFR and GMP Values1110852 -Node: Registration Functions1112413 -Node: Extension Functions1113117 -Node: Exit Callback Functions1118693 -Node: Extension Version String1120012 -Node: Input Parsers1120707 -Node: Output Wrappers1135351 -Node: Two-way processors1140199 -Node: Printing Messages1142560 -Ref: Printing Messages-Footnote-11143774 -Node: Updating ERRNO1143929 -Node: Requesting Values1144728 -Ref: table-value-types-returned1145481 -Node: Accessing Parameters1146590 -Node: Symbol Table Access1147874 -Node: Symbol table by name1148390 -Ref: Symbol table by name-Footnote-11151601 -Node: Symbol table by cookie1151733 -Ref: Symbol table by cookie-Footnote-11156014 -Node: Cached values1156078 -Ref: Cached values-Footnote-11159722 -Node: Array Manipulation1159879 -Ref: Array Manipulation-Footnote-11160982 -Node: Array Data Types1161019 -Ref: Array Data Types-Footnote-11163841 -Node: Array Functions1163941 -Node: Flattening Arrays1168970 -Node: Creating Arrays1176022 -Node: Redirection API1180872 -Node: Extension API Variables1183893 -Node: Extension Versioning1184618 -Ref: gawk-api-version1185055 -Node: Extension GMP/MPFR Versioning1186843 -Node: Extension API Informational Variables1188549 -Node: Extension API Boilerplate1189710 -Node: Changes from API V11193846 -Node: Finding Extensions1195480 -Node: Extension Example1196055 -Node: Internal File Description1196879 -Node: Internal File Ops1201203 -Ref: Internal File Ops-Footnote-11212761 -Node: Using Internal File Ops1212909 -Ref: Using Internal File Ops-Footnote-11215340 -Node: Extension Samples1215618 -Node: Extension Sample File Functions1217187 -Node: Extension Sample Fnmatch1225325 -Node: Extension Sample Fork1226920 -Node: Extension Sample Inplace1228196 -Node: Extension Sample Ord1231868 -Node: Extension Sample Readdir1232744 -Ref: table-readdir-file-types1233641 -Node: Extension Sample Revout1234779 -Node: Extension Sample Rev2way1235376 -Node: Extension Sample Read write array1236128 -Node: Extension Sample Readfile1239402 -Node: Extension Sample Time1240533 -Node: Extension Sample API Tests1242823 -Node: gawkextlib1243331 -Node: Extension summary1246367 -Node: Extension Exercises1250225 -Node: Language History1251503 -Node: V7/SVR3.11253217 -Node: SVR41255567 -Node: POSIX1257099 -Node: BTL1258524 -Node: POSIX/GNU1259293 -Node: Feature History1265824 -Node: Common Extensions1284942 -Node: Ranges and Locales1286311 -Ref: Ranges and Locales-Footnote-11291112 -Ref: Ranges and Locales-Footnote-21291139 -Ref: Ranges and Locales-Footnote-31291378 -Node: Contributors1291601 -Node: History summary1297806 -Node: Installation1299252 -Node: Gawk Distribution1300216 -Node: Getting1300708 -Node: Extracting1301707 -Node: Distribution contents1303419 -Node: Unix Installation1311499 -Node: Quick Installation1312321 -Node: Compiling with MPFR1314867 -Node: Shell Startup Files1315573 -Node: Additional Configuration Options1316730 -Node: Configuration Philosophy1319117 -Node: Compiling from Git1321619 -Node: Building the Documentation1322178 -Node: Non-Unix Installation1323590 -Node: PC Installation1324066 -Node: PC Binary Installation1324939 -Node: PC Compiling1325844 -Node: PC Using1327022 -Node: Cygwin1330750 -Node: MSYS1332006 -Node: OpenVMS Installation1332638 -Node: OpenVMS Compilation1333319 -Ref: OpenVMS Compilation-Footnote-11334802 -Node: OpenVMS Dynamic Extensions1334864 -Node: OpenVMS Installation Details1336500 -Node: OpenVMS Running1338935 -Node: OpenVMS GNV1343072 -Node: Bugs1343827 -Node: Bug definition1344751 -Node: Bug address1348402 -Node: Usenet1351993 -Node: Performance bugs1353224 -Node: Asking for help1356242 -Node: Maintainers1358233 -Node: Other Versions1359260 -Node: Installation summary1368192 -Node: Notes1369576 -Node: Compatibility Mode1370386 -Node: Additions1371208 -Node: Accessing The Source1372153 -Node: Adding Code1373688 -Node: New Ports1380824 -Node: Derived Files1385334 -Ref: Derived Files-Footnote-11391181 -Ref: Derived Files-Footnote-21391216 -Ref: Derived Files-Footnote-31391833 -Node: Future Extensions1391947 -Node: Implementation Limitations1392619 -Node: Extension Design1393861 -Node: Old Extension Problems1395025 -Ref: Old Extension Problems-Footnote-11396601 -Node: Extension New Mechanism Goals1396662 -Ref: Extension New Mechanism Goals-Footnote-11400158 -Node: Extension Other Design Decisions1400359 -Node: Extension Future Growth1402558 -Node: Notes summary1403182 -Node: Basic Concepts1404395 -Node: Basic High Level1405080 -Ref: figure-general-flow1405362 -Ref: figure-process-flow1406069 -Ref: Basic High Level-Footnote-11409470 -Node: Basic Data Typing1409659 -Node: Glossary1413077 -Node: Copying1446199 -Node: GNU Free Documentation License1483960 -Node: Index1509283 +Node: Indirect Calls669660 +Node: Functions Summary680819 +Node: Library Functions683596 +Ref: Library Functions-Footnote-1687144 +Ref: Library Functions-Footnote-2687287 +Node: Library Names687462 +Ref: Library Names-Footnote-1691256 +Ref: Library Names-Footnote-2691483 +Node: General Functions691579 +Node: Strtonum Function692773 +Node: Assert Function695855 +Node: Round Function699307 +Node: Cliff Random Function700885 +Node: Ordinal Functions701918 +Ref: Ordinal Functions-Footnote-1705027 +Ref: Ordinal Functions-Footnote-2705279 +Node: Join Function705493 +Ref: Join Function-Footnote-1707296 +Node: Getlocaltime Function707500 +Node: Readfile Function711274 +Node: Shell Quoting713303 +Node: Isnumeric Function714759 +Node: Data File Management716171 +Node: Filetrans Function716803 +Node: Rewind Function721097 +Node: File Checking723076 +Ref: File Checking-Footnote-1724448 +Node: Empty Files724655 +Node: Ignoring Assigns726722 +Node: Getopt Function728296 +Ref: Getopt Function-Footnote-1744130 +Node: Passwd Functions744342 +Ref: Passwd Functions-Footnote-1753524 +Node: Group Functions753612 +Ref: Group Functions-Footnote-1761750 +Node: Walking Arrays761963 +Node: Library Functions Summary765011 +Node: Library Exercises766435 +Node: Sample Programs766922 +Node: Running Examples767704 +Node: Clones768456 +Node: Cut Program769728 +Node: Egrep Program780169 +Node: Id Program789486 +Node: Split Program799600 +Ref: Split Program-Footnote-1809835 +Node: Tee Program810022 +Node: Uniq Program812931 +Node: Wc Program820796 +Node: Bytes vs. Characters821191 +Node: Using extensions822793 +Node: wc program823573 +Node: Miscellaneous Programs828579 +Node: Dupword Program829808 +Node: Alarm Program831871 +Node: Translate Program836784 +Ref: Translate Program-Footnote-1841525 +Node: Labels Program841803 +Ref: Labels Program-Footnote-1845244 +Node: Word Sorting845336 +Node: History Sorting849530 +Node: Extract Program851805 +Node: Simple Sed860074 +Node: Igawk Program863290 +Ref: Igawk Program-Footnote-1878537 +Ref: Igawk Program-Footnote-2878743 +Ref: Igawk Program-Footnote-3878873 +Node: Anagram Program879000 +Node: Signature Program882096 +Node: Programs Summary883348 +Node: Programs Exercises884606 +Ref: Programs Exercises-Footnote-1888922 +Node: Advanced Features889008 +Node: Nondecimal Data891502 +Node: Boolean Typed Values893132 +Node: Array Sorting895107 +Node: Controlling Array Traversal895836 +Ref: Controlling Array Traversal-Footnote-1904343 +Node: Array Sorting Functions904465 +Ref: Array Sorting Functions-Footnote-1910584 +Node: Two-way I/O910792 +Ref: Two-way I/O-Footnote-1918787 +Ref: Two-way I/O-Footnote-2918978 +Node: TCP/IP Networking919060 +Node: Profiling922240 +Node: Persistent Memory931950 +Ref: Persistent Memory-Footnote-1940908 +Node: Extension Philosophy941039 +Node: Advanced Features Summary942574 +Node: Internationalization944844 +Node: I18N and L10N946550 +Node: Explaining gettext947245 +Ref: Explaining gettext-Footnote-1953398 +Ref: Explaining gettext-Footnote-2953593 +Node: Programmer i18n953758 +Ref: Programmer i18n-Footnote-1958871 +Node: Translator i18n958920 +Node: String Extraction959756 +Ref: String Extraction-Footnote-1960934 +Node: Printf Ordering961032 +Ref: Printf Ordering-Footnote-1963894 +Node: I18N Portability963962 +Ref: I18N Portability-Footnote-1966536 +Node: I18N Example966607 +Ref: I18N Example-Footnote-1970007 +Ref: I18N Example-Footnote-2970083 +Node: Gawk I18N970200 +Node: I18N Summary970856 +Node: Debugger972257 +Node: Debugging973281 +Node: Debugging Concepts973730 +Node: Debugging Terms975556 +Node: Awk Debugging978169 +Ref: Awk Debugging-Footnote-1979146 +Node: Sample Debugging Session979286 +Node: Debugger Invocation979838 +Node: Finding The Bug981467 +Node: List of Debugger Commands988153 +Node: Breakpoint Control989530 +Node: Debugger Execution Control993362 +Node: Viewing And Changing Data996842 +Node: Execution Stack1000580 +Node: Debugger Info1002261 +Node: Miscellaneous Debugger Commands1006560 +Node: Readline Support1011813 +Node: Limitations1012759 +Node: Debugging Summary1015403 +Node: Namespaces1016706 +Node: Global Namespace1017833 +Node: Qualified Names1019278 +Node: Default Namespace1020313 +Node: Changing The Namespace1021088 +Node: Naming Rules1022782 +Node: Internal Name Management1024697 +Node: Namespace Example1025767 +Node: Namespace And Features1028350 +Node: Namespace Summary1029807 +Node: Arbitrary Precision Arithmetic1031320 +Node: Computer Arithmetic1032839 +Ref: table-numeric-ranges1036656 +Ref: table-floating-point-ranges1037154 +Ref: Computer Arithmetic-Footnote-11037813 +Node: Math Definitions1037872 +Ref: table-ieee-formats1040917 +Node: MPFR features1041491 +Node: MPFR On Parole1041944 +Ref: MPFR On Parole-Footnote-11042788 +Node: MPFR Intro1042947 +Node: FP Math Caution1044637 +Ref: FP Math Caution-Footnote-11045711 +Node: Inexactness of computations1046088 +Node: Inexact representation1047119 +Node: Comparing FP Values1048502 +Node: Errors accumulate1049760 +Node: Strange values1051227 +Ref: Strange values-Footnote-11053893 +Node: Getting Accuracy1053998 +Node: Try To Round1056735 +Node: Setting precision1057642 +Ref: table-predefined-precision-strings1058347 +Node: Setting the rounding mode1060232 +Ref: table-gawk-rounding-modes1060614 +Ref: Setting the rounding mode-Footnote-11064672 +Node: Arbitrary Precision Integers1064855 +Ref: Arbitrary Precision Integers-Footnote-11068067 +Node: Checking for MPFR1068223 +Node: POSIX Floating Point Problems1069713 +Ref: POSIX Floating Point Problems-Footnote-11074577 +Node: Floating point summary1074615 +Node: Dynamic Extensions1076879 +Node: Extension Intro1078478 +Node: Plugin License1079786 +Node: Extension Mechanism Outline1080599 +Ref: figure-load-extension1081050 +Ref: figure-register-new-function1082635 +Ref: figure-call-new-function1083745 +Node: Extension API Description1085869 +Node: Extension API Functions Introduction1087598 +Ref: table-api-std-headers1089496 +Node: General Data Types1093960 +Ref: General Data Types-Footnote-11103128 +Node: Memory Allocation Functions1103443 +Ref: Memory Allocation Functions-Footnote-11108168 +Node: Constructor Functions1108267 +Node: API Ownership of MPFR and GMP Values1112172 +Node: Registration Functions1113733 +Node: Extension Functions1114437 +Node: Exit Callback Functions1120013 +Node: Extension Version String1121332 +Node: Input Parsers1122027 +Node: Output Wrappers1136671 +Node: Two-way processors1141519 +Node: Printing Messages1143880 +Ref: Printing Messages-Footnote-11145094 +Node: Updating ERRNO1145249 +Node: Requesting Values1146048 +Ref: table-value-types-returned1146801 +Node: Accessing Parameters1147910 +Node: Symbol Table Access1149194 +Node: Symbol table by name1149710 +Ref: Symbol table by name-Footnote-11152921 +Node: Symbol table by cookie1153053 +Ref: Symbol table by cookie-Footnote-11157334 +Node: Cached values1157398 +Ref: Cached values-Footnote-11161042 +Node: Array Manipulation1161199 +Ref: Array Manipulation-Footnote-11162302 +Node: Array Data Types1162339 +Ref: Array Data Types-Footnote-11165161 +Node: Array Functions1165261 +Node: Flattening Arrays1170290 +Node: Creating Arrays1177342 +Node: Redirection API1182192 +Node: Extension API Variables1185213 +Node: Extension Versioning1185938 +Ref: gawk-api-version1186375 +Node: Extension GMP/MPFR Versioning1188163 +Node: Extension API Informational Variables1189869 +Node: Extension API Boilerplate1191030 +Node: Changes from API V11195166 +Node: Finding Extensions1196800 +Node: Extension Example1197375 +Node: Internal File Description1198199 +Node: Internal File Ops1202523 +Ref: Internal File Ops-Footnote-11214081 +Node: Using Internal File Ops1214229 +Ref: Using Internal File Ops-Footnote-11216660 +Node: Extension Samples1216938 +Node: Extension Sample File Functions1218507 +Node: Extension Sample Fnmatch1226645 +Node: Extension Sample Fork1228240 +Node: Extension Sample Inplace1229516 +Node: Extension Sample Ord1233188 +Node: Extension Sample Readdir1234064 +Ref: table-readdir-file-types1234961 +Node: Extension Sample Revout1236099 +Node: Extension Sample Rev2way1236696 +Node: Extension Sample Read write array1237448 +Node: Extension Sample Readfile1240722 +Node: Extension Sample Time1241853 +Node: Extension Sample API Tests1244143 +Node: gawkextlib1244651 +Node: Extension summary1247687 +Node: Extension Exercises1251545 +Node: Language History1252823 +Node: V7/SVR3.11254537 +Node: SVR41256887 +Node: POSIX1258419 +Node: BTL1259844 +Node: POSIX/GNU1260613 +Node: Feature History1267144 +Node: Common Extensions1286262 +Node: Ranges and Locales1287631 +Ref: Ranges and Locales-Footnote-11292432 +Ref: Ranges and Locales-Footnote-21292459 +Ref: Ranges and Locales-Footnote-31292698 +Node: Contributors1292921 +Node: History summary1299126 +Node: Installation1300572 +Node: Gawk Distribution1301536 +Node: Getting1302028 +Node: Extracting1303027 +Node: Distribution contents1304739 +Node: Unix Installation1312819 +Node: Quick Installation1313641 +Node: Compiling with MPFR1316187 +Node: Shell Startup Files1316893 +Node: Additional Configuration Options1318050 +Node: Configuration Philosophy1320437 +Node: Compiling from Git1322939 +Node: Building the Documentation1323498 +Node: Non-Unix Installation1324910 +Node: PC Installation1325386 +Node: PC Binary Installation1326259 +Node: PC Compiling1327164 +Node: PC Using1328342 +Node: Cygwin1332070 +Node: MSYS1333326 +Node: OpenVMS Installation1333958 +Node: OpenVMS Compilation1334639 +Ref: OpenVMS Compilation-Footnote-11336122 +Node: OpenVMS Dynamic Extensions1336184 +Node: OpenVMS Installation Details1337820 +Node: OpenVMS Running1340255 +Node: OpenVMS GNV1344392 +Node: Bugs1345147 +Node: Bug definition1346071 +Node: Bug address1349722 +Node: Usenet1353313 +Node: Performance bugs1354544 +Node: Asking for help1357562 +Node: Maintainers1359553 +Node: Other Versions1360580 +Node: Installation summary1369512 +Node: Notes1370896 +Node: Compatibility Mode1371706 +Node: Additions1372528 +Node: Accessing The Source1373473 +Node: Adding Code1375008 +Node: New Ports1382144 +Node: Derived Files1386654 +Ref: Derived Files-Footnote-11392501 +Ref: Derived Files-Footnote-21392536 +Ref: Derived Files-Footnote-31393153 +Node: Future Extensions1393267 +Node: Implementation Limitations1393939 +Node: Extension Design1395181 +Node: Old Extension Problems1396345 +Ref: Old Extension Problems-Footnote-11397921 +Node: Extension New Mechanism Goals1397982 +Ref: Extension New Mechanism Goals-Footnote-11401478 +Node: Extension Other Design Decisions1401679 +Node: Extension Future Growth1403878 +Node: Notes summary1404502 +Node: Basic Concepts1405715 +Node: Basic High Level1406400 +Ref: figure-general-flow1406682 +Ref: figure-process-flow1407389 +Ref: Basic High Level-Footnote-11410790 +Node: Basic Data Typing1410979 +Node: Glossary1414397 +Node: Copying1447519 +Node: GNU Free Documentation License1485280 +Node: Index1510603  End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 6ce9db35..a745dca2 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -21987,8 +21987,59 @@ a fatal error, so @command{awk} will not report the second error. If you comment out that call, though, then @command{awk} does report the second error. -Usually, such things aren't a big issue, but it's worth -being aware of them. +Here is a more extreme example: + +@example +BEGIN @{ + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] +@} + +function funky(arr) +@{ + if (A == 0) + arr = 1 + else + arr[1] = 1 +@} +@end example + +Here, the function uses its parameter differently depending upon the +value of the global variable @code{A}. If @code{A} is zero, the +parameter @code{arr} is treated as a scalar. Otherwise it's treated +as an array. + +There are two ways this program might behave. @command{awk} could notice +that in the main program, @code{a} is subscripted, and so mark it as +an array before the program even begins to run. BWK @code{awk}, @code{mawk}, +and possibly others do this: + +@example +$ @kbd{nawk -v A=0 -f funky.awk} +@error{} nawk: can't assign to a; it's an array name. +@error{} source line number 11 +$ @kbd{nawk -v A=1 -f funky.awk} +@print{} 1 +@end example + +Or @command{awk} could wait until runtime to set the type of @code{a}. +In this case, since @code{a} was never assigned used before being +passed to the function, how the function uses it forces the type to +be resolved to either scalar or array. @command{gawk} +and the MKS @command{awk} do this: + +@example +$ @kbd{gawk -v A=0 -f funky.awk} +@print{} <> +$ @kbd{gawk -v A=1 -f funky.awk } +@print{} 1 +@end example + +POSIX does not specify the correct behavior, so be aware that different +implementations work differently. @node Indirect Calls @section Indirect Function Calls diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 30bf38c5..5fb7a0f8 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -20972,8 +20972,59 @@ a fatal error, so @command{awk} will not report the second error. If you comment out that call, though, then @command{awk} does report the second error. -Usually, such things aren't a big issue, but it's worth -being aware of them. +Here is a more extreme example: + +@example +BEGIN @{ + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] +@} + +function funky(arr) +@{ + if (A == 0) + arr = 1 + else + arr[1] = 1 +@} +@end example + +Here, the function uses its parameter differently depending upon the +value of the global variable @code{A}. If @code{A} is zero, the +parameter @code{arr} is treated as a scalar. Otherwise it's treated +as an array. + +There are two ways this program might behave. @command{awk} could notice +that in the main program, @code{a} is subscripted, and so mark it as +an array before the program even begins to run. BWK @code{awk}, @code{mawk}, +and possibly others do this: + +@example +$ @kbd{nawk -v A=0 -f funky.awk} +@error{} nawk: can't assign to a; it's an array name. +@error{} source line number 11 +$ @kbd{nawk -v A=1 -f funky.awk} +@print{} 1 +@end example + +Or @command{awk} could wait until runtime to set the type of @code{a}. +In this case, since @code{a} was never assigned used before being +passed to the function, how the function uses it forces the type to +be resolved to either scalar or array. @command{gawk} +and the MKS @command{awk} do this: + +@example +$ @kbd{gawk -v A=0 -f funky.awk} +@print{} <> +$ @kbd{gawk -v A=1 -f funky.awk } +@print{} 1 +@end example + +POSIX does not specify the correct behavior, so be aware that different +implementations work differently. @node Indirect Calls @section Indirect Function Calls -- cgit v1.2.1