aboutsummaryrefslogtreecommitdiff
path: root/dzref
blob: 0bf42f376229bae892e1a8a897f4d71423911584 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/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β€ΏβˆžβŸ© 𝕩
}
UniqueMask←{
  ! 1≀=𝕩
  u←0↑𝕩
  {(β‰ u)>βŠ‘u IndexOf 𝕩}β—Ά{u↩uβˆΎπ•©β‹„1}β€Ώ0Λ˜π•©
}
Find←{
  r←=𝕨
  ! r≀=𝕩
  𝕨 β‰‘βŽ‰r (≒𝕨) β†•βŽ‰r 𝕩
}

⊐ ← ⊐              ⊘ IndexOf
∊ ← UniqueMask     ⊘ (⊐˜<β‰ βˆ˜βŠ’)
⍷ ← ∊⊸/            ⊘ Find

OccurrenceCount ← ⊐˜(⊒-⊏)β‹βˆ˜β‹
ProgressiveIndexOf ← {π•¨βŠβ—‹(β‰Λ˜βŸœOccurrenceCountπ•¨βŠΈβŠ)𝕩}

βŠ’ ← OccurrenceCount⊘ ProgressiveIndexOf
"

raw ← {⍎}
X ← {F:≀4}
_withRef ← Λ™
{v:
  chrsβ†βŸ¨
    "β†•βŠβŠ’βˆŠβ·"
    ""
    "βš‡"
  ⟩
  nc ← β‰ Β¨chrs
  chr ← ∾chrs
  itr ← 0β₯ŠΛœβ‰ chr

  init ← " "⊸∾¨(/⟜"_"Β¨nc/0β€Ώ1β€Ώ1)∾¨(nc/"FMD")∾¨(nc+Β΄βŠΈβ†‘β₯Š"AB"βˆΎβŒœβ€’a)
  post ← ∾⟜" "Β¨/⟜"_"Β¨nc/0β€Ώ0β€Ώ1
  names ← init∾¨'0'∾¨post

  Inc ← {
    iβ†βŠ‘chrβŠπ•©
    n←0 β‹„ itr↩{n↩1+𝕩}⌾(iβŠ‘βŠ’)itr
    names↩((iβŠ‘init)∾('0'+n)∾iβŠ‘post)⌾(iβŠ‘βŠ’)names
  }

  # built-in assumptions
  (Raw (chr⊸⊐⌾<βŠ‘namesΛ™)∾" ← "∾β₯Š)Β¨ "β†•βŠ"
  chrβˆΎβ†©"⍎" β‹„ namesβˆΎβ†©βŸ¨"⍎_withRef "⟩


  # checks if line is a builtin redefinition
  E_isdef ← (3≀≠)β—ΆβŸ¨0,∧´⟨chr," ","←↩"⟩∊˜¨3βŠΈβ†‘βŸ©

  # removes comments and replaces built-ins with names
  E_proc ← {
    l←≠chr
    q←≠`π•©βˆŠ"""'" β‹„ f←(𝕩=lf)β‰₯β—‹(β†•βˆ˜β‰ βŠΈ(⌈`Γ—))q<𝕩='#'
    ∾ (((lΓ—f/q)+chr⊸⊐) (β‰₯⟜l)β—ΆβŸ¨βŠ‘βŸœnames,β₯Šβˆ˜βŠ’⟩¨ ⊒) f/𝕩
  }

  E_redef ← { # handles [fmd] [←↩]
    tail ← E_proc 3↓𝕩 # must use old def
    Inc βŠ‘π•©
    (E_proc 1↑𝕩) ∾ "←" ∾ tail
  }

  lf ← @+10
  pre ← E_isdefβ—ΆE_procβ€ΏE_redefΒ¨ lf((⊒-ΛœΒ¬Γ—+`)∘=βŠ”βŠ’)impl
  ExecFile←{
    src ← E_procΒ¨ β€’FLines 𝕩
    ⟨⟨⟩,"",(∨`⌾⌽'/'=𝕩)/π•©βŸ© Raw ∾ ∾⟜lfΒ¨ src
  }
  _withRef ↩ {π”½βˆ˜E_proc⊘(π”½βŸœE_proc)}
  X↩Raw _withRef
  Raw ∾ ∾⟜lf¨ pre
  β‰ β—Ά(XΛ™)β€Ώ{ExecFile βŠ‘π•©}β€Ώ{ExecFile βŠ‘π•© β‹„ X 1βŠ‘π•©} β€’args
}