Take: Difference between revisions

Jump to navigation Jump to search
20 bytes added ,  12:39, 25 October 2019
m
→‎APL model: Source indentation
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
    ⎕IO←0                        ⍝ For index comparisons
  r s ← ≢¨(⍴⍵)(⍺)              ⍝ Rank and number of modified axes
    r s ← ≢¨(⍴⍵)(⍺)              ⍝ Rank and number of modified axes
  (r=0)∧s>0: ⍺∇(s⍴1)⍴⍵          ⍝ Right argument scalar rank extension
    (r=0)∧s>0: ⍺∇(s⍴1)⍴⍵          ⍝ Right argument scalar rank extension
  s<r: (⍺,(s-r)∇⍴⍵)∇⍵          ⍝ SHARP APL extension
    s<r: (⍺,(s-r)∇⍴⍵)∇⍵          ⍝ SHARP APL extension
  inds ← ((⍺<0)×⍺+⍴⍵)∘+¨ ⍳|⍺    ⍝ Indices to select
    inds ← ((⍺<0)×⍺+⍴⍵)∘+¨ ⍳|⍺    ⍝ Indices to select
  sel ← {
    sel ← {
    ∧/(0≤⍺)∧⍺<⍴⍵: (⊂⍺)⊃⍵       ⍝ In range: use Pick
        ∧/(0≤⍺)∧⍺<⍴⍵: (⊂⍺)⊃⍵     ⍝ In range: use Pick
    ⊃0⍴⍵                       ⍝ Otherwise, get prototype
        ⊃0⍴⍵                     ⍝ Otherwise, get prototype
  }
    }
  sel∘⍵¨ inds
    sel∘⍵¨ inds
}
}
</source>
</source>
Anonymous user

Navigation menu