Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001136 [1003.1(2016/18)/Issue7+TC2] Shell and Utilities Editorial Omission 2017-04-19 20:56 2019-10-31 11:48
Reporter stephane View Status public  
Assigned To
Priority normal Resolution Accepted As Marked  
Status Applied  
Name Stephane Chazelas
Organization
User Reference
Section awk
Page Number 2488-2489
Line Number 80013-80018
Interp Status ---
Final Accepted Text See Note: 0004143.
Summary 0001136: awk: missing case where a bare array name may be used
Description nitpick.

The spec says:

     Unsubscripted array names can be used in only the following contexts:

       * A parameter in a function definition or function call

       * The NAME token following any use of the keyword in as specified in
         the grammar (see Grammar); if the name used in this context is not
         an array name, the behavior is undefined

It's missing the case of the second argument to split()
Desired Action Below line 80018, add a third list item:

       * The second parameter to the split() function

It may also be worth pointing out in the first point above, that we're speaking of *user-defined* functions only.

Since "delete array" is not supported, it may be worth also adding (in some non-normative section) that split("", var) is one way to empty an array (but that it still gives the "array" type to the variable (that one shouldn't do for instance var = "value" after that).
Tags tc3-2008
Attached Files

- Relationships
related to 0000544Appliedajosey 1003.1(2008)/Issue 7 extend awk delete statement to delete entire array 

-  Notes
(0003673)
Don Cragun (manager)
2017-04-20 03:15
edited on: 2017-04-20 03:16

Another bug (0000544) has already been accepted to note that <tt>split("", array)</tt> can be used to delete all elements of an array and to allow <tt>delete array</tt> to delete all elements in an array in addition to the <tt>delete array[index]</tt> that can be used to delete a single element from an array.

I see no reason to believe that the 1st case in the list mentioned in the Description of this bug report does not include the the array name argument passed to the <tt>split()</tt> function nor do I see any reason to believe that functions provided by an <tt>awk</tt> implementation are never allowed to accept an array name as an argument (with <tt>split()</tt> being an obvious counterexample).

I do not see why any change suggested in this bug (other than the changes already specified in 0000544 for inclusion in the next revision of the standard) should be implemented.

(0003674)
stephane (reporter)
2017-04-20 06:11
edited on: 2018-10-04 15:22

Re: Note: 0003673

I understand the first item as one may declare and use functions that take array names as arguments (passed as reference).

Apart from split(), no other builtin function specified in this standard accept bare arrays in any implementations I've tried (except for busybox awk where variables can be both scalar and array at the same time).

Other builtin functions that awk implementations may provide as extension are out of the scope of this spec, and anyway this standard more or less precludes the addition of extra builtin functions as that would break compliance (prevent users from using them as user-defined functions, see how gawk disables all of it's extra functions under POSIXLY_CORRECT)

About bug:544, that would mean a 4th item would need to be added here ("delete" would hardly be taken as a "function" as you typically call it without parenthesis).

Also, I don't know about tawk where "delete array" apparently comes from but in gawk and busybox awk, the only implementations I know that also support it, the variable remains of array type after "delete variable", might be worth pointing out explicitly as one could assume that the variable is free to use as a scalar once it has been deleted.

Last slightly related point, it may be worth clarifying how array parameters may be passed by reference to user-defined functions (and maybe split() as well). For instance, most awk implementations accept myfunction(foo, (myarray)), but not mawk:

$ gawk 'function f(a) {a[1] = 1}; BEGIN{f((a)); print a[1]}'
1
$ nawk 'function f(a) {a[1] = 1}; BEGIN{f((a)); print a[1]}'
1
$ busybox awk 'function f(a) {a[1] = 1}; BEGIN{f((a)); print a[1]}'
1
$ mawk 'function f(a) {a[1] = 1}; BEGIN{f((a)); print a[1]}'
mawk: line 1: type error in arg(1) in call to f
mawk: line 1: illegal reference to variable a


See also f(mybool ? array : other_array) (that one supported by nawk and busybox awk but not gawk nor mawk).

(0004143)
Don Cragun (manager)
2018-10-04 15:17
edited on: 2018-10-04 15:22

Add a new bullet to the list on P2489 after L80018:

    * An implementation may allow the operand to the delete statement to be an array name


Move the paragraph starting on P2499, L80458 to follow P2496, L80325. (This moves
the discussion of array parameters from the user defined functions section to the section
that applies to all functions.)
    
Add a new paragraph after P2494, L80242:
Implementations may also accept the statement:
<tt>delete array</tt>

as a synonym for the above loop.


Add a new line to the grammar after P2502, L80593:

        | Delete NAME /* See footnote 1.*/

with footnote 1 being:
A future version of this standard may require the delete statement with an unsubscripted array name to be accepted. This version of the standard allows but does not require support for this syntax.


See also 0000544 for changes to be applied in the next revision of this standard.


- Issue History
Date Modified Username Field Change
2017-04-19 20:56 stephane New Issue
2017-04-19 20:56 stephane Name => Stephane Chazelas
2017-04-19 20:56 stephane Section => awk
2017-04-19 20:56 stephane Page Number => 2488-2489
2017-04-19 20:56 stephane Line Number => 80013-80018
2017-04-20 03:15 Don Cragun Note Added: 0003673
2017-04-20 03:16 Don Cragun Note Edited: 0003673
2017-04-20 03:17 Don Cragun Relationship added related to 0000544
2017-04-20 06:11 stephane Note Added: 0003674
2017-04-24 12:08 stephane Note Edited: 0003674
2018-10-04 15:17 Don Cragun Note Added: 0004143
2018-10-04 15:19 Don Cragun Interp Status => ---
2018-10-04 15:19 Don Cragun Final Accepted Text => See Note: 0004143.
2018-10-04 15:19 Don Cragun Status New => Resolved
2018-10-04 15:19 Don Cragun Resolution Open => Accepted As Marked
2018-10-04 15:21 Don Cragun Note Edited: 0004143
2018-10-04 15:21 Don Cragun Tag Attached: tc3-2008
2018-10-04 15:22 Don Cragun Note Edited: 0004143
2018-10-04 15:22 Don Cragun Note Edited: 0003674
2019-10-31 11:48 geoffclare Status Resolved => Applied


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker