aboutsummaryrefslogtreecommitdiff
path: root/tutorial
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-16 13:01:19 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-16 13:24:13 -0400
commitbbce87e26a262a2f442b86608bae06bfd42f3b0e (patch)
tree5182dc737638b329787ee130277c09d825b57e86 /tutorial
parentd1813495bce24c37049abdca553bfb184f3ab753 (diff)
First expression diagram
Diffstat (limited to 'tutorial')
-rw-r--r--tutorial/evalexp.bqn19
-rw-r--r--tutorial/expression.md7
2 files changed, 17 insertions, 9 deletions
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
+ <tp Shadow f/ix
}
diff --git a/tutorial/expression.md b/tutorial/expression.md
index 59fe827c..39738d51 100644
--- a/tutorial/expression.md
+++ b/tutorial/expression.md
@@ -57,10 +57,9 @@ For a longer example, here's an expression for the [volume of a sphere](https://
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 `×`.
- = 2⋆3
- π ×
- 4÷3
- ( ) ×
+<!--SVG evalexp.bqn
+DrawEval "(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.