From bb8ea349f336c5fbdc1ffc8c3809aca7d00aadd2 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 30 Apr 2022 22:02:39 -0400 Subject: Try to reduce formatted size of array elements if necessary --- src/f.bqn | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'src/f.bqn') diff --git a/src/f.bqn b/src/f.bqn index 859c5fff..c00b43a5 100644 --- a/src/f.bqn +++ b/src/f.bqn @@ -46,19 +46,28 @@ ≍(1<≠)◶⟨"⟨⟩",'↕'⌾⊑·∾·"‿"⊸∾¨FN¨⟩≢𝕩 }) - PaddingJoin ← { + _paddingJoin ← { # 𝕗 is 1 to left align and ¯1 to right align s ← ≢¨ 𝕩 w ← (0<=)◶⟨⥊,⌈˝⍟(=-1˙)⟩1⊑¨s h ← ⌈˝⎉1⍟(0<=) ⊑¨s - o ← <∘∾⎉2 ≍⍟(0⌈2-=) (h ≍⌜ 𝕨×w¬(-𝕨×≠w)↑1) ↑¨ 𝕩 + o ← <∘∾⎉2 ≍⍟(0⌈2-=) (h ⋈⌜ 𝕗×w¬(-𝕗×≠w)↑1) ↑¨ 𝕩 2 PadH (1⊸⌽⊸≡⥊h)◶⟨PadVMixed,PadV∘>⟩ o } - FmtMixed ← { - (=𝕩) Enframe (𝕨⊣1) PaddingJoin Fmt¨𝕩 + _fmtMixedP ← { + r ← =𝕩 + Join ← r Enframe 𝕗 _paddingJoin + 𝕨 (∨´<⟜∞)◶(Join <⊸(Fmt¨))‿{ + p ← ⟨r>1,2⟩ # Outer padding + o ← ¯1((0+⌜´(1(1+×)`⊢)⌾⌽×↕¨)∘↓⋈⌜2×↕∘⊑)≢𝕩 # Offset + E ← (1‿1⥊'…')˙ + f ← o (𝕨-p)⊸-⊸(⊣ E∘⊢⍟(∨´<⟜≢) (∨´≤⟜0)◶Fmt‿E)¨ 𝕩 + Join f + } 𝕩 } + FmtMixed ← 1 _fmtMixedP - FmtSimple ← (≠(0⊸<+≤)+´)∘(⥊<@˙)◶{ # Depth 1 + FmtSimple ← (≠(0⊸<+≤)+´)∘(⥊<@˙)∘⊢◶{ # Depth 1 # All characters r ← =𝕩 ⋄ 𝕩 ↩ ><¨0↓𝕩 # Ensure rank>0 and ' ' for fill k ← ∞⍟(0⊸=) -≠ c ← ¯1↓≢𝕩 @@ -70,14 +79,18 @@ (r Enframe 1 PadH PadV)⍟(1≠r) ≍ (q⌾⊑c⥊(¯1⊑1∾c)↑'·') ∾⎉k 𝕩 ∾⎉k c-⊸↑q }‿{ # Not homogeneous, or empty - (∨´0=≢)◶FmtMixed‿FmtEmpty 𝕩 + (∨´0=≢)◶⟨𝕨⊸FmtMixed,FmtEmpty⟩ 𝕩 }‿{ # All numbers - ¯1 FmtMixed 𝕩 + 𝕨 ¯1 _fmtMixedP 𝕩 } # Format data type - FmtDat ← (2⌊≡)◶⟨≍ReprAtom,(∨´∘⥊3≤Type⌜)◶FmtSimple‿FmtMixed,FmtMixed⟩ + FmtDat ← (2⌊≡∘⊢)◶⟨ + ≍ ReprAtom∘⊢ + (∨´∘⥊3≤Type⌜∘⊢)◶FmtSimple‿FmtMixed + FmtMixed + ⟩ # Format part of a compound operation; return precedence‿string _dispOp_ ← { @@ -94,15 +107,19 @@ FmtOp ← ≍1⊑ (1=≠)◶⟨arr,⊏⟩∘FmtDat _dispOp_ (=⟜2◶⟨FF⊑∘⊢,arr⟩) # Format any value to character matrix - Fmt ← Type (3≤⊣)◶⟨FmtDat⊢,FmtOp⟩ ⊢ + Fmt ← { + t ← Type𝕩 + 𝕨 (3≤t)◶⟨FmtDat,t⊸FmtOp⟩ 𝕩 + } Trunc ← { + c ← 𝕨