What's the best way to do 2f/⍵ where f is a dyadic function and ⍵ is an array, except operate on 'non-overlapping' pairs. I'm curious about both the most idiomatic way, and also the golfiest way.
Three back-to-back Commutes feels a bit much, IMHO. At the very least, something like {(⌈0.5×≢⍵) 2⍴⍵} parses more immediately for my (still APL student) brain.
Since we can lengthen/recycle with overtake/reshape, I'd be inclined to just error if the element counts don't match. Though since ⍴ recycles, maybe just defaulting to recycle also "makes sense"?
In the wild, is there a clear winner for the behaviour that is most commonly called for?
@xpqz heh, I'd say recycle would be the most surprising behavior. I can see how it makes sense as an extension of regular Reshape, but for a ⍬ 2⍴ specifically it'd always result in putting a column 1 element in column 2, which I don't think would be desired like ever, and it only recycles to a max of less than one row too
Is it more surprising than 5⍴⍳4 putting the first element last? The recycle behaviour always seemed more puzzling to me full stop, than the padding behaviour of (over)take.
you can do 8⍴⍳4 though, which neatly repeats all elements twice; but 5⍴⍳4 is indeed strange. No way to do the former with a ⍬n⍴ though, all you can get is the weird behavior of 5⍴⍳4
I personally think erroring is the sanest default if going for one option; multiple options is also acceptable, but I haven't found myself ever in a situation where I need padding and the prototype/fill element is acceptable
@essielovett How does first-axis reshape enter the picture? Surely, that's incompatible with the existing ⍴
@essielovett I think shorten makes the most sense, as then it is easy to append some elements (of your choice, including from the beginning if you want recycle) to achieve a lengthen.
Also, there's precedent for shorting, as ⎕MAP includes this feature (with ¯1 being the special value) and it shortens.
{sign←'Pig' 'Rat' 'Ox' 'Tiger' 'Rabbit' 'Dragon' 'Snake' 'Horse' 'Goat' 'Monkey' 'Rooster' 'Dog' ⋄ sign[(⍵<0)+1+12|⍵-2007]} Where the 2007 can be removed by rotating the vector a few postitions
Super late to the party, but this is my quickly-hack-it-out solution: `(⊃'Monkey' 'Rooster' 'Dog' 'Pig' 'Rat' 'Ox' 'Tiger' 'Rabbit' 'Dragon' 'Snake' 'Horse' 'Goat'⌷⍨1+12|⊢+<∘0)`
@Adám Hahahaha! Leveraging the capitals and rotating the the list of values instead of moduloing the index. Beautiful.