Yeah Awk and JavaScript have surprisingly similar syntax. But the semantics are very different. Here are some things I found when studying Awk a bit more:
- Awk has no local variables! There is no "var". Believe it or not, people fake locals with unused function parameters.
- Awk has no dict literals like d={}. And no function literals like f = function(x) { return x; }
- Awk dicts can't be nested. You can't have something like: {key1: {key2: 123}} (using JS syntax)
- Awk CAN accept dicts as parameters, but it CAN'T return them. "return d" is invalid.
- Awk can't take functions as parameters OR return them. That is, no higher order functions.
The latter three facts are basically consequences of the fact that Awk has no garbage collection. It has a strict stack discipline and no nested compound data structures.
Yes, and another difference is the use of 1-based string indexes, as opposed to 0-based string indexes in JavaScript. Even though I started with C many years ago (where 0-based string indexes are there for a reason, unlike in Java and JavaScript IMHO), I found 1-based string index semantics to allow much more compact and idiomatic expressions for typical string massaging tasks.
- Awk has no local variables! There is no "var". Believe it or not, people fake locals with unused function parameters.
- Awk has no dict literals like d={}. And no function literals like f = function(x) { return x; }
- Awk dicts can't be nested. You can't have something like: {key1: {key2: 123}} (using JS syntax)
- Awk CAN accept dicts as parameters, but it CAN'T return them. "return d" is invalid.
- Awk can't take functions as parameters OR return them. That is, no higher order functions.
The latter three facts are basically consequences of the fact that Awk has no garbage collection. It has a strict stack discipline and no nested compound data structures.