From aaac31f1668fe5516902ee7d2034e5c0e41667a6 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 13 Jul 2022 16:37:06 -0400 Subject: Support line breaks inside brackets in markdown BQN evaluation --- docs/doc/block.html | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'docs/doc/block.html') diff --git a/docs/doc/block.html b/docs/doc/block.html index a79791df..ec9e4ed9 100644 --- a/docs/doc/block.html +++ b/docs/doc/block.html @@ -20,7 +20,11 @@

Headerless blocks

In the simplest case a block is just a list of statements, which are executed to evaluate the block. A block with no special names like 𝕨 or 𝕩 is called an immediate block, and is evaluated as soon as it is reached. The only thing such a block does is group some statements, and create a scope for them so that definitions made there are discarded when the block finishes. Even this small amount of functionality could be useful; as an example the following program can build up an array from named components without polluting the rest of the program with those names.

-↗️
    updown ← { up←↕5 β‹„ downβ†βŒ½up β‹„ up∾down }
+↗️
    updown ← {
+      up ← ↕5
+      down ← ⌽up
+      up∾down
+    }
     updown
 ⟨ 0 1 2 3 4 4 3 2 1 0 ⟩
 
@@ -139,9 +143,11 @@

Because 𝕣 only ever refers to a 1-modifier or 2-modifer, it can never make sense to refer to it as a function, and the uppercase letter ℝ is not recognized by BQN. To allow 𝕣 to be spelled as a 1-modifier _𝕣 or 2-modifier _𝕣_, it's tokenized as an ordinary identifier character, so it has to be separated from adjacent letters or numbers with a space.

Block headers

As a program becomes larger, it often becomes necessary to name inputs to blocks rather than just using special names. It can also become difficult to identify what kind of block is being defined, as it requires scanning through the block for special names. A block header, which is separated from the body of a block by a colon :, specifies the kind of block and can declare names for the block and its inputs.

-
Fact ← { F n:
-  n Γ— (0⊸<)β—Ά1β€ΏF n-1
-}
+↗️
    Fact_head ← { F n:
+      n Γ— (0⊸<)β—Ά1β€ΏF n-1
+    }
+    Fact_head 7
+5040
 

Its syntax mirrors an application of the block. As suggested by the positioning, the names given in a header apply only inside the block: for example F above is only defined inside the {} braces while Fact could be used either outside or inside. Some other possibilites are given below.

# A dyadic function that refers to itself as Func
@@ -197,7 +203,11 @@
 ⟨ 2 'a' 'b' ⟩
 

Bodies with headers come before any that don't have them. When a block is called, its headers are checked in order for compatibility with the arguments, and the first body with a compatible header is used.

-↗️
    CaseAdd ← { 2π•Š3:0β€Ώ5 ; 2π•Šπ•©:⟨1,2+π•©βŸ© ; π•Šπ•©:2‿𝕩 }
+↗️
    CaseAdd ← {
+      2π•Š3: 0β€Ώ5 ;
+      2π•Šπ•©: ⟨1,2+π•©βŸ© ;
+       π•Šπ•©: 2‿𝕩
+    }
 
     2 CaseAdd 3
 ⟨ 0 5 ⟩
@@ -214,12 +224,14 @@
 

Case headers

A special rule allows for convenient case-matching syntax for one-argument functions. In any function header with one argument, the function name can be omitted as long as the argument is not a plain identifierβ€”it must be 𝕩 or a compound value like a list to distinguish it from an immediate block label.

-
Test ← {
-  "abc": "string" ;
-  ⟨2,b⟩: βŒ½π•©       ;
-  5:     "number" ;
-  𝕩:     "default"
-}
+↗️
    Test ← {
+      "abc": "string" ;
+      ⟨2,b⟩: βŒ½π•©       ;
+      5:     "number" ;
+      𝕩:     "default"
+    }
+    Test 5
+"number"
 

These case-style headers function exactly the same as if they were preceded by π•Š, and can be mixed with other kinds of headers.

Predicates

-- cgit v1.2.3