From f6a7c636f8187a8e324901e6671d04c759d5e4c7 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 2 Oct 2020 20:37:08 -0400 Subject: Simplify vertical padding when formatting --- src/fmt.bqn | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/fmt.bqn b/src/fmt.bqn index def46f58..61bd8639 100644 --- a/src/fmt.bqn +++ b/src/fmt.bqn @@ -1,7 +1,7 @@ # Format an array to a string including newlines { - F0←𝔽 # Function to format an atom - FmtAtom ← (≍ <⟜@β—ΆβŸ¨@βŠΈβ‰ β—ΆβŸ¨"@","'"⊸(∾∾⊣)⟩,F0⟩) + F0←𝔽 # Format a number or operation to a string + FmtAtom ← ≍ <⟜@β—ΆβŸ¨@βŠΈβ‰ β—ΆβŸ¨"@","'"⊸(∾∾⊣)⟩,F0⟩ # Vertical padding for arrays of rank greater than 2 PadV ← { @@ -12,8 +12,10 @@ 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βŠ‘β‰’π•©) β₯Š 𝕩 + # If 𝕩 has cells, pad by selection; if it's empty, there are only + # pads but selection would try to get cells (1⌈ above), so overtake. + Pad ← {(»⊸<βŠΈΓ—/0∾1+𝕨) ⊏ ' 'Β¨βˆ˜βŠβŠΈβˆΎπ•©} + p (0<β‰ βˆ˜βŠ’)β—ΆβŸ¨+Β΄βŠΈβ†‘,Pad⟩ ((Γ—Β΄ls)∾¯1↑≒𝕩) β₯Š 𝕩 }⍟(2 < =) # Horizontal padding: just some spaces on either side @@ -30,7 +32,7 @@ l ← Β―1 βŠ‘ ≒𝕩 ∾ ⟨ ≍lβ†‘βˆΎβŸ¨"β”Œ",(5⊸<)β—ΆβŸ¨β₯Š"·─"⊏˜1⌊⊒,F0βŸ©π•¨βŸ© - ((4⌊0βŒˆπ•¨-1)βŠ‘"Β·β•΅β•Žβ”†β”Š")βŒΎβŠ‘ 𝕩 + ((0⌈4βŒŠπ•¨-1)βŠ‘"Β·β•΅β•Žβ”†β”Š")βŒΎβŠ‘ 𝕩 ≍l-βŠΈβ†‘"β”˜" ⟩ } -- cgit v1.2.3