blob: 4996aae4d5ef00b7d0a4d7b5174bebc305758511 (
plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#!/usr/bin/env dbqn
impl ← "
#⌜
# LAYER 4: Operators
ValidateRanks←{
! 1≥=𝕩
𝕩↩⥊𝕩
! (1⊸≤∧≤⟜3)≠𝕩
! ∧´⌊⊸=⌜𝕩
𝕩
}
_ranks ← {⟨2⟩⊘⟨1,0⟩ ((⊣-1+|)˜⟜≠⊑¨<∘⊢) ValidateRanks∘𝔽}
_depthOp_←{
neg←0>n←𝕨𝔾_ranks𝕩 ⋄ F←𝔽
_d←{
R←(𝕗+neg)_d
𝕨(2⥊(neg∧𝕗≥0)∨(0⌈𝕗)≥≍○<○≡)◶(⟨R¨⋄R⟜𝕩¨∘⊣⟩≍⟨(𝕨R⊢)¨∘⊢⋄F⟩)𝕩
}
𝕨 n _d 𝕩
}
⚇ ← _depthOp_
#⌜
# LAYER 5: Structural functions
Windows←{
Nat←(1=•Type)◶⟨0,0⊸≤∧⌊⊸=⟩
! 0=•Type 𝕩
! 1≥=𝕨
! 𝕨≤○≠≢𝕩
! ∧´Nat¨⥊𝕨
s←(≠𝕨)↑≢𝕩
! ∧´𝕨≤1+s
𝕨{(∾⟜(𝕨≠⊸↓≢𝕩)∘≢⥊>)<¨⊸⊏⟜𝕩¨s(¬+⌜○↕⊢)⥊𝕨}⍟(0<≠𝕨)𝕩
}
↕ ↩ ↕ ⊘ Windows
#⌜
# LAYER 6: Everything else
# Searching
IndexOf←(1<⌈○=)◶⊐‿{
c←1-˜=𝕨
! 0≤c
𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,(+˝∧`)≢⎉c⎉c‿∞⟩ 𝕩
}
MarkFirst←{
! 1≤=𝕩
u←0↑𝕩
{(≠u)>⊑u IndexOf 𝕩}◶{u↩u∾𝕩⋄1}‿0˘𝕩
}
Find←{
r←=𝕨
! r≤=𝕩
0 •FillFn 𝕨 ≡⎉r ((1+r-⊸↑≢𝕩)⌊≢𝕨)⊸↕⎉r 𝕩
}
⊐ ↩ ⊐ ⊘ IndexOf
∊ ← MarkFirst ⊘ (⊐˜<≠∘⊢)
⍷ ← ∊⊸/ ⊘ Find
OccurrenceCount ← ⊐˜(⊢-⊏)⍋∘⍋
ProgressiveIndexOf ← {𝕨⊐○(((≢∾2˙)⥊≍˘⟜OccurrenceCount∘⥊)𝕨⊸⊐)𝕩}
⊒ ← OccurrenceCount⊘ ProgressiveIndexOf
"
raw ← {•Eval}
X ← {F:≤4}
_withRef ← ˙
{v:
chrs←⟨
"↕⊐⊒∊⍷"
""
"⚇"
⟩
# built-in assumptions
GetRepls ← {
c‿n ← 𝕩 ⋄ k←"↕⊐"
⟨c,(⥊¨k)⌾(((⊑¨c)⊐k)⊸⊏)n⟩ ∾⟜<¨ ⟨"•Eval","(•Eval _withRef)"⟩
}
⟨E_proc⟩ ← chrs‿GetRepls •Import "src/pp.bqn"
E_nodef ← 0⊸E_proc
ExecFile←{
((•path⊸∾⌾⊑(2∾˜∧`⌾⌽'/'≠𝕩)⊔𝕩)∾⟨𝕨⟩) Raw E_nodef •FChars 𝕩
}
_withRef ↩ {𝔽∘E_nodef⊘(𝔽⟜E_nodef)}
X↩Raw _withRef
Raw E_proc impl
(1⊸↓ ExecFile ⊑) •args
}
|