3 ms·
Oh look, you just invented array slices! https://en.wikipedia.org/wiki/Array_slicing https://en.wikipedia.org/wiki/Array_slicing
by peteretep 14y ago
Oh look, you just invented array slices!
https://en.wikipedia.org/wiki/Array_slicing https://en.wikipedia.org/wiki/Array_slicing
- freudianquip 14y ago"The concept of slicing was surely known even before the invention of compilers. Slicing as a language feature probably started with FORTRAN (1957)" Maybe slightly late for that.
- batista 14y agoGuy who doesn't understand general statements and statistics: "Your title is wrong, _I have_ heard of that idiom". A different guy with the same deficiency: "Wrong, it's a common idiom in (list of obscure languages)". Plus: array slicing, in 95% of the languages mentioned (and 99% of common languages) is NOT what he talks about. It just returns a sub-array and it only takes an uper/lower bound.
- kd0amg 14y agoYeah, ok, array slicing, woohoo. But what's interesting here is that this doesn't come from any special/privileged syntax or from special handling by the { operator. The { operator just expects a scalar and a list and accesses an element of the list according to the scalar. This slicing capability simply falls out of the automatic lifting J does when you pass an array of higher rank than the operator expects, the same rule that gives you (2 5 3)+7 = (9 12 10).
- silentbicycle 14y agoJ has it via APL, which is heavily based on linear algebra. (Not surprisingly, R, MATLAB, and other matrix-math-centric languages also have it.) It's one thing to say, "yeah, I can kinda do this in [language]", it's quite another when your whole language is based on it, as the APL family are. If you can do array slicing in parallel, you can work with permutation vectors rather than sorts (as he notes), and guess what? The same idiom works for relational joins, among many other things. (The killer app for Q, kdb+, is an in-memory, column oriented relational database. NoSQL, before it was cool.)
- northbranch 14y agoThis pattern is incredibly useful in Q, and one of the things I miss about using it daily. Of course, now I mainly use java, so the pendulum has truly swung.