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
0000544 [1003.1(2008)/Issue 7] Shell and Utilities Objection Enhancement Request 2012-02-18 19:12 2024-06-11 08:52
Reporter weeks View Status public  
Assigned To ajosey
Priority normal Resolution Accepted As Marked  
Status Closed  
Name Nathan Weeks
Organization Iowa State University HPC Group
User Reference
Section awk
Page Number 2441,2449
Line Number 77580-77583,77934
Interp Status ---
Final Accepted Text Note: 0004144
Summary 0000544: extend awk delete statement to delete entire array
Description The awk "delete" statement is currently defined as removing an individual array
element. To delete an entire array, a delete statement must be called for each
element of the array, typically in a loop.

At least gawk, mawk, BWK awk, Solaris /usr/xpg4/bin/awk, and BusyBox awk, which
collectively comprise the vast majority of installed awk implementations,
provide an extension that allows the deletion of all elements of an array with
a single delete statement, specifying only the array name without subscripts
(e.g., "delete ARRAY" instead of "for(i in ARRAY) delete ARRAY[i]")). Besides
the advantage of syntactic compactness, it allows an implementation to more
easily optimize the deletion of all array elements (e.g., the gawk manual states
"Using this version of the delete statement is about three times more efficient
than the equivalent loop that deletes each element one at a time.").

Desired Action Extend the awk syntax to allow
   delete ARRAY
where ARRAY is an array name.
Tags issue8
Attached Files

- Relationships
related to 0001136Closed 1003.1(2016/18)/Issue7+TC2 awk: missing case where a bare array name may be used 

-  Notes
(0001136)
Don Cragun (manager)
2012-02-18 19:31

If this is done, the awk grammar needs to be fixed as well as the description of the delete statement in the Extended Description section.
(0001137)
waldner (reporter)
2012-02-18 23:34

The typical way to do that is split("", ARRAY).
(0001139)
weeks (reporter)
2012-02-19 19:03

That's a good point. If the standard isn't amended to accept "delete ARRAY", then it would be useful for it to mention the 'split("", ARRAY)' idiom as an efficient way to delete all elements of an array.
(0001145)
geoffclare (manager)
2012-02-23 17:15
edited on: 2018-10-04 15:22

(Old resolution kept as historical record)

On page 2441 line 77580 change:

The delete statement shall remove an individual array element. Thus,
the following code deletes an entire array:

for (index in array)
    delete array[index]
    
to:

The delete statement shall remove either a specified individual array
element or, if no element is specified, all array elements. Thus, the
following code:

for (index in array)
    delete array[index]

is equivalent to:

delete array

Both delete all elements of the array.

Add after page 2449 line 77934:

   | Delete NAME

Add after page 2463 line 78548:

Deleting all elements of an array one element at a time, via:
for (index in array)
    delete array[index]
is usually not efficient. This standard requires 'delete array' to
have the same effects, and this was supported in most implementations
as a more efficient operation. It is also possible to use
'split("", array)' to achieve the same effect and efficiency.

(0004144)
geoffclare (manager)
2018-10-04 15:20
edited on: 2018-10-04 15:22

On 2016 edition page 2489 after line 80018 change the new bullet item added by bug 1136 from:
An implementation may allow the operand to the delete statement to be an array name.
to:
The NAME token following the keyword Delete without a subscript as specified in the grammar (see Grammar, on page XXX); if the name used in this context is not an array name, the behavior is undefined.

On 2016 edition page 2494 line 80239 change:
The delete statement shall remove an individual array element. Thus, the following code deletes an entire array:
for (index in array)
    delete array[index]
to:
The delete statement shall remove either a specified individual array element or, if no element is specified, all array elements. Thus, the following code:
for (index in array)
    delete array[index]

is equivalent to:
delete array

Both delete all elements of the array.

After 2016 edition P2494, L80242, delete the text added by bug 1136
Implementations may also accept the statement:
<tt>delete array</tt>
as a synonym for the above loop.

On 2016 edition page 2502 line 80593, change:
| Delete NAME                 /* See footnote 1. */
to:
| Delete NAME

and delete footnote 1.

Add after 2016 edition page 2516 line 81222:
Deleting all elements of an array one element at a time, via:
for (index in array)
    delete array[index]

is usually not efficient. This standard requires <tt>delete array</tt> to have the same effects, and this was supported in most implementations as a more efficient operation. It is also possible to use <tt>split("", array)</tt> to achieve the same effect and efficiency.



- Issue History
Date Modified Username Field Change
2012-02-18 19:12 weeks New Issue
2012-02-18 19:12 weeks Status New => Under Review
2012-02-18 19:12 weeks Assigned To => ajosey
2012-02-18 19:12 weeks Name => Nathan Weeks
2012-02-18 19:12 weeks Organization => Iowa State University HPC Group
2012-02-18 19:12 weeks Section => (section number or name, can be interface name)
2012-02-18 19:12 weeks Page Number => (page or range of pages)
2012-02-18 19:12 weeks Line Number => (Line or range of lines)
2012-02-18 19:12 weeks Issue Monitored: weeks
2012-02-18 19:31 Don Cragun Section (section number or name, can be interface name) => awk
2012-02-18 19:31 Don Cragun Page Number (page or range of pages) => 2441,2449
2012-02-18 19:31 Don Cragun Line Number (Line or range of lines) => 77580-77583,77934
2012-02-18 19:31 Don Cragun Interp Status => ---
2012-02-18 19:31 Don Cragun Note Added: 0001136
2012-02-18 23:34 waldner Note Added: 0001137
2012-02-19 19:03 weeks Note Added: 0001139
2012-02-23 17:15 geoffclare Note Added: 0001145
2012-02-23 17:16 geoffclare Final Accepted Text => Note: 0001145
2012-02-23 17:16 geoffclare Status Under Review => Resolved
2012-02-23 17:16 geoffclare Resolution Open => Accepted As Marked
2012-02-23 17:17 geoffclare Tag Attached: issue8
2012-02-23 17:28 eblake Note Edited: 0001145
2017-04-20 03:17 Don Cragun Relationship added related to 0001136
2018-10-04 15:20 geoffclare Note Added: 0004144
2018-10-04 15:22 geoffclare Note Edited: 0004144
2018-10-04 15:22 geoffclare Note Edited: 0001145
2018-10-04 15:23 geoffclare Final Accepted Text Note: 0001145 => Note: 0004144
2020-03-20 09:27 geoffclare Status Resolved => Applied
2024-06-11 08:52 agadmin Status Applied => Closed


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