From f0e089208e22236483747360394155dc76cf7e48 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 5 Sep 2020 10:39:41 -0400 Subject: Show source of errors (primitive or compiler) --- src/r.bqn | 132 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 66 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/r.bqn b/src/r.bqn index de6ea148..d523ec8c 100644 --- a/src/r.bqn +++ b/src/r.bqn @@ -24,7 +24,7 @@ Nat←IsArray◶⟨0⊸≤×⌊⊸=,0⟩ ≠ ← (0<=)◶⟨1⋄0⊑≢⟩ # LIMITED to monadic case _fold←{ - "Argument to fold must be a list" ! 1==𝕩 + "´: 𝕩 must be a list" ! 1==𝕩 l←≠v←𝕩 ⋄ F←𝔽 r←𝕨 (0)⌜ 𝕨 + "𝕨⊏𝕩: Indices out of range" ! 1×´⥊ ((-l)⊸≤×l⊸>)⌜ 𝕨 ((⊢+l×0>⊢)⌜𝕨)(1==𝕩)◶{ c←1×´s←1 Cell 𝕩 𝕨((⥊𝕩)⊑˜c⊸×⊸+)⌜s⥊↕c @@ -127,12 +127,12 @@ SelSub←{ } Reverse ← { - "Reverse argument must have rank at least 1" ! 1≤=𝕩 + "⌽𝕩: 𝕩 must have rank at least 1" ! 1≤=𝕩 l←≠𝕩 ((l-1)⊸-⌜↕l) Select 𝕩 } Rot ← { - "Amount to rotate must be an integer" ! Int𝕨 + "𝕨⌽𝕩: 𝕨 must consist of integers" ! Int𝕨 l←≠𝕩 ⋄ 𝕨-↩l×⌊𝕨÷l ⋄ ((𝕨+⊢-l×(l-𝕨)≤⊢)⌜↕l) Select 𝕩 } @@ -164,11 +164,11 @@ Depth←IsArray◶0‿{1+0(⊣-≤×-)´Depth⌜⥊𝕩} _onAxes_←{ F←𝔽 (𝔾<≡)∘⊣◶{ # One axis - "First-axis function right argument must have rank at least 1" ! 1≤=𝕩 + "First-axis primitive: 𝕩 must have rank at least 1" ! 1≤=𝕩 𝕨F𝕩 }‿{ # Multiple axes - "Left argument must have rank at most 1" ! 1≥=𝕨 - "Left argument length must be at most right argument rank" ! 𝕨≤○≠≢𝕩 + "Multi-axis primitive: 𝕨 must have rank at most 1" ! 1≥=𝕨 + "Multi-axis primitive: length of 𝕨 must be at most rank of 𝕩" ! 𝕨≤○≠≢𝕩 l←≠𝕨 ⋄ W←⊑⟜(⥊𝕨) 0{(W𝕨)F(1+𝕨)⊸𝕊˘⍟(𝕨𝕩: Elements of 𝕩 must have matching shapes" ! 1×´(c≡≢)⌜⥊𝕩 𝕩⊑⟜Deshape˜⌜c⥊↕1×´c }⍟(0<≠∘⥊)⍟IsArray @@ -198,27 +198,27 @@ _sort ← {(𝕗⊑⟨Cmp,Cmp˜⟩)_grade_𝕗 ⊸ Select} > ↩ Merge ⊘ ((1-≤) _perv) ≠ ↩ ≠ ⊘ ((1-=) _perv) = ↩ = ⊘ (= _perv) -≥ ← ("No monadic form: ≥"!0˜) ⊘ (≥ _perv) -≤ ↩ ("No monadic form: ≤"!0˜) ⊘ (≤ _perv) +≥ ← ("≥: No monadic form"!0˜) ⊘ (≥ _perv) +≤ ↩ ("≤: No monadic form"!0˜) ⊘ (≤ _perv) + ↩ + _perv - ↩ - _perv ¬ ← 1+- -identity ← (0⊑⟨"Identity not found"!0˜⟩) {(0⊑𝕨){𝕗=𝕩}◶𝕩‿(1⊑𝕨)}´ ⟨+‿0,-‿0,×‿1,÷‿1,⋆‿1,√‿1,∧‿1,∨‿0,¬‿1,|‿0,⌊‿∞,⌈‿¯∞,<‿0,≤‿1,=‿1,≥‿1,>‿0,≠‿0⟩ +identity ← (0⊑⟨"´: Identity not found"!0˜⟩) {(0⊑𝕨){𝕗=𝕩}◶𝕩‿(1⊑𝕨)}´ ⟨+‿0,-‿0,×‿1,÷‿1,⋆‿1,√‿1,∧‿1,∨‿0,¬‿1,|‿0,⌊‿∞,⌈‿¯∞,<‿0,≤‿1,=‿1,≥‿1,>‿0,≠‿0⟩ Deshape←IsArray◶{⟨𝕩⟩}‿⥊ Reshape←{ - "Shape argument to Reshape must have rank at most 1" ! 1≥=𝕨 + "𝕨⥊𝕩: 𝕨 must have rank at most 1" ! 1≥=𝕨 s←Deshape 𝕨 sp←+´p←¬Nat⌜s - "Shape in Reshape must consist of natural numbers" ! 1≥sp + "𝕨⥊𝕩: 𝕨 must consist of natural numbers" ! 1≥sp n←≠d←Deshape 𝕩 l←sp◶(×´)‿{ lp←×´p⊣◶⊢‿1¨𝕩 - "Can't compute axis length in Reshape when rest of shape is empty" ! 00)+(-s)⌈s⌊𝕨)↑𝕩 } -Suffixes ← {"Suffixes argument must have rank at least 1"!1≤=𝕩 ⋄ Drop⟜𝕩⌜↕1+≠𝕩} +Suffixes ← {"↓𝕩: 𝕩 must have rank at least 1"!1≤=𝕩 ⋄ Drop⟜𝕩⌜↕1+≠𝕩} ↓ ← Suffixes ⊘ Drop Windows←{ - "Windows right argument must be an array" ! IsArray 𝕩 - "Windows left argument must have rank at most 1" ! 1≥=𝕨 - "Windows left argument length must be at most right argument rank" ! 𝕨≤○≠≢𝕩 - "Windows left argument must consist of natural numbers" ! ∧´Nat⌜⥊𝕨 + "𝕨↕𝕩: 𝕩 must be an array" ! IsArray 𝕩 + "𝕨↕𝕩: 𝕨 must have rank at most 1" ! 1≥=𝕨 + "𝕨↕𝕩: length of 𝕨 must be at most rank of 𝕩" ! 𝕨≤○≠≢𝕩 + "𝕨↕𝕩: 𝕨 must consist of natural numbers" ! ∧´Nat⌜⥊𝕨 s←(≠𝕨)↑≢𝕩 - "Window length must be at most axis length plus one" ! ∧´𝕨≤1+s + "𝕨↕𝕩: Window length 𝕨 must be at most axis length plus one" ! ∧´𝕨≤1+s 𝕨{(∾⟜(𝕨≠⊸↓≢𝕩)∘≢⥊>)<⌜⊸⊏⟜𝕩¨s(¬+⌜○Range⊢)⥊𝕨}⍟(0<≠𝕨)𝕩 } Rep ← Indices⊸⊏ -Replicate ← {0<=𝕨}◶{𝕨˘⊸Rep𝕩}‿{"Replicate argument lengths must match"!𝕨=○≠𝕩⋄𝕨Rep𝕩} _onAxes_ (1-0=≠) +Replicate ← {0<=𝕨}◶{𝕨˘⊸Rep𝕩}‿{"𝕨/𝕩: lengths of components of 𝕨 must match 𝕩"!𝕨=○≠𝕩⋄𝕨Rep𝕩} _onAxes_ (1-0=≠) ↕ ↩ Range ⊘ Windows ⌽ ← Reverse ⊘ (Rot _onAxes_ 0) @@ -319,35 +319,35 @@ Join←(1≠=)◶⟨∨´1≠=⌜,1⟩◶{ }‿{ # Multidimensional C←(<⟨⟩)⥊⊸∾⌜´⊢ # Cartesian array product - "Join argument must be an array" ! IsArray 𝕩 + "∾𝕩: 𝕩 must be an array" ! IsArray 𝕩 s←≢⌜𝕩 d←≠0⊑⥊s - "Join argument elements must all have the same rank" ! ∧´⥊d=≠⌜s - "Join argument element rank must be at least argument rank" ! d≥=𝕩 + "∾𝕩: elements of 𝕩 must all have the same rank" ! ∧´⥊d=≠⌜s + "∾𝕩: 𝕩 element rank must be at least argument rank" ! d≥=𝕩 l←(≢𝕩){(𝕩⊑⟜≢a Pick1˜(j=𝕩)⊸×)⌜↕𝕨}¨j←↕r←=a←𝕩 - "Join argument element shapes must be compatible" ! (r⊸↑⌜s)≡C l + "∾𝕩: 𝕩 element shapes must be compatible" ! (r⊸↑⌜s)≡C l i←C{p←+´⌜↑𝕩⋄(↕0⊑⌽p)-𝕩/¯1↓p}⌜l >i<⌜⊸⊏¨l/𝕩 }⍟(0<≠∘⥊) _group←{ - "Grouping argument must consist of integers" ! ∧´Int⌜𝕩 - "Grouping argument values cannot be less than ¯1" ! ∧´¯1≤𝕩 + "⊔: Grouping argument must consist of integers" ! ∧´Int⌜𝕩 + "⊔: Grouping argument values cannot be less than ¯1" ! ∧´¯1≤𝕩 d←(l←GroupLen𝕩)GroupOrd𝕩 i←0⋄(𝔽{𝕩⋄(i↩i+1)⊢i⊑d}⌜∘↕)⌜l } GroupInds←{ - "Group Indices argument must be a list" ! 1==𝕩 + "⊔𝕩: 𝕩 must be a list" ! 1==𝕩 G←⊢_group (1<≡)◶⟨G , (<<⟨⟩) ∾⌜⌜´ {⊏⟜(⥊↕≢𝕩)⌜ G⥊𝕩}⌜⟩ 𝕩 } GroupGen←{ - "Group right argument must be an array" ! IsArray 𝕩 + "𝕨⊔𝕩: 𝕩 must be an array" ! IsArray 𝕩 𝕨↩Pair∘ToArray⍟(2>≡)𝕨 - "Compound group left argument must be a list" ! 1==𝕨 + "𝕨⊔𝕩: Compound 𝕨 must be a list" ! 1==𝕨 n←+´=⌜𝕨 - "Group left argument total rank must be at most right argument rank" ! n≤=𝕩 - "Group argument lengths must be compatible" ! ∧´(Join≢⌜𝕨)=n↑≢𝕩 + "𝕨⊔𝕩: Total rank of 𝕨 must be at most rank of 𝕩" ! n≤=𝕩 + "𝕨⊔𝕩: Lengths of components of 𝕨 must be compatible with 𝕩" ! ∧´(Join≢⌜𝕨)=n↑≢𝕩 l←≠⌜𝕨↩⥊⌜𝕨 S←⊏⟜(𝕩⥊˜⟨×´l⟩∾n Cell 𝕩) (1≠≠)◶(S _group 0⊸⊑)‿(S⌜ ·+⌜⌜´ (⌽×`⟨1⟩∾⌽1↓l) × ⊢_group⌜) 𝕨 @@ -357,10 +357,10 @@ GroupGen←{ ⊔ ← GroupInds ⊘ GroupGen Pick1←{ - "Indices in compound Pick must be lists" ! 1==𝕨 - "Pick index length must match right argument rank" ! 𝕨=○≠s←≢𝕩 - "Pick indices must consist of integers" ! ∧´Int⌜𝕨 - "Pick index out of range" ! ∧´𝕨(≥⟜-∧<)s + "𝕨⊑𝕩: Indices in compound 𝕨 must be lists" ! 1==𝕨 + "𝕨⊑𝕩: Index length in 𝕨 must match rank of 𝕩" ! 𝕨=○≠s←≢𝕩 + "𝕨⊑𝕩: Indices in 𝕨 must consist of integers" ! ∧´Int⌜𝕨 + "𝕨⊑𝕩: Index out of range" ! ∧´𝕨(≥⟜-∧<)s 𝕨↩𝕨+s×𝕨<0 (⥊𝕩)⊑˜0(⊑⟜𝕨+⊑⟜s×⊢)´-↕⊸¬≠𝕨 } @@ -401,11 +401,11 @@ _binSearch ← { } _bins←{ c←1-˜=𝕨 - "Bins argument must have rank at least 1" ! 0≤c - "Bins right argument rank is too small" ! c≤=𝕩 + "⍋ or ⍒: Rank of 𝕨 must be at least 1" ! 0≤c + "⍋ or ⍒: Rank of 𝕩 must be at least cell rank of 𝕨" ! c≤=𝕩 lw←×´sw←1 Cell 𝕨 cw←lw 𝔽○(⊑⟜(⥊𝕨)) _getCellCmp 0 - "Bins left argument must be sorted" ! 0⊸<◶⟨1,∧´0≤˜·cw⟜(lw⊸+)⌜lw×↕∘-⟜1⟩≠𝕨 + "⍋ or ⍒: 𝕨 must be sorted" ! 0⊸<◶⟨1,∧´0≤˜·cw⟜(lw⊸+)⌜lw×↕∘-⟜1⟩≠𝕨 cx←c-˜=𝕩 sx←cx Cell 𝕩 ⋄ lc←sw CmpLen sx cc ← (⊑⟜(⥊𝕨))⊸𝔽⟜(⊑⟜(⥊𝕩)) _getCellCmp´ lc @@ -422,7 +422,7 @@ _search←{ # 0 for ∊˜, 1 for ⊐ red ← 𝕗⊑⟨¬∧˝,+˝∧`⟩ { c←1-˜=𝕨 - "Search principal argument must have rank at least 1" ! 0≤c + "p⊐𝕩 or 𝕨∊p: p must have rank at least 1" ! 0≤c 𝕨 ∧○(8<≠∘⥊)◶⟨ (0<≠𝕨)◶⟨0⎉c∘⊢, Red≢⌜○((0