#!/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 Nat←IsArray◶⟨0⊸≤∧⌊⊸=,0⟩ Windows←{ ! IsArray 𝕩 ! 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 Mod ← {((⊑chr⊐𝕨)⊑names) ∾ " ← " ∾ 𝕩} Raw¨ ⟨ "IsArray ← 0≠≡" ⟩∾Mod⟜⥊¨ "↕⊐" 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 }