3 ms·
I share your sentiments and it is incredible. To an outsider this might as well be a parody of programming blog posts. Such impenetrable syntax taken in stride:
by boerseth 3y ago
I share your sentiments and it is incredible. To an outsider this might as well be a parody of programming blog posts. Such impenetrable syntax taken in stride:
We can improve this approach by recognizing that we can handle the edge cases by using a catenation:
⍸0 1⍷0,⍵
⍸1 0⍷⍵,0
Notice immediately how much better this feels.
Ah yes, how immediate is the feeling, much better, indeed. APL is so ridiculous, you have to love it.
- abrudz 3y agoThe syntax is actually quite simple, but you may be confused by the unfamiliar symbols and lack of syntax. 0 1 is simply [0,1] in JSON and ⍵ is the argument name. The other symbols cirrespond to prefix and infix operators. Compare the following JS expression which is syntactically (but not semantically) equivalent to the APL expression below it: - [0,1] * 0 ** w ⍸ 0 1 ⍷ 0 , ⍵
- abrudz 3y agoAs for the semantics, here are the equivalent JS functions: I = y => [...y.keys()].filter((e,i) => y[i]) // ⍸y Indices of trues in y E = (x,y) => y.map((e,i) => x.every((e,j) => e == y[i+j])) // x⍷y mask indicating indices where x Exists as a sub-array in y C = (x,y) => [x,y].flat() // x,y Catenate x and y into a single array w = [1,1,1,1,0,1,1,1,0,1,0,1,1,0,0,0,1,1,1,1] I(E([0,1],C(0,w))) // [0,5,9,11,16] Now, if I, E, and C were prefix/infix JS operators, with x being the left argument (if any) and y being the right argument, we'd write: I([0,1] E (0 C w)) All APL operators have long right scope, so we don't need to parenthesise right arguments: I [0,1] E 0 C w // same syntax as APL's ⍸ 0 1 ⍷ 0 , ⍵ Alternatively, you can see the infix operators as being methods of all types: I([0,1].E(0.C(w))) Now we remove all the .() noise: I [0,1] E 0 C w // same syntax as APL's ⍸ 0 1 ⍷ 0 , ⍵ Wasn't that hard, was it?