Take: Difference between revisions
Jump to navigation
Jump to search
Miraheze>Adám Brudzewsky No edit summary |
Miraheze>Marshall m (→APL model: Source indentation) |
||
Line 79: | Line 79: | ||
<source lang=apl> | <source lang=apl> | ||
Take ← { | Take ← { | ||
⎕IO←0 ⍝ For index comparisons | |||
r s ← ≢¨(⍴⍵)(⍺) ⍝ Rank and number of modified axes | |||
(r=0)∧s>0: ⍺∇(s⍴1)⍴⍵ ⍝ Right argument scalar rank extension | |||
s<r: (⍺,(s-r)∇⍴⍵)∇⍵ ⍝ SHARP APL extension | |||
inds ← ((⍺<0)×⍺+⍴⍵)∘+¨ ⍳|⍺ ⍝ Indices to select | |||
sel ← { | |||
∧/(0≤⍺)∧⍺<⍴⍵: (⊂⍺)⊃⍵ ⍝ In range: use Pick | |||
⊃0⍴⍵ ⍝ Otherwise, get prototype | |||
} | |||
sel∘⍵¨ inds | |||
} | } | ||
</source> | </source> |