From bbce87e26a262a2f442b86608bae06bfd42f3b0e Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 16 Oct 2020 13:01:19 -0400 Subject: First expression diagram --- docs/style.css | 8 ++++++-- docs/tutorial/expression.html | 45 ++++++++++++++++++++++++++++++++++++++----- svg.bqn | 4 ++++ tutorial/evalexp.bqn | 19 +++++++++++++----- tutorial/expression.md | 7 +++---- 5 files changed, 67 insertions(+), 16 deletions(-) diff --git a/docs/style.css b/docs/style.css index 4e208c47..2dc22dde 100644 --- a/docs/style.css +++ b/docs/style.css @@ -50,10 +50,13 @@ pre, code, textarea, .kb { border: 1px solid #bdcac4; letter-spacing: 0.2; } -.code { +.code, .codeCover { fill: #e3e7e7; stroke: #bdcac4; } +.codeCover { + stroke: #e3e7e7; +} code { padding: 0.15em 0.1em 0.05em; white-space: nowrap; @@ -123,7 +126,8 @@ a:visited { color: #3d155f; } input { border-color: #0c0d0e; } textarea, pre, code { color: #969698; background-color: #0c0d0e; } textarea, pre, code, .kb { border-color: #040509; } - .code { fill: #0c0d0e; stroke: #040509; } + .code, .codeCover { fill: #0c0d0e; stroke: #040509; } + .codeCover { stroke: #0c0d0e; } code { border-color: #0c0d0e; background-color: #0f1011; } table td, th{ border-color: #636967; } table th { border-color: #88918c; background-color: #292a2b; } diff --git a/docs/tutorial/expression.html b/docs/tutorial/expression.html index 5dfa2251..1f14e90b 100644 --- a/docs/tutorial/expression.html +++ b/docs/tutorial/expression.html @@ -60,11 +60,46 @@ 33.5103216382911

The evaluation order is shown below, with the function on the first line evaluated first, then × on the next, and so on. The effect of the parentheses is that ÷ is evaluated before the leftmost ×.

-
 =              23
-            π ×
-     4÷3
-    (   ) ×
-
+ + + + (4÷3) × π × 23 + + + + + + + + + + + + 4 + ÷ + 3 + × + π + × + 2 + + 3 + + + 4 + ÷ + 3 + × + π + × + 2 + + 3 + + + + +

The following rule might help you to internalize this system in addition to identifying when parentheses are needed: an expression never needs to end with a parenthesis, or contain two closing parentheses in a row. If it does, at least one set of parentheses can be removed.

One or two arguments?

What about functions without a left argument? Let's find an equation with lots of square roots in it… looks good.

diff --git a/svg.bqn b/svg.bqn index ae7b12de..f419acd3 100644 --- a/svg.bqn +++ b/svg.bqn @@ -36,6 +36,10 @@ Fmt ← (2⌊≡)◶FmtNum‿(1↓·∾(' '∾FmtNum)¨)‿{𝕩⋄!0} Attr ← { 𝕨 ∾ ∾ {<∾⟨" ",𝕨,"='",𝕩,"'"⟩}´⎉1 𝕩 } +At ← { + _s ← {((+`׬)⊸-𝕗⊸=)⊸⊔} + 𝕨 ⊢⊘Attr >'='_s¨ '|'_s 𝕩 +} Pos ← ⟨"x","y"⟩ ≍˘ FmtNum¨ Elt ← Void∘Attr diff --git a/tutorial/evalexp.bqn b/tutorial/evalexp.bqn index 304301e5..5d922af1 100644 --- a/tutorial/evalexp.bqn +++ b/tutorial/evalexp.bqn @@ -1,10 +1,17 @@ wh ← 10.75‿24 -pad← wh×1.5‿1 +pad← wh×2‿1 t ← 10 -ps ← >⟨"stroke"‿"#585552","style"‿"fill:none","stroke-width"‿"2"⟩ -rc ← >⟨"class"‿"code","stroke-width"‿"1","rx"‿"12"⟩ -gr ← "g" Attr >⟨"font-family"‿"BQN,monospace", "font-size"‿"18px"⟩ +ps ← At "class=Paren|stroke=currentColor|fill=none|stroke-width=1" +rc ← At "class=code|stroke-width=1|rx=10" +gr ← "g" At "font-family=BQN,monospace|font-size=18px" +gt ← "g" At "text-anchor=middle" +gb ← "g" At "class=codeCover|stroke-width=6|stroke-linejoin=round" +gf ← "g" At "font-size=15px|opacity=0.9" +Shadow ← { + t ← (⟨0,0‿¯2⟩+⌜𝕨) ("text" Attr Pos)⊸Enc¨ (⊢≍Highlight¨) ⥊¨𝕩 + gt Enc ⟨gb,gf⟩ Enc¨<˘ t +} DrawEval←{ ix←𝕩⊏˜i←/𝕩≠' ' @@ -18,12 +25,14 @@ DrawEval←{ m←1+⌈´d←+`⊸×⌾(rev⊸⊏)fn pt ← f/⍉> wh×⟨i,d⟩ - off← (o ⊏ ∾⟜(whׯ1‿m))⊸- pt + off← (o ⊏ ∾⟜(whׯ1.25‿m))⊸- pt pd ← pt (<(wh×0.6‿0.1)⊸+)⊸∾⟜⌽˘ off dim← (wh×⟨≠𝕩,2+m⟩)+2‿0×pad + tp ← <˘pt+(1+wh÷2‿3)+⎉1(0‿1×⌜˜f/¬fn)×off (512‿0⊸⌈⊸(⊣∾˜(t+pad)-˜-˜÷2˙)dim+2×t) SVG gr Enc ∾⥊¨⟨ <"rect" Elt rc∾(Pos-pad)∾"width"‿"height"≍˘FmtNum¨dim <"text" Enc Highlight 𝕩 (<"path" Elt ps∾"d"≍○<·∾"Mvh"∾⟜Fmt¨⊢)˘ pd + The following rule might help you to internalize this system in addition to identifying when parentheses are needed: an expression never needs to end with a parenthesis, or contain two closing parentheses in a row. If it does, at least one set of parentheses can be removed. -- cgit v1.2.3