3 ms·
Yeah it's definitely a historical thing. Bourne shell / POSIX shell doesn't have arrays, and ksh added arrays and bash adopted the same semantics. ksh did it
by chubot 5y ago
Yeah it's definitely a historical thing. Bourne shell / POSIX shell doesn't have arrays, and ksh added arrays and bash adopted the same semantics.
ksh did it in the most "backward compatible" way, with the least amount of work, but which leads to very confusing semantics.
They just "extended" every string so it can have an array part, and then changed a FEW parts of the evaluator, not ALL parts of it. So arrays "decay" to strings in most contexts. They didn't have to touch that code.
It's hard to explain but if you write an interpreter you'll get a feel for this O(M x N) explosion between data types and operations. The amount of work explodes as you add more of either, and shell already has a ton of operations. As mentioned, the evaluation rules for the word $x in 'echo $x' and 'echo foo > $x' are completely different.
There are ways to avoid this, like Python has PyObject and a bunch of protocols. Similarly, Clojure has more protocols than Racket, which the Racket authors have noted -- it works on abstractions and not "concretions". As far as I remember, these come directly from Java interfaces. So yes Java actually adds something to Lisp :)