aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-07-10 22:15:01 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-07-10 22:15:01 -0400
commit920e354fd76fd5cba8411cf09b6cbe4c27a85520 (patch)
treeadeb8ffb17d79a64ff0280388cd1e0edf4dbde8d
parentc731c372f41e4b8a73b96dd58be9a6d579e62f4b (diff)
Quick starting takes a while, it turns out
-rw-r--r--doc/quick.md98
-rw-r--r--docs/doc/quick.html80
2 files changed, 150 insertions, 28 deletions
diff --git a/doc/quick.md b/doc/quick.md
index 5a7c058b..9ac0a8f6 100644
--- a/doc/quick.md
+++ b/doc/quick.md
@@ -21,22 +21,19 @@ Here's a little BQN program:
Split ← {
!1==𝕩 ⋄ (!2=•Type)¨𝕩
Proc ← {
- · 𝕊 ' ': spl⇐1 ⋄ str⇐"" ; # Space: break and delete it
- prev Proc cur: spl‿str⇐
- spl←0 ⋄ str←⋈cur # Include and don't break...
- { prev≡cur ? spl+↩1 ; @ } # except at equal characters
+ · 𝕊 ' ': spl⇐1 ; # Space: break and delete it
+ prev Fn cur: ⟨spl,str⟩⇐
+ spl←0 ⋄ str←⟨cur⟩ # Include and don't break...
+ { prev=cur ? spl+↩1 ; @ } # except at equal characters
}
- r ← (»𝕩) Proc¨ 𝕩
- GV←{𝕩.str} ⋄ GS←{⟨s⇐spl⟩:s}
- (∾¨ GV¨ ⊔˜ ·+`GS¨) r
+ GV‿GS ← {𝕏¨}¨ ⟨ {⟨s⇐str⟩:s;""}
+ {𝕩.spl} ⟩
+ r ← Proc{»𝔽¨⊢} 𝕩
+ (∾¨ GV ⊔˜ ·+`GS) r
}
- •Show shw ← Split hw # ⟨ "Hel" "lo," "World!" ⟩
+ •Show Split hw # ⟨ "Hel" "lo," "World!" ⟩
- fns ← ⟨⌽, split
- case.Lower⌾⊑⟩
- •Show fns {𝕎𝕩}¨ shw # ⟨ "leH" ⟨ "lo," ⟩ "world!" ⟩
-
-It's not the most idiomatic BQN you'll see, but that's because this piece of code uses every piece of syntax in the language (and a good number of the primitives).
+It's not the most idiomatic BQN you'll see, but that's because this piece of code uses nearly all the syntax in the language (and a good number of the primitives).
If you save it with the name hello.bqn and have BQN [installed](../running.md), the script can be run with `$ bqn hello.bqn` from a shell. Because of the `#!` line at the top, `$ ./hello.bqn` also works if `bqn` is in your path and hello.bqn is executable. It can also be run from another BQN file in the same directory, or REPL started there, using `•Import "hello.bqn"`. Or just copy-paste it into the [online REPL](https://mlochbaum.github.io/BQN/try.html).
@@ -64,7 +61,7 @@ The function `-´` is a *compound* function, because it consists of another func
diff ← -´ "Aa"
'b' + diff
-The function `Lower` is defined to be `-⟜diff`, but it uses a different arrow `⇐` to do this. This is an [export](namespace.md#exports), and it declares that `Lower` is a *field* of a namespace that can be accessed from the outside. Having a `⇐` in it is also what makes the block define a namespace. `Lower` isn't accessed in the rest of the program, but `Upper` is, with `case.Upper`.
+The function `Lower` is defined to be `-⟜diff`, but it uses a different arrow `⇐` to do this. This is an [export](namespace.md#exports), and it declares that `Lower` is a *field* of a namespace that can be accessed from the outside. Having a `⇐` in it is also what makes the block define a namespace. `Lower` itself won't be used for a while, but `Upper` is accessed a few lines down, with `case.Upper`.
`Lower` is created with a modifier again, this time the 2-modifier `⟜`. We've now seen one each of the three [*primitive*](primitive.md) types: function, 1-modifier, and 2-modifier. There are a lot of primitives, but some simple rules tell you which type they have. Primitives are functions by default, but superscript characters are 1-modifiers (`` ´˘¨˜` `` in our program), and ones with an unbroken circle are 2-modifiers (`⟜∘⌾`; `⍉` is a broken circle so it's a function). Variable names follow a [similar system](expression.md#role-spellings), where functions start with an uppercase letter and subjects with a lowercase one.
@@ -156,3 +153,76 @@ Finally, [Join](join.md) combines this list of strings into a single string.
hw
The full statement stores this back in `hw` with `↩`, then prints it using `•Out`. Assignment can be used inline, much like a function! `•Out` is our first [system function](../spec/system.md) (see [this section](../spec/system.md#input-and-output)), and prints a string directly as output. We have now printed that which new programmers must print, and covered the basics of BQN expressions!
+
+## Breaking hello
+
+Now we're going to play around with the string `hw` or `"Hello, World!"` that we've constructed, and see a few ways to construct functions. If you're starting out you won't need many of the details here for a while, so you may want to stop after getting the basic idea and revisit this page later.
+
+ # Split at spaces and repeated characters
+ Split ← {
+ !1==𝕩 ⋄ (!2=•Type)¨𝕩
+ Proc ← {
+ · 𝕊 ' ': spl⇐1 ; # Space: break and delete it
+ prev Fn cur: ⟨spl,str⟩⇐
+ spl←0 ⋄ str←⟨cur⟩ # Include and don't break...
+ { prev=cur ? spl+↩1 ; @ } # except at equal characters
+ }
+ GV‿GS ← {𝕏¨}¨ ⟨ {⟨s⇐str⟩:s;""}
+ {𝕩.spl} ⟩
+ r ← Proc{»𝔽¨⊢} 𝕩
+ (∾¨ GV ⊔˜ ·+`GS) r
+ }
+ •Show Split hw # ⟨ "Hel" "lo," "World!" ⟩
+
+The big definition `Split` is a [block function](block.md), using `{}` like the namespace `case`—that was an immediate block. The difference is that `Split` contains an `𝕩`, which indicates an argument. We also see that blocks can be nested within each other. The inner blocks contain other characters like `⇐` and `𝔽` that can change the nature of a block, but these only affect the block immediately containing them.
+
+To begin with, `Split` tests its argument `𝕩`. There are two tests, with a statement [separator](token.md#separators) `⋄` between them. The diamond, as well as `,`, is interchangeable with a newline. The tests are done with the function [Assert](assert.md) (`!`).
+
+ !1==𝕩 ⋄ (!2=•Type)¨𝕩
+
+First, `Split` requires that the [rank](shape.md) `=𝕩` be 1, that is, `𝕩` must be a list. In `1==𝕩`, `=` has two meanings, depending on whether it has a left argument. Next, it checks that each element has a character [type](../spec/system.md#operation-properties).
+
+The subexpression `!2=•Type` is a function [train](train.md), and it happens to have a simple expansion, as `(!2=•Type)e` is `!2=•Type e`. It matters that `2` is just a number; if it were a function it would be applied to `e`. We'll discuss trains more later. This one is applied with [Each](map.md#one-argument-mapping) to test every element of `𝕩`. This does form an array result, but it's not used.
+
+### Subfunction
+
+The function `Proc` is called on each character of `𝕩` along with the previous character, and says what to at that position. Also, it's deliberately inconsistent to cover more BQN features. Here's the whole thing:
+
+ Proc ← {
+ · 𝕊 ' ': spl⇐1 ; # Space: break and delete it
+ prev Fn cur: ⟨spl,str⟩⇐
+ spl←0 ⋄ str←⟨cur⟩ # Include and don't break...
+ { prev=cur ? spl+↩1 ; @ } # except at equal characters
+ }
+
+Unlike `Split`, which only contains a sequence of statements, `Proc` has some structure. Let's reduce each block *body* to a `…` to see it better.
+
+ Proc ← {
+ · 𝕊 ' ': … ;
+ prev Fn cur: …
+ }
+
+This function has two bodies with `;` in between. Each one has a *header*, separated from the body with a `:`. A header indicates the kind of the block as a whole, and also which inputs the body after it works on. It mirrors the way the block should be used. In the right context, both `· 𝕊 ' '` and `prev Fn cur` would be valid function calls. Which tells us `Proc` is a function.
+
+The first header, `· 𝕊 ' ':`, is more specific. The function is unlabelled, since `𝕊` just indicates the block function it's in (useful for [recursion](block.md#self-reference)). The right argument is `' '`, a space character, so this body will only be used if `𝕩` is a space. And the left argument is… `·`, which is called [Nothing](expression.md#nothing). Both here and as an assignment target, Nothing indicates an ignored value. This body *does* require a left argument, but it doesn't name it. And the body itself is just `spl⇐1`. The `⇐` makes this body (only this one!) return a namespace, which has only the field `spl`.
+
+The next header, `prev Fn cur:` sets names for the function and its arguments, but doesn't constrain them other than requiring two arguments. So it applies in all the cases where the previous one didn't match, that is, when `𝕩` isn't `' '`. The body starts with `⟨spl,str⟩⇐`, and the `⇐` means it will return a namespace too. This is an [export statement](namespace.md#exports), which declares `spl` and `str` to be fields but doesn't define them—they must be defined somewhere else in the block, which is what happens next.
+
+ prev Fn cur: ⟨spl,str⟩⇐
+ spl←0 ⋄ str←⟨cur⟩ # Include and don't break...
+ { prev=cur ? spl+↩1 ; @ } # except at equal characters
+
+Both `⟨spl,str⟩` and `⟨cur⟩` are written with [list notation](arrayrepr.md#brackets), giving a list of two names, then one value. While `⟨spl,str⟩` can also be written `spl‿str`, there's no way to write `⟨cur⟩` with stranding.
+
+On the last line we're now three blocks deep! This block also has two bodies, but they don't have headers. A [predicate](block.md#predicates) `prev=cur ?` tests whether to use the first body, which increments `spl` with [modified assignment](expression.md#assignment). Note that `𝕨=𝕩` wouldn't work here, because the special names `𝕨` and `𝕩` pertain only to the surrounding block, and `Proc` is a level up. However, the idiomatic way to write this part would be the much shorter `spl←prev=cur`, since BQN's booleans are 0 and 1.
+
+The end result of `Proc` is always a namespace. It has a field `spl` set to 1 if `𝕩` is `' '` or the two arguments are equal. And if `𝕩` isn't `' '`, it has another field `str` set to `⟨𝕩⟩`.
+
+### Extraction
+
+Once `Proc` is applied to all the characters, we'll end up with a list of namespaces (which, yes, is over-engineered for what we're doing). The following statement defines two functions `GV` and `GS` to extract fields from this list.
+
+ GV‿GS ← {𝕏¨}¨ ⟨ {⟨s⇐str⟩:s;""}
+ {𝕩.spl} ⟩
+
+Going left to right, `GV‿GS` indicates [destructuring assignment](expression.md#destructuring), which will expect a list of two values on the right and take it apart to assign the two names.
diff --git a/docs/doc/quick.html b/docs/doc/quick.html
index 4daf6574..34c5e331 100644
--- a/docs/doc/quick.html
+++ b/docs/doc/quick.html
@@ -23,22 +23,19 @@
</span><span class='Function'>Split</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='Function'>!</span><span class='Number'>1</span><span class='Function'>==</span><span class='Value'>𝕩</span> <span class='Separator'>⋄</span> <span class='Paren'>(</span><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=•Type</span><span class='Paren'>)</span><span class='Modifier'>¨</span><span class='Value'>𝕩</span>
<span class='Function'>Proc</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
- <span class='Nothing'>·</span> <span class='Function'>𝕊</span> <span class='String'>' '</span><span class='Head'>:</span> <span class='Value'>spl</span><span class='Gets'>⇐</span><span class='Number'>1</span> <span class='Separator'>⋄</span> <span class='Value'>str</span><span class='Gets'>⇐</span><span class='String'>&quot;&quot;</span> <span class='Head'>;</span> <span class='Comment'># Space: break and delete it
-</span> <span class='Value'>prev</span> <span class='Function'>Proc</span> <span class='Value'>cur</span><span class='Head'>:</span> <span class='Value'>spl</span><span class='Ligature'>‿</span><span class='Value'>str</span><span class='Gets'>⇐</span>
- <span class='Value'>spl</span><span class='Gets'>←</span><span class='Number'>0</span> <span class='Separator'>⋄</span> <span class='Value'>str</span><span class='Gets'>←</span><span class='Function'>⋈</span><span class='Value'>cur</span> <span class='Comment'># Include and don't break...
-</span> <span class='Brace'>{</span> <span class='Value'>prev</span><span class='Function'>≡</span><span class='Value'>cur</span> <span class='Head'>?</span> <span class='Value'>spl</span><span class='Function'>+</span><span class='Gets'>↩</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='String'>@</span> <span class='Brace'>}</span> <span class='Comment'># except at equal characters
+ <span class='Nothing'>·</span> <span class='Function'>𝕊</span> <span class='String'>' '</span><span class='Head'>:</span> <span class='Value'>spl</span><span class='Gets'>⇐</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='Comment'># Space: break and delete it
+</span> <span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span> <span class='Bracket'>⟨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>⟩</span><span class='Gets'>⇐</span>
+ <span class='Value'>spl</span><span class='Gets'>←</span><span class='Number'>0</span> <span class='Separator'>⋄</span> <span class='Value'>str</span><span class='Gets'>←</span><span class='Bracket'>⟨</span><span class='Value'>cur</span><span class='Bracket'>⟩</span> <span class='Comment'># Include and don't break...
+</span> <span class='Brace'>{</span> <span class='Value'>prev</span><span class='Function'>=</span><span class='Value'>cur</span> <span class='Head'>?</span> <span class='Value'>spl</span><span class='Function'>+</span><span class='Gets'>↩</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='String'>@</span> <span class='Brace'>}</span> <span class='Comment'># except at equal characters
</span> <span class='Brace'>}</span>
- <span class='Value'>r</span> <span class='Gets'>←</span> <span class='Paren'>(</span><span class='Function'>»</span><span class='Value'>𝕩</span><span class='Paren'>)</span> <span class='Function'>Proc</span><span class='Modifier'>¨</span> <span class='Value'>𝕩</span>
- <span class='Function'>GV</span><span class='Gets'>←</span><span class='Brace'>{</span><span class='Value'>𝕩.str</span><span class='Brace'>}</span> <span class='Separator'>⋄</span> <span class='Function'>GS</span><span class='Gets'>←</span><span class='Brace'>{</span><span class='Bracket'>⟨</span><span class='Value'>s</span><span class='Gets'>⇐</span><span class='Value'>spl</span><span class='Bracket'>⟩</span><span class='Head'>:</span><span class='Value'>s</span><span class='Brace'>}</span>
- <span class='Paren'>(</span><span class='Function'>∾</span><span class='Modifier'>¨</span> <span class='Function'>GV</span><span class='Modifier'>¨</span> <span class='Function'>⊔</span><span class='Modifier'>˜</span> <span class='Nothing'>·</span><span class='Function'>+</span><span class='Modifier'>`</span><span class='Function'>GS</span><span class='Modifier'>¨</span><span class='Paren'>)</span> <span class='Value'>r</span>
+ <span class='Function'>GV</span><span class='Ligature'>‿</span><span class='Function'>GS</span> <span class='Gets'>←</span> <span class='Brace'>{</span><span class='Function'>𝕏</span><span class='Modifier'>¨</span><span class='Brace'>}</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span> <span class='Brace'>{</span><span class='Bracket'>⟨</span><span class='Value'>s</span><span class='Gets'>⇐</span><span class='Value'>str</span><span class='Bracket'>⟩</span><span class='Head'>:</span><span class='Value'>s</span><span class='Head'>;</span><span class='String'>&quot;&quot;</span><span class='Brace'>}</span>
+ <span class='Brace'>{</span><span class='Value'>𝕩.spl</span><span class='Brace'>}</span> <span class='Bracket'>⟩</span>
+ <span class='Value'>r</span> <span class='Gets'>←</span> <span class='Function'>Proc</span><span class='Brace'>{</span><span class='Function'>»𝔽</span><span class='Modifier'>¨</span><span class='Function'>⊢</span><span class='Brace'>}</span> <span class='Value'>𝕩</span>
+ <span class='Paren'>(</span><span class='Function'>∾</span><span class='Modifier'>¨</span> <span class='Function'>GV</span> <span class='Function'>⊔</span><span class='Modifier'>˜</span> <span class='Nothing'>·</span><span class='Function'>+</span><span class='Modifier'>`</span><span class='Function'>GS</span><span class='Paren'>)</span> <span class='Value'>r</span>
<span class='Brace'>}</span>
-<span class='Function'>•Show</span> <span class='Value'>shw</span> <span class='Gets'>←</span> <span class='Function'>Split</span> <span class='Value'>hw</span> <span class='Comment'># ⟨ &quot;Hel&quot; &quot;lo,&quot; &quot;World!&quot; ⟩
-</span>
-<span class='Value'>fns</span> <span class='Gets'>←</span> <span class='Bracket'>⟨</span><span class='Function'>⌽</span><span class='Separator'>,</span> <span class='Value'>split</span>
- <span class='Value'>case.</span><span class='Function'>Lower</span><span class='Modifier2'>⌾</span><span class='Function'>⊑</span><span class='Bracket'>⟩</span>
-<span class='Function'>•Show</span> <span class='Value'>fns</span> <span class='Brace'>{</span><span class='Function'>𝕎</span><span class='Value'>𝕩</span><span class='Brace'>}</span><span class='Modifier'>¨</span> <span class='Value'>shw</span> <span class='Comment'># ⟨ &quot;leH&quot; ⟨ &quot;lo,&quot; ⟩ &quot;world!&quot; ⟩
+<span class='Function'>•Show</span> <span class='Function'>Split</span> <span class='Value'>hw</span> <span class='Comment'># ⟨ &quot;Hel&quot; &quot;lo,&quot; &quot;World!&quot; ⟩
</span></pre>
-<p>It's not the most idiomatic BQN you'll see, but that's because this piece of code uses every piece of syntax in the language (and a good number of the primitives).</p>
+<p>It's not the most idiomatic BQN you'll see, but that's because this piece of code uses nearly all the syntax in the language (and a good number of the primitives).</p>
<p>If you save it with the name hello.bqn and have BQN <a href="../running.html">installed</a>, the script can be run with <code><span class='Value'>$</span> <span class='Value'>bqn</span> <span class='Value'>hello.bqn</span></code> from a shell. Because of the <code><span class='Comment'>#!</span></code> line at the top, <code><span class='Value'>$</span> <span class='Value'>.</span><span class='Function'>/</span><span class='Value'>hello.bqn</span></code> also works if <code><span class='Value'>bqn</span></code> is in your path and hello.bqn is executable. It can also be run from another BQN file in the same directory, or REPL started there, using <code><span class='Function'>•Import</span> <span class='String'>&quot;hello.bqn&quot;</span></code>. Or just copy-paste it into the <a href="https://mlochbaum.github.io/BQN/try.html">online REPL</a>.</p>
<p>Now let's see how it works.</p>
<h2 id="case-conversion"><a class="header" href="#case-conversion">Case conversion</a></h2>
@@ -62,7 +59,7 @@
<span class='String'>'b'</span> <span class='Function'>+</span> <span class='Value'>diff</span>
'B'
</pre>
-<p>The function <code><span class='Function'>Lower</span></code> is defined to be <code><span class='Function'>-</span><span class='Modifier2'>⟜</span><span class='Value'>diff</span></code>, but it uses a different arrow <code><span class='Gets'>⇐</span></code> to do this. This is an <a href="namespace.html#exports">export</a>, and it declares that <code><span class='Function'>Lower</span></code> is a <em>field</em> of a namespace that can be accessed from the outside. Having a <code><span class='Gets'>⇐</span></code> in it is also what makes the block define a namespace. <code><span class='Function'>Lower</span></code> isn't accessed in the rest of the program, but <code><span class='Function'>Upper</span></code> is, with <code><span class='Value'>case.</span><span class='Function'>Upper</span></code>.</p>
+<p>The function <code><span class='Function'>Lower</span></code> is defined to be <code><span class='Function'>-</span><span class='Modifier2'>⟜</span><span class='Value'>diff</span></code>, but it uses a different arrow <code><span class='Gets'>⇐</span></code> to do this. This is an <a href="namespace.html#exports">export</a>, and it declares that <code><span class='Function'>Lower</span></code> is a <em>field</em> of a namespace that can be accessed from the outside. Having a <code><span class='Gets'>⇐</span></code> in it is also what makes the block define a namespace. <code><span class='Function'>Lower</span></code> itself won't be used for a while, but <code><span class='Function'>Upper</span></code> is accessed a few lines down, with <code><span class='Value'>case.</span><span class='Function'>Upper</span></code>.</p>
<p><code><span class='Function'>Lower</span></code> is created with a modifier again, this time the 2-modifier <code><span class='Modifier2'>⟜</span></code>. We've now seen one each of the three <a href="primitive.html"><em>primitive</em></a> types: function, 1-modifier, and 2-modifier. There are a lot of primitives, but some simple rules tell you which type they have. Primitives are functions by default, but superscript characters are 1-modifiers (<code><span class='Modifier'>´˘¨˜`</span></code> in our program), and ones with an unbroken circle are 2-modifiers (<code><span class='Modifier2'>⟜∘⌾</span></code>; <code><span class='Function'>⍉</span></code> is a broken circle so it's a function). Variable names follow a <a href="expression.html#role-spellings">similar system</a>, where functions start with an uppercase letter and subjects with a lowercase one.</p>
<p><a href="hook.html">After</a> (<code><span class='Modifier2'>⟜</span></code>) takes two operands, <code><span class='Function'>-</span></code> and <code><span class='Value'>diff</span></code>, to produce a function—specifically, it binds <code><span class='Value'>diff</span></code> as the right argument of <code><span class='Function'>-</span></code>, so that calling it on an argument subtracts <code><span class='Value'>diff</span></code> from that argument.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LeKfnGRpZmYgJ0cnCgonRycgLSBkaWZm">↗️</a><pre> <span class='Function'>-</span><span class='Modifier2'>⟜</span><span class='Value'>diff</span> <span class='String'>'G'</span>
@@ -189,3 +186,58 @@
"Hello, World!"
</pre>
<p>The full statement stores this back in <code><span class='Value'>hw</span></code> with <code><span class='Gets'>↩</span></code>, then prints it using <code><span class='Function'>•Out</span></code>. Assignment can be used inline, much like a function! <code><span class='Function'>•Out</span></code> is our first <a href="../spec/system.html">system function</a> (see <a href="../spec/system.html#input-and-output">this section</a>), and prints a string directly as output. We have now printed that which new programmers must print, and covered the basics of BQN expressions!</p>
+<h2 id="breaking-hello"><a class="header" href="#breaking-hello">Breaking hello</a></h2>
+<p>Now we're going to play around with the string <code><span class='Value'>hw</span></code> or <code><span class='String'>&quot;Hello, World!&quot;</span></code> that we've constructed, and see a few ways to construct functions. If you're starting out you won't need many of the details here for a while, so you may want to stop after getting the basic idea and revisit this page later.</p>
+<pre><span class='Comment'># Split at spaces and repeated characters
+</span><span class='Function'>Split</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
+ <span class='Function'>!</span><span class='Number'>1</span><span class='Function'>==</span><span class='Value'>𝕩</span> <span class='Separator'>⋄</span> <span class='Paren'>(</span><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=•Type</span><span class='Paren'>)</span><span class='Modifier'>¨</span><span class='Value'>𝕩</span>
+ <span class='Function'>Proc</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
+ <span class='Nothing'>·</span> <span class='Function'>𝕊</span> <span class='String'>' '</span><span class='Head'>:</span> <span class='Value'>spl</span><span class='Gets'>⇐</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='Comment'># Space: break and delete it
+</span> <span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span> <span class='Bracket'>⟨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>⟩</span><span class='Gets'>⇐</span>
+ <span class='Value'>spl</span><span class='Gets'>←</span><span class='Number'>0</span> <span class='Separator'>⋄</span> <span class='Value'>str</span><span class='Gets'>←</span><span class='Bracket'>⟨</span><span class='Value'>cur</span><span class='Bracket'>⟩</span> <span class='Comment'># Include and don't break...
+</span> <span class='Brace'>{</span> <span class='Value'>prev</span><span class='Function'>=</span><span class='Value'>cur</span> <span class='Head'>?</span> <span class='Value'>spl</span><span class='Function'>+</span><span class='Gets'>↩</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='String'>@</span> <span class='Brace'>}</span> <span class='Comment'># except at equal characters
+</span> <span class='Brace'>}</span>
+ <span class='Function'>GV</span><span class='Ligature'>‿</span><span class='Function'>GS</span> <span class='Gets'>←</span> <span class='Brace'>{</span><span class='Function'>𝕏</span><span class='Modifier'>¨</span><span class='Brace'>}</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span> <span class='Brace'>{</span><span class='Bracket'>⟨</span><span class='Value'>s</span><span class='Gets'>⇐</span><span class='Value'>str</span><span class='Bracket'>⟩</span><span class='Head'>:</span><span class='Value'>s</span><span class='Head'>;</span><span class='String'>&quot;&quot;</span><span class='Brace'>}</span>
+ <span class='Brace'>{</span><span class='Value'>𝕩.spl</span><span class='Brace'>}</span> <span class='Bracket'>⟩</span>
+ <span class='Value'>r</span> <span class='Gets'>←</span> <span class='Function'>Proc</span><span class='Brace'>{</span><span class='Function'>»𝔽</span><span class='Modifier'>¨</span><span class='Function'>⊢</span><span class='Brace'>}</span> <span class='Value'>𝕩</span>
+ <span class='Paren'>(</span><span class='Function'>∾</span><span class='Modifier'>¨</span> <span class='Function'>GV</span> <span class='Function'>⊔</span><span class='Modifier'>˜</span> <span class='Nothing'>·</span><span class='Function'>+</span><span class='Modifier'>`</span><span class='Function'>GS</span><span class='Paren'>)</span> <span class='Value'>r</span>
+<span class='Brace'>}</span>
+<span class='Function'>•Show</span> <span class='Function'>Split</span> <span class='Value'>hw</span> <span class='Comment'># ⟨ &quot;Hel&quot; &quot;lo,&quot; &quot;World!&quot; ⟩
+</span></pre>
+<p>The big definition <code><span class='Function'>Split</span></code> is a <a href="block.html">block function</a>, using <code><span class='Brace'>{}</span></code> like the namespace <code><span class='Value'>case</span></code>—that was an immediate block. The difference is that <code><span class='Function'>Split</span></code> contains an <code><span class='Value'>𝕩</span></code>, which indicates an argument. We also see that blocks can be nested within each other. The inner blocks contain other characters like <code><span class='Gets'>⇐</span></code> and <code><span class='Function'>𝔽</span></code> that can change the nature of a block, but these only affect the block immediately containing them.</p>
+<p>To begin with, <code><span class='Function'>Split</span></code> tests its argument <code><span class='Value'>𝕩</span></code>. There are two tests, with a statement <a href="token.html#separators">separator</a> <code><span class='Separator'>⋄</span></code> between them. The diamond, as well as <code><span class='Separator'>,</span></code>, is interchangeable with a newline. The tests are done with the function <a href="assert.html">Assert</a> (<code><span class='Function'>!</span></code>).</p>
+<pre><span class='Function'>!</span><span class='Number'>1</span><span class='Function'>==</span><span class='Value'>𝕩</span> <span class='Separator'>⋄</span> <span class='Paren'>(</span><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=•Type</span><span class='Paren'>)</span><span class='Modifier'>¨</span><span class='Value'>𝕩</span>
+</pre>
+<p>First, <code><span class='Function'>Split</span></code> requires that the <a href="shape.html">rank</a> <code><span class='Function'>=</span><span class='Value'>𝕩</span></code> be 1, that is, <code><span class='Value'>𝕩</span></code> must be a list. In <code><span class='Number'>1</span><span class='Function'>==</span><span class='Value'>𝕩</span></code>, <code><span class='Function'>=</span></code> has two meanings, depending on whether it has a left argument. Next, it checks that each element has a character <a href="../spec/system.html#operation-properties">type</a>.</p>
+<p>The subexpression <code><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=•Type</span></code> is a function <a href="train.html">train</a>, and it happens to have a simple expansion, as <code><span class='Paren'>(</span><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=•Type</span><span class='Paren'>)</span><span class='Value'>e</span></code> is <code><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=•Type</span> <span class='Value'>e</span></code>. It matters that <code><span class='Number'>2</span></code> is just a number; if it were a function it would be applied to <code><span class='Value'>e</span></code>. We'll discuss trains more later. This one is applied with <a href="map.html#one-argument-mapping">Each</a> to test every element of <code><span class='Value'>𝕩</span></code>. This does form an array result, but it's not used.</p>
+<h3 id="subfunction"><a class="header" href="#subfunction">Subfunction</a></h3>
+<p>The function <code><span class='Function'>Proc</span></code> is called on each character of <code><span class='Value'>𝕩</span></code> along with the previous character, and says what to at that position. Also, it's deliberately inconsistent to cover more BQN features. Here's the whole thing:</p>
+<pre><span class='Function'>Proc</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
+ <span class='Nothing'>·</span> <span class='Function'>𝕊</span> <span class='String'>' '</span><span class='Head'>:</span> <span class='Value'>spl</span><span class='Gets'>⇐</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='Comment'># Space: break and delete it
+</span> <span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span> <span class='Bracket'>⟨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>⟩</span><span class='Gets'>⇐</span>
+ <span class='Value'>spl</span><span class='Gets'>←</span><span class='Number'>0</span> <span class='Separator'>⋄</span> <span class='Value'>str</span><span class='Gets'>←</span><span class='Bracket'>⟨</span><span class='Value'>cur</span><span class='Bracket'>⟩</span> <span class='Comment'># Include and don't break...
+</span> <span class='Brace'>{</span> <span class='Value'>prev</span><span class='Function'>=</span><span class='Value'>cur</span> <span class='Head'>?</span> <span class='Value'>spl</span><span class='Function'>+</span><span class='Gets'>↩</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='String'>@</span> <span class='Brace'>}</span> <span class='Comment'># except at equal characters
+</span><span class='Brace'>}</span>
+</pre>
+<p>Unlike <code><span class='Function'>Split</span></code>, which only contains a sequence of statements, <code><span class='Function'>Proc</span></code> has some structure. Let's reduce each block <em>body</em> to a <code><span class='Value'>…</span></code> to see it better.</p>
+<pre><span class='Function'>Proc</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
+ <span class='Nothing'>·</span> <span class='Function'>𝕊</span> <span class='String'>' '</span><span class='Head'>:</span> <span class='Value'>…</span> <span class='Head'>;</span>
+ <span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span> <span class='Value'>…</span>
+<span class='Brace'>}</span>
+</pre>
+<p>This function has two bodies with <code><span class='Head'>;</span></code> in between. Each one has a <em>header</em>, separated from the body with a <code><span class='Head'>:</span></code>. A header indicates the kind of the block as a whole, and also which inputs the body after it works on. It mirrors the way the block should be used. In the right context, both <code><span class='Nothing'>·</span> <span class='Function'>𝕊</span> <span class='String'>' '</span></code> and <code><span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span></code> would be valid function calls. Which tells us <code><span class='Function'>Proc</span></code> is a function.</p>
+<p>The first header, <code><span class='Nothing'>·</span> <span class='Function'>𝕊</span> <span class='String'>' '</span><span class='Head'>:</span></code>, is more specific. The function is unlabelled, since <code><span class='Function'>𝕊</span></code> just indicates the block function it's in (useful for <a href="block.html#self-reference">recursion</a>). The right argument is <code><span class='String'>' '</span></code>, a space character, so this body will only be used if <code><span class='Value'>𝕩</span></code> is a space. And the left argument is… <code><span class='Nothing'>·</span></code>, which is called <a href="expression.html#nothing">Nothing</a>. Both here and as an assignment target, Nothing indicates an ignored value. This body <em>does</em> require a left argument, but it doesn't name it. And the body itself is just <code><span class='Value'>spl</span><span class='Gets'>⇐</span><span class='Number'>1</span></code>. The <code><span class='Gets'>⇐</span></code> makes this body (only this one!) return a namespace, which has only the field <code><span class='Value'>spl</span></code>.</p>
+<p>The next header, <code><span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span></code> sets names for the function and its arguments, but doesn't constrain them other than requiring two arguments. So it applies in all the cases where the previous one didn't match, that is, when <code><span class='Value'>𝕩</span></code> isn't <code><span class='String'>' '</span></code>. The body starts with <code><span class='Bracket'>⟨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>⟩</span><span class='Gets'>⇐</span></code>, and the <code><span class='Gets'>⇐</span></code> means it will return a namespace too. This is an <a href="namespace.html#exports">export statement</a>, which declares <code><span class='Value'>spl</span></code> and <code><span class='Value'>str</span></code> to be fields but doesn't define them—they must be defined somewhere else in the block, which is what happens next.</p>
+<pre><span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span> <span class='Bracket'>⟨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>⟩</span><span class='Gets'>⇐</span>
+ <span class='Value'>spl</span><span class='Gets'>←</span><span class='Number'>0</span> <span class='Separator'>⋄</span> <span class='Value'>str</span><span class='Gets'>←</span><span class='Bracket'>⟨</span><span class='Value'>cur</span><span class='Bracket'>⟩</span> <span class='Comment'># Include and don't break...
+</span> <span class='Brace'>{</span> <span class='Value'>prev</span><span class='Function'>=</span><span class='Value'>cur</span> <span class='Head'>?</span> <span class='Value'>spl</span><span class='Function'>+</span><span class='Gets'>↩</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='String'>@</span> <span class='Brace'>}</span> <span class='Comment'># except at equal characters
+</span></pre>
+<p>Both <code><span class='Bracket'>⟨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>⟩</span></code> and <code><span class='Bracket'>⟨</span><span class='Value'>cur</span><span class='Bracket'>⟩</span></code> are written with <a href="arrayrepr.html#brackets">list notation</a>, giving a list of two names, then one value. While <code><span class='Bracket'>⟨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>⟩</span></code> can also be written <code><span class='Value'>spl</span><span class='Ligature'>‿</span><span class='Value'>str</span></code>, there's no way to write <code><span class='Bracket'>⟨</span><span class='Value'>cur</span><span class='Bracket'>⟩</span></code> with stranding.</p>
+<p>On the last line we're now three blocks deep! This block also has two bodies, but they don't have headers. A <a href="block.html#predicates">predicate</a> <code><span class='Value'>prev</span><span class='Function'>=</span><span class='Value'>cur</span> <span class='Head'>?</span></code> tests whether to use the first body, which increments <code><span class='Value'>spl</span></code> with <a href="expression.html#assignment">modified assignment</a>. Note that <code><span class='Value'>𝕨</span><span class='Function'>=</span><span class='Value'>𝕩</span></code> wouldn't work here, because the special names <code><span class='Value'>𝕨</span></code> and <code><span class='Value'>𝕩</span></code> pertain only to the surrounding block, and <code><span class='Function'>Proc</span></code> is a level up. However, the idiomatic way to write this part would be the much shorter <code><span class='Value'>spl</span><span class='Gets'>←</span><span class='Value'>prev</span><span class='Function'>=</span><span class='Value'>cur</span></code>, since BQN's booleans are 0 and 1.</p>
+<p>The end result of <code><span class='Function'>Proc</span></code> is always a namespace. It has a field <code><span class='Value'>spl</span></code> set to 1 if <code><span class='Value'>𝕩</span></code> is <code><span class='String'>' '</span></code> or the two arguments are equal. And if <code><span class='Value'>𝕩</span></code> isn't <code><span class='String'>' '</span></code>, it has another field <code><span class='Value'>str</span></code> set to <code><span class='Bracket'>⟨</span><span class='Value'>𝕩</span><span class='Bracket'>⟩</span></code>.</p>
+<h3 id="extraction"><a class="header" href="#extraction">Extraction</a></h3>
+<p>Once <code><span class='Function'>Proc</span></code> is applied to all the characters, we'll end up with a list of namespaces (which, yes, is over-engineered for what we're doing). The following statement defines two functions <code><span class='Function'>GV</span></code> and <code><span class='Function'>GS</span></code> to extract fields from this list.</p>
+<pre><span class='Function'>GV</span><span class='Ligature'>‿</span><span class='Function'>GS</span> <span class='Gets'>←</span> <span class='Brace'>{</span><span class='Function'>𝕏</span><span class='Modifier'>¨</span><span class='Brace'>}</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span> <span class='Brace'>{</span><span class='Bracket'>⟨</span><span class='Value'>s</span><span class='Gets'>⇐</span><span class='Value'>str</span><span class='Bracket'>⟩</span><span class='Head'>:</span><span class='Value'>s</span><span class='Head'>;</span><span class='String'>&quot;&quot;</span><span class='Brace'>}</span>
+ <span class='Brace'>{</span><span class='Value'>𝕩.spl</span><span class='Brace'>}</span> <span class='Bracket'>⟩</span>
+</pre>
+<p>Going left to right, <code><span class='Function'>GV</span><span class='Ligature'>‿</span><span class='Function'>GS</span></code> indicates <a href="expression.html#destructuring">destructuring assignment</a>, which will expect a list of two values on the right and take it apart to assign the two names.</p>