Comments (2)
Interesting! Yeah, the spec doesn't seem to define this, though I think a reasonable assumption (extrapolating the bit you quoted about adding new elements) would be that it's not specified and the implementation is free to yield the deleted element (gawk, mawk), or not yield it (GoAWK, original-awk).
Note that apart from the question of how delete
interactions with iteration, there's also the question of iteration order itself. The POSIX AWK spec says that the implementation can iterate "in an unspecified order". GoAWK does just that, and actually uses Go's map iteration order, which varies from iteration to iteration. In this case for whatever reason Go usually iterates 0 first, then 1 ... but if you run it a dozen times or so, you'll see it iterate the other way:
# case where 0 is iterated first (seems to be more common)
$ goawk -f t.awk
key 0 val zero
# every so often 1 is iterated first
$ goawk -f t.awk
key 1 val one
key 0 val zero
GoAWK also uses Go's delete()
semantics, which is that "If a map entry that has not yet been reached is removed during iteration, the corresponding iteration value will not be produced." In other words, if the 0 is iterated first, the 1 will be deleted and not shown at all; but if the 1 is iterated first, GoAWK will try to delete 2, which doesn't exist so it'll do nothing, and then show the 0 after.
Note also that original-awk ("one true awk") seems to iterate the 0 first, and delete the 1:
$ original-awk -f t.awk
key 0 val zero
In any case, given the above, I think GoAWK's behaviour is within spec here.
from goawk.
Yes I did notice goawk is the only one to iterate in an (obviously) varying order but that's completely fair given the spec and seems natural for a go impl. If onetrueawk agrees with you I'm a lot more confident that this a fair interpretation of the spec (:
I really don't like the gawk/mawk behavior of yielding a deleted key; happy you did not got go that way.
from goawk.
Related Issues (20)
- Code coverage for GoAWK HOT 10
- Semicolon not allowed as terminator for normal pattern without action HOT 2
- Add logfmt support HOT 1
- Add JSON Lines support HOT 2
- Add some tests for the -d, -da, and -dt options
- Add optimization for a[1] -> a["1"]
- Should coverage profiles use relative filenames? HOT 2
- [Feature Request] Support case when end range pattern is not distinct from start pattern HOT 2
- Error parsing "cond && var=value" HOT 3
- Error parsing $++a
- Add support for 'nextfile'
- Add support for --csv (which Gawk and onetrueawk are adding)
- Wrong order of output with pipe and print HOT 1
- GoAWK 1.23.X fails on gron.awk HOT 7
- Mutually-recursive functions without type info cause compiler panic HOT 6
- Parser doesn't allow null ; (semicolon)
- Parsing "expr | getline > 0" fails without extra parens HOT 2
- FS regex [^,]* fails on empty field
- Exit status code in BEGIN should apply if END has exit
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goawk.