4 ms·
> AWK was designed to not require a GC ... > The most substantial consequence is that it’s forbidden to return an array from a function, you can return only a
by colonwqbang 4y ago
> AWK was designed to not require a GC
...
> The most substantial consequence is that it’s forbidden to return an array from a function, you can return only a scalar value.
This doesn't make sense to me. Does someone understand what it means?
In e.g. C++ a function can return an array without any GC or refcounting, by "moving" the array into the caller's stack.
- doctor_eval 4y agoI am not an expert but I’d say it’s because Awk arrays are associative; they are more like maps than slices, to use Go terminology. And IIRC (it’s been a while) the array values are not strongly typed. So I think you could even say: a[1] = “hello” a[“world”] = 2 That means that - unlike C arrays - Awk arrays are not a simple, addressable byte range, but a complex data structure with lots of pointers. I suppose you could come up with a way to serialise the array and pop it on the stack but that would be a lot of work, and for the kind of things I use Awk for, the arrays would often be huge.
- colonwqbang 4y agoI'm not really convinced my that argument. No matter how big your associative array is, it is still represented by a pointer to the initial/root element. It should be quite possible to move the pointer into the caller. Maybe the language is simpler without it, and that can be a good reason to avoid it. But I don't buy that it has anything to do with GC.
- deleted 4y ago[deleted]
- ufo 4y agoIf arrays were first-class values we would be able to construct circular references: a[1] = a Even if we only allowed it on return values: function f(x) { return x } a[1] = f(a)