aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/bqn.js4
-rw-r--r--md.bqn62
-rw-r--r--src/fmt.bqn13
3 files changed, 14 insertions, 65 deletions
diff --git a/docs/bqn.js b/docs/bqn.js
index c7f7082e..8bc75e62 100644
--- a/docs/bqn.js
+++ b/docs/bqn.js
@@ -164,9 +164,9 @@ let fmt0 = x =>
(x.glyph||(x.m?"*"+x.m+"-modifier*":"*function*"))
: ""+x;
let fmt1 = run(
- new Uint8Array([0,46,22,0,0,11,14,15,1,25,21,0,4,22,0,5,11,14,0,9,0,7,0,43,19,0,38,15,2,8,22,0,6,11,14,15,3,22,0,7,11,14,21,0,6,0,33,21,0,7,8,22,0,8,11,14,15,4,22,0,9,11,14,21,0,9,15,5,3,2,0,36,15,6,8,22,0,10,11,14,0,56,0,17,0,55,17,15,7,15,8,3,2,0,36,0,8,0,9,0,42,19,0,6,0,9,0,8,0,43,19,19,8,3,2,0,36,0,12,0,12,0,42,0,42,3,2,19,8,22,0,11,11,14,15,9,0,35,15,10,8,22,0,12,11,14,15,11,22,0,13,11,14,0,13,0,16,0,16,19,0,32,0,61,8,21,0,5,3,2,0,36,0,40,0,33,0,10,8,8,0,17,9,15,12,21,0,13,3,3,0,36,0,11,0,3,0,43,19,8,22,0,14,11,14,21,0,1,21,0,14,16,0,26,21,1,0,0,33,0,16,8,7,16,0,15,16,0,19,0,39,17,25,21,0,1,0,12,16,0,19,0,39,17,22,0,3,11,14,0,41,0,27,0,18,7,21,0,3,0,4,0,41,17,0,1,16,17,0,20,0,34,0,31,0,25,0,28,0,2,7,7,7,8,16,0,29,0,39,0,40,3,2,0,37,0,0,8,7,16,0,15,16,22,0,4,11,14,21,0,4,0,23,0,32,0,39,8,0,34,0,42,8,16,22,0,4,12,14,15,13,22,0,5,11,14,21,0,1,0,15,21,0,1,0,12,16,0,23,0,39,17,0,16,21,0,3,0,29,0,2,7,16,17,17,21,0,5,0,18,0,32,0,29,0,0,7,8,3,2,0,36,21,0,3,0,24,0,42,17,0,23,16,8,21,0,4,17,25,21,0,1,0,13,0,41,0,37,0,16,8,0,41,0,37,0,16,8,19,0,47,0,21,21,0,2,17,17,25,0,49,0,16,21,0,1,0,22,16,0,19,0,41,17,0,19,0,39,17,17,0,16,0,48,17,0,17,16,25,21,0,1,0,12,16,0,23,0,39,17,22,0,3,11,14,0,51,21,0,2,0,14,0,3,0,41,19,0,25,0,22,7,0,52,19,0,15,9,21,1,5,3,2,0,36,0,7,0,32,0,44,8,8,16,3,2,0,16,16,0,18,0,41,21,0,3,3,2,17,21,0,1,0,23,0,34,0,53,0,23,0,41,0,1,21,0,2,17,0,4,0,42,17,0,3,0,45,17,17,8,16,0,54,0,18,21,0,3,0,1,16,0,16,0,41,17,17,3,3,0,16,16,25,21,0,1,0,22,16,0,28,0,9,7,0,50,17,0,30,0,1,7,16,0,31,0,0,7,16,0,24,0,43,17,0,23,16,0,6,21,0,1,0,8,16,0,8,0,41,17,17,0,6,21,0,2,0,8,0,41,17,17,25,21,0,1,0,27,0,47,7,16,21,1,7,0,41,17,21,1,10,0,43,17,0,23,0,32,0,42,0,39,3,2,8,0,34,0,57,8,16,25,21,0,1,0,12,16,0,58,0,27,21,1,5,7,0,27,0,60,0,33,0,16,8,7,9,0,16,9,0,23,0,32,0,39,8,0,34,0,59,8,9,3,2,0,36,0,8,0,7,0,41,19,8,16,0,25,0,16,7,0,50,17,0,17,16,25,21,0,1,0,27,0,12,7,16,22,0,3,11,14,21,0,3,0,27,0,23,7,0,41,17,0,15,0,25,0,41,7,0,1,0,9,19,0,38,0,30,0,4,7,8,3,2,0,36,0,9,0,7,0,42,19,8,16,22,0,4,11,14,21,0,3,0,27,0,23,7,16,0,9,0,7,0,42,19,0,38,0,41,0,37,0,30,0,4,7,8,8,16,22,0,5,11,14,21,0,1,0,27,0,18,7,0,41,0,18,21,0,4,0,8,16,0,2,21,0,2,17,0,1,16,17,0,5,21,0,4,17,0,2,21,0,2,17,0,28,0,16,7,21,0,5,17,17,0,9,0,1,0,43,19,0,4,0,42,19,0,38,0,17,8,16,0,43,0,37,0,16,8,16,25,21,0,1,21,1,12,0,41,17,25,21,0,1,0,27,21,1,14,7,16,21,1,12,21,0,2,17,21,1,8,0,43,17,21,1,10,21,0,1,0,9,16,17,25,0,40,0,10,21,0,1,17,22,0,3,11,14,21,0,1,0,9,16,22,0,4,11,14,21,0,1,15,14,15,15,15,16,3,3,0,36,21,0,3,0,15,16,0,29,0,0,7,0,10,0,0,0,7,0,32,0,42,8,19,0,8,19,16,8,16,25,21,0,2,0,0,0,41,17,0,21,16,22,0,3,11,14,0,47,0,15,21,0,1,0,12,16,0,23,0,39,17,17,0,16,21,0,1,17,0,22,21,0,3,0,21,0,32,21,0,3,0,24,16,0,5,16,8,0,34,0,27,0,39,7,8,16,17,25,21,0,1,0,12,16,0,19,0,39,17,22,0,3,11,0,8,16,0,1,16,0,9,0,32,0,42,8,0,38,0,40,8,16,22,0,4,11,14,0,62,22,0,5,11,14,21,0,1,0,9,0,9,0,41,19,0,38,0,21,0,32,0,14,0,9,21,0,5,19,0,0,0,41,19,8,8,16,22,0,1,12,14,21,0,5,0,18,21,0,3,17,0,15,0,34,0,20,8,16,21,0,4,0,37,0,16,8,21,0,1,17,21,0,4,0,37,0,16,8,21,0,5,0,18,21,0,3,17,17,0,17,16,21,1,4,0,8,0,41,17,0,38,21,2,6,21,2,7,0,41,19,21,2,10,21,1,4,19,8,16,25,21,0,1,21,2,13,21,2,11,3,2,0,36,0,12,0,9,0,42,19,0,29,0,6,7,9,8,16,25,21,0,1,21,2,13,0,39,17,25])
+ new Uint8Array([15,1,25,21,0,4,22,0,5,11,14,0,46,22,0,6,11,14,0,9,0,7,0,43,19,0,38,15,2,8,22,0,7,11,14,15,3,22,0,8,11,14,21,0,7,0,33,21,0,8,8,22,0,9,11,14,15,4,22,0,10,11,14,21,0,10,15,5,3,2,0,36,15,6,8,22,0,11,11,14,0,56,0,17,0,55,17,15,7,15,8,3,2,0,36,0,8,0,9,0,42,19,0,6,0,9,0,8,0,43,19,19,8,3,2,0,36,0,12,0,12,0,42,0,42,3,2,19,8,22,0,12,11,14,15,9,0,35,15,10,8,22,0,13,11,14,15,11,22,0,14,11,14,0,13,0,16,0,16,19,0,32,0,61,8,21,0,5,3,2,0,36,0,40,0,33,0,10,8,8,0,17,9,15,12,21,0,14,3,3,0,36,0,11,0,3,0,43,19,8,22,0,15,11,14,21,0,1,21,0,15,16,0,26,21,0,6,0,33,0,16,8,7,16,0,15,16,0,19,0,39,17,25,21,0,1,0,12,16,0,19,0,39,17,22,0,3,11,14,0,41,0,27,0,18,7,21,0,3,0,4,0,41,17,0,1,16,17,0,20,0,34,0,31,0,25,0,28,0,2,7,7,7,8,16,0,29,0,39,0,40,3,2,0,37,0,0,8,7,16,0,15,16,22,0,4,11,14,21,0,4,0,23,0,32,0,39,8,0,34,0,42,8,16,22,0,4,12,14,15,13,22,0,5,11,14,21,0,1,0,15,21,0,1,0,12,16,0,23,0,39,17,0,16,21,0,3,0,29,0,2,7,16,17,17,21,0,5,0,18,0,32,0,29,0,0,7,8,3,2,0,36,21,0,3,0,24,0,42,17,0,23,16,8,21,0,4,17,25,21,0,1,0,13,0,41,0,37,0,16,8,0,41,0,37,0,16,8,19,0,47,0,21,21,0,2,17,17,25,0,49,0,16,21,0,1,0,22,16,0,19,0,41,17,0,19,0,39,17,17,0,16,0,48,17,0,17,16,25,21,0,1,0,12,16,0,23,0,39,17,22,0,3,11,14,0,51,21,0,2,0,14,0,3,0,41,19,0,25,0,22,7,0,52,19,0,15,9,21,1,5,3,2,0,36,0,7,0,32,0,44,8,8,16,3,2,0,16,16,0,18,0,41,21,0,3,3,2,17,21,0,1,0,23,0,34,0,53,0,23,0,41,0,1,21,0,2,17,0,4,0,42,17,0,3,0,45,17,17,8,16,0,54,0,18,21,0,3,0,1,16,0,16,0,41,17,17,3,3,0,16,16,25,21,0,1,0,22,16,0,28,0,9,7,0,50,17,0,30,0,1,7,16,0,31,0,0,7,16,0,24,0,43,17,0,23,16,0,6,21,0,1,0,8,16,0,8,0,41,17,17,0,6,21,0,2,0,8,0,41,17,17,25,21,0,1,0,27,0,47,7,16,21,1,8,0,41,17,21,1,11,0,43,17,0,23,0,32,0,42,0,39,3,2,8,0,34,0,57,8,16,25,21,0,1,0,12,16,0,58,0,27,21,1,5,7,0,27,0,60,0,33,0,16,8,7,9,0,16,9,0,23,0,32,0,39,8,0,34,0,59,8,9,3,2,0,36,0,8,0,7,0,41,19,8,16,0,25,0,16,7,0,50,17,0,17,16,25,21,0,1,0,27,0,12,7,16,22,0,3,11,14,21,0,3,0,27,0,23,7,0,41,17,0,15,0,25,0,41,7,0,1,0,9,19,0,38,0,30,0,4,7,8,3,2,0,36,0,9,0,7,0,42,19,8,16,22,0,4,11,14,21,0,3,0,27,0,23,7,16,0,9,0,7,0,42,19,0,38,0,41,0,37,0,30,0,4,7,8,8,16,22,0,5,11,14,21,0,1,0,27,0,18,7,0,41,0,18,21,0,4,0,8,16,0,2,21,0,2,17,0,1,16,17,0,5,21,0,4,17,0,2,21,0,2,17,0,28,0,16,7,21,0,5,17,17,0,9,0,1,0,43,19,0,4,0,42,19,0,38,0,17,8,16,0,43,0,37,0,16,8,16,25,21,0,1,21,1,13,0,41,17,25,21,0,1,0,27,21,1,15,7,16,21,1,13,21,0,2,17,21,1,9,0,43,17,21,1,11,21,0,1,0,9,16,17,25,0,40,0,10,21,0,1,17,22,0,3,11,14,21,0,1,0,9,16,22,0,4,11,14,21,0,1,15,14,15,15,15,16,3,3,0,36,21,0,3,0,15,16,0,29,0,0,7,0,10,0,0,0,7,0,32,0,42,8,19,0,8,19,16,8,16,25,21,0,2,0,0,0,41,17,0,21,16,22,0,3,11,14,0,47,0,15,21,0,1,0,12,16,0,23,0,39,17,17,0,16,21,0,1,17,0,22,21,0,3,0,21,0,32,21,0,3,0,24,16,0,5,16,8,0,34,0,27,0,39,7,8,16,17,25,21,0,1,0,12,16,0,19,0,39,17,22,0,3,11,0,8,16,0,1,16,0,9,0,32,0,42,8,0,38,0,40,8,16,22,0,4,11,14,0,62,22,0,5,11,14,21,0,1,0,9,0,9,0,41,19,0,38,0,21,0,32,0,14,0,9,21,0,5,19,0,0,0,41,19,8,8,16,22,0,1,12,14,21,0,5,0,18,21,0,3,17,0,15,0,34,0,20,8,16,21,0,4,0,37,0,16,8,21,0,1,17,21,0,4,0,37,0,16,8,21,0,5,0,18,21,0,3,17,17,0,17,16,21,1,4,0,8,0,41,17,0,38,21,2,7,21,2,8,0,41,19,21,2,11,21,1,4,19,8,16,25,21,0,1,21,2,14,21,2,12,3,2,0,36,0,12,0,9,0,42,19,0,29,0,6,7,9,8,16,25,21,0,1,21,2,14,0,39,17,25])
,[runtime[0],runtime[1],runtime[2],runtime[6],runtime[7],runtime[9],runtime[11],runtime[12],runtime[14],runtime[15],runtime[16],runtime[18],runtime[19],runtime[20],runtime[21],runtime[22],runtime[23],runtime[24],runtime[25],runtime[26],runtime[28],runtime[30],runtime[33],runtime[34],runtime[37],runtime[41],runtime[42],runtime[43],runtime[44],runtime[46],runtime[47],runtime[48],runtime[51],runtime[52],runtime[53],runtime[54],runtime[55],runtime[56],runtime[58],-1,Infinity,1,0,2,5,4,'\n',str(" "),str("⟨"),str("⟩"),str("⟨⟩"),str("┌"),str("·─"),str("·╵╎┆┊"),str("┘"),str("┌┐"),str("└┘"),'┐',str(""),'⥊',str("‿"),str("'"),'"']
- ,[[0,1,0,1],[1,0,10,15],[0,0,233,6],[0,0,399,3],[0,0,429,3],[0,0,459,4],[0,0,583,3],[0,0,643,3],[0,0,682,3],[0,0,748,6],[0,0,923,3],[0,0,933,3],[0,0,967,5],[0,0,1034,4],[0,0,1102,6],[0,0,1264,3],[0,0,1293,3]]
+ ,[[0,1,0,0],[1,0,3,16],[0,0,233,6],[0,0,399,3],[0,0,429,3],[0,0,459,4],[0,0,583,3],[0,0,643,3],[0,0,682,3],[0,0,748,6],[0,0,923,3],[0,0,933,3],[0,0,967,5],[0,0,1034,4],[0,0,1102,6],[0,0,1264,3],[0,0,1293,3]]
)(a=>str(fmt0(a)));
let fmt = x => fmt1(x).map(c=>c===0?" ":c).join("");
diff --git a/md.bqn b/md.bqn
index bc6c9d8e..e2b65992 100644
--- a/md.bqn
+++ b/md.bqn
@@ -545,66 +545,8 @@ GetMultiHighlights ← {
################################
# Format an array to a character matrix
# Won't work on functions until we can catch errors
-Fmt ← {
- # Vertical padding for arrays of rank greater than 2
- PadV ← {
- # Leading shape
- ls ← ¯1↓≢𝕩
- # Empty lines after each row: 1 if it's at the end of a 2-cell, plus
- # 1 if it's at the end of a 2-cell and a 3-cell, and so on
- p ← ⥊ +⎉¯1‿∞´ ×⌜˜`⌾⌽ (-1⌈ls)↑¨1
- # But none at the very end
- p ↩ 0⌾(¯1⊸⊑) p
- Pad ← {i←/1+𝕨 ⋄ (¯1¨⌾((¬∊i)⊸/)i) ⊏ 𝕩∾(¯1⊑≢𝕩)⥊" "}
- p (⊑0∊ls)◶⟨Pad,+´⊸↑⟩ ((×´ls)∾¯1⊑≢𝕩) ⥊ 𝕩
- }⍟(2 < =)
- # Horizontal padding: just some spaces on either side
- PadH ← {
- (𝕨/" ") (∾⎉1∾⎉1⊣) 𝕩
- }
- Pad ← PadH⟜PadV
- Enframe ← {(1≠𝕨)∨(1≠≠𝕩)∨⊑2∊+`-˝"⟨⟩"=⌜⊏𝕩}◶{
- ≍"⟨"∾(¯1↓1↓⊏𝕩)∾"⟩"
- }‿{
- l ← ¯1 ⊑ ≢𝕩
- ∾ ⟨ # "┼╒╛╪"
- 1‿l↑∾⟨"┌",(5⊸<)◶⟨⥊"·─"⊏˜1⌊⊢,⍕⟩𝕨⟩
- ((4⌊0⌈𝕨-1)⊑"·╵╎┆┊")⌾⊑ 𝕩
- (1∾-l)↑"┘"
- ⟩
- }
- FmtEmpty ← (0‿0≢≢)◶("┌┐"≍"└┘")‿(((2≠=)∨0=≠)◶{
- '┐'⌾(0‿¯1⊸⊑) 2 Enframe 1 PadH " "¨𝕩
- }‿{
- ≍"⟨⟩"∾˜(1<≠)◶⟨"",'⥊'⌾(¯1⊸⊑)·∾·∾⟜"‿"¨⍕¨⟩≢𝕩
- })
- PaddingJoin ← {1𝕊𝕩;
- s ← ≢¨ 𝕩
- w ← ⌈˝⍟(=-1˜)1⊑¨s
- h ← ⌈˝⎉1 ⊑¨s
- ∾⎉2 ≍⍟(0⌈2-=) (h ∾⌜ 𝕨×w¬(-𝕨×≠w)↑1) ↑¨ 𝕩
- }
- FmtMixed ← {
- (=𝕩) Enframe 2 Pad 𝕨 PaddingJoin F¨𝕩
- }
- F ← (2⌊≡)◶(≍≤⟜∞◶⟨"'"⊸(∾∾⊣),⍕⟩)‿{
- num ← 𝕩≤∞ ⋄ r ← =𝕩
- ((≠(0⊸<+≤)+´)⥊num)◶{
- # All characters
- k ← -≠ c ← ¯1↓≢𝕩
- q ← '"'
- 𝕩 ↩ (1+q=⊢)⊸/⍟(k=0) 𝕩
- (r Enframe 1 PadH PadV)⍟(1≠r) ≍ (c↑q) ∾⎉k 𝕩 ∾⎉k ⌽⌾⥊c↑q
- }‿{
- # Not homogeneous, or empty
- (∨´0=≢)◶FmtMixed‿FmtEmpty 𝕩
- }‿{
- # All numbers
- ¯1 FmtMixed 𝕩
- } 𝕩
- }‿FmtMixed
- F 𝕩
-}
+fmtm ← ⟨•path∾"src/fmt.bqn"⟩ •EX •path∾"dzref"
+Fmt ← ⍕ _fmtm
################################
diff --git a/src/fmt.bqn b/src/fmt.bqn
index 7869b4a2..d5b3d355 100644
--- a/src/fmt.bqn
+++ b/src/fmt.bqn
@@ -1,14 +1,21 @@
-lf←'
-'
+# Format an array to a character matrix
{
- F0←𝔽
+ F0←𝔽 # Function to format a scalar
+ lf←'
+'
+ # Vertical padding for arrays of rank greater than 2
PadV ← {
+ # Leading shape
ls ← ¯1↓≢𝕩
+ # Empty lines after each row: 1 if it's at the end of a 2-cell, plus
+ # 1 if it's at the end of a 2-cell and a 3-cell, and so on
p ← ⥊ +⎉¯1‿∞´ ×⌜˜`⌾⌽ (-1⌈ls)↑¨1
+ # But none at the very end
p ↩ 0⌾(¯1⊸⊑) p
Pad ← {i←/1+𝕨 ⋄ (¯1¨⌾((¬∊i)⊸/)i) ⊏ 𝕩∾(¯1⊑≢𝕩)⥊" "}
p (⊑0∊ls)◶⟨Pad,+´⊸↑⟩ ((×´ls)∾¯1⊑≢𝕩) ⥊ 𝕩
}⍟(2 < =)
+ # Horizontal padding: just some spaces on either side
PadH ← {
(𝕨/" ") (∾⎉1∾⎉1⊣) 𝕩
}