-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Iota.dyalog
26 lines (26 loc) · 1.63 KB
/
Iota.dyalog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Iota←{ ⍝ ⍳ generalized (Unicode version of http://dfns.dyalog.com/n_iotag.htm)
AlphaInterval←{⍵=' ':'' ⍝ ⍳' ' is empty vector.
a←⎕UCS'0AaΑαАа⁰₀Ⓐ' ⍝ Starting points
k←⎕IO+a+.<i←1+⎕UCS ⍵ ⍝ Find starting point.
⍺←⎕UCS a[k-1] ⍝ Default left argument.
≤/i,j←⎕UCS ⍺:⌽⍵ ∇ ⍺ ⍝ If ⍵ before ⍺, reverse.
j↓i↑⎕UCS 0,1-⎕IO-⍳⎕UCS ⍵ ⍝ Truncate character set.
}
⍝Interval←{⍺+0,+\(|d)⍴×d←⍵-⍺} ⍝ Interval Function.
Interval←{s←×/1↓⍵,(⍺>↑⍵)/¯1 ⍝ Calculate step size
⍺-s×⎕IO-⍳⌊1-(⍺-↑⍵)÷s} ⍝ Generate Interval
IndexOf←{i←1↓⍳⍴⍴⍺ ⍝ Enclose left arg axis.
j←(1-⍴⍴⍺)↑⍳⍴⍴⍵ ⍝ Enclose right arg axis.
m←(⍴⍺)[i]⌈(⍴⍵)[j] ⍝ Pad both arguments.
(⊂[i]m↑[i]⍺)⍳⊂[j]m↑[j]⍵ ⍝ Get index.
}
ischar←{0 2∊⍨10|⎕DR ⍵} ⍝ type ∊ 82 80 160 ...
m←0=⎕NC'⍺' ⍝ Monadic?
m∧1=⍴⍴⍵:⊃∘.,/∇¨⍵ ⍝ Vector right argument
m∧ischar ⍵:AlphaInterval ⍵ ⍝ Alpha Monadic.
m:(×⍵)×⍳|⍵ ⍝ Integer Monadic.
s←0=⍴⍴⍺ ⍝ Scalar Left Argument?
s∧ischar ⍵:⍺ AlphaInterval ⍵ ⍝ Alpha Interval.
s:⍺ Interval ⍵ ⍝ Numeric Interval.
⍺ IndexOf ⍵ ⍝ Dyadic.
}