4 ms·
if you put s =: ({. , }. /: 12"_ o. }. - {.) @ /:~ in my code base, you are going to get smacked. Expressability of programming languages has a cognitive
by beders 11y ago
if you put
s =: ({. , }. /: 12"_ o. }. - {.) @ /:~
in my code base, you are going to get smacked.
Expressability of programming languages has a cognitive limit and J is flirting with it.
- Avshalom 11y agoif it makes you feel any better in Dyalog APL[1] I'd write that as: s←{ sp←⍵[⍋ ⍵] h t←(1↑sp) (1↓sp) h , t[⍋ 12○(t-h)] } or I can make it ugly as hell: s←{h,t[⍋ 12○(t←1↓p)-h←1↑p←⍵[⍋ ⍵]]} In Dyalog (and most APLs now) ←{...} creates function that automatically has ⍵ as it's left argument (so invoking "s points" ⍵ is points ) ⍋ give the indexes in sorted order and [ ] is how you access elements so ⍵[⍋ ⍵] is how you sort an array ↑ and ↓ are take and drop so (1↑sp) takes the head and (1↓sp) drops the head leaving the tail "h t←(1↑sp) (1↓sp)" is just multiple assignments J's verb trains are cute but kind of awful "h , t[⍋ 12○(t-h)]" sorts the tail according to the value of each elements phase (I agree the circle functions are particularly bad) and cats its back on to the head (also strictly speaking i don't need the parens around "t-h" but I like them). [1] well no actually I wouldn't because Dyalog's grade up (⍋) function doesn't work on complex numbers (though how to write a function ( gu ) that DOES is covered here http://dfns.dyalog.com/c_le.htm http://dfns.dyalog.com/c_le.htm )