From eecbb6875af7dcc40d016eae596bf508e9a3ae57 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 20 Jul 2020 14:54:19 -0400 Subject: Don't print assignment results when auto-running code --- docs/doc/group.html | 15 --------------- md.bqn | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/docs/doc/group.html b/docs/doc/group.html index 8a562285..88e02f29 100644 --- a/docs/doc/group.html +++ b/docs/doc/group.html @@ -18,9 +18,6 @@ a b c d e

For example, we might choose to group a list of words by length. Within each group, cells maintain the ordering they had in the list originally.

    phrase  "BQN""uses""notation""as""a""tool""of""thought"
-┌───┬────┬────────┬──┬─┬────┬──┬───────┐
-│BQN│uses│notation│as│a│tool│of│thought│
-└───┴────┴────────┴──┴─┴────┴──┴───────┘
     ˘ ¨ phrase
 ┌───────────┐
 │⟨⟩         │
@@ -126,13 +123,7 @@ caeb
 

Applications

The obvious application of Group is to group some values according to a known or computed property. If this property isn't an integer, it can be turned into one using Unique and Index Of (the combination has been called "self-classify").

    ln  "Phelps""Latynina""Bjørgen""Andrianov""Bjørndalen"
-┌──────┬────────┬───────┬─────────┬──────────┐
-│Phelps│Latynina│Bjørgen│Andrianov│Bjørndalen│
-└──────┴────────┴───────┴─────────┴──────────┘
     co  "US"    "SU"      "NO"     "SU"       "NO"
-┌──┬──┬──┬──┬──┐
-│US│SU│NO│SU│NO│
-└──┴──┴──┴──┴──┘
     ˘ co  ln
 ┌────────────────────┐
 │┌──────┐            │
@@ -150,9 +141,6 @@ caeb
 

If we would like a particular index to key correspondence, we can use a fixed left argument to Index Of.

    countries  "IT""JP""NO""SU""US"
-┌──┬──┬──┬──┬──┐
-│IT│JP│NO│SU│US│
-└──┴──┴──┴──┴──┘
     countries ˘ co countries ln
 ┌──┬────────────────────┐
 │IT│⟨⟩                  │
@@ -174,9 +162,6 @@ caeb
 

However, this solution will fail if there are trailing keys with no values. To force the result to have a particular length you can append that length as a dummy index to each argument, then remove the last group after grouping.

    countries  "IT""JP""NO""SU""US""ZW"
-┌──┬──┬──┬──┬──┬──┐
-│IT│JP│NO│SU│US│ZW│
-└──┴──┴──┴──┴──┴──┘
     countries ˘ co countries{𝕗(¯1↓⊔((𝕗)))} ln
 ┌──┬────────────────────┐
 │IT│⟨⟩                  │
diff --git a/md.bqn b/md.bqn
index bda35610..55a5b236 100644
--- a/md.bqn
+++ b/md.bqn
@@ -130,8 +130,15 @@ Markdown ← {filename𝕊𝕩:
     # If every line is indented by at least 4 additional spaces, we will
     # execute each one and insert the results.
     addRslt ← ∧´ ' ' = ∾ 4 (⌊⟜≠ ↑ ⊢)¨ 𝕩
+    # Don't show assignment results by default
+    ShowRslt ← {
+      depth ← +` "(){}⟨⟩" (⊣(≠⊸>ׯ1⋆2|⊢)⊐) 𝕩
+      𝕩 /˜↩ ¬ ∨`⌾⌽ (0=depth) ∧ 𝕩∊"⋄,"  # Just the last statement
+      g ← 𝕩∊"←↩"
+      (⊑g⊐1) (<⟜(≠g))◶⟨1,¬(" "∾∾idChars)∧´∘∊˜↑⟩ 𝕩
+    }
     r‿ri ← addRslt◶(2⥊<⟨⟩)‿{
-      ⟨ (⥊∾⟜lf⎉1)∘⍕∘CodeExec⍟(0<≠)¨ 𝕩
+      ⟨ (ShowRslt ⊣◶⟨"",(⥊∾⟜lf⎉1)∘⍕∘⊢⟩ CodeExec)⍟(0<≠)¨ 𝕩
         1 -˜ +` 1 + ≠¨ 𝕩   ⟩ # Don't forget the trailing newline
     } 𝕩
 
@@ -383,13 +390,13 @@ TestSections ← {
 
 ################################
 # Syntax highlighting
+idChars ← ⟨
+  •d∾"¯.π∞"
+  ' '+⌾•UCS•a
+  •a
+  "_"
+⟩
 GetHighlights ← {
-  idChars ← ⟨
-    •d∾"¯.π∞"
-    ' '+⌾•UCS•a
-    •a
-    "_"
-  ⟩
   classes‿chars ← <˘ ⍉ 2⊸(÷˜⟜≠∾⊣)⊸⥊⟨
     0             , " "∾•UCS 9‿10
     "Value"       , ¯1⊏˘5‿2⥊"𝕨𝕩𝕗𝕘𝕤"
-- 
cgit v1.2.3