diff options
Diffstat (limited to 'docs/doc')
| -rw-r--r-- | docs/doc/arrayrepr.html | 28 | ||||
| -rw-r--r-- | docs/doc/block.html | 34 | ||||
| -rw-r--r-- | docs/doc/functional.html | 22 | ||||
| -rw-r--r-- | docs/doc/oop.html | 42 | ||||
| -rw-r--r-- | docs/doc/quick.html | 30 |
5 files changed, 84 insertions, 72 deletions
diff --git a/docs/doc/arrayrepr.html b/docs/doc/arrayrepr.html index dc0fd389..61f5dd42 100644 --- a/docs/doc/arrayrepr.html +++ b/docs/doc/arrayrepr.html @@ -33,8 +33,9 @@ <p>Array displays show only the array shape and elements. The <a href="fill.html">fill</a> is an inferred property and the display never indicates or depends on it.</p> <h3 id="corners"><a class="header" href="#corners">Corners</a></h3> <p>Those top-left and bottom-right corners are a distinctive part of BQN's display, as other systems almost always completely enclose the contents. BQN could add the other two corners, naturally; it just doesn't. Within the corners, elements are separated by whitespace only, and generally aligned to the top left.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oMiwieHki4p+p4omN4p+oMuKAvzLipYoiYWJjZCIsNOKfqSAgIyBOZXN0ZWQgMsOXMiBhcnJheQ==">↗️</a><pre> <span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='String'>"xy"</span><span class='Bracket'>⟩</span><span class='Function'>≍</span><span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Function'>⥊</span><span class='String'>"abcd"</span><span class='Separator'>,</span><span class='Number'>4</span><span class='Bracket'>⟩</span> <span class='Comment'># Nested 2×2 array -</span>┌─ +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=W+KfqDIgICAgICAgICAsICJ4eSLin6kKIOKfqDLigL8y4qWKImFiY2QiLCA0ICAg4p+pXQ==">↗️</a><pre> <span class='Bracket'>[⟨</span><span class='Number'>2</span> <span class='Separator'>,</span> <span class='String'>"xy"</span><span class='Bracket'>⟩</span> + <span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Function'>⥊</span><span class='String'>"abcd"</span><span class='Separator'>,</span> <span class='Number'>4</span> <span class='Bracket'>⟩]</span> +┌─ ╵ 2 "xy" ┌─ 4 ╵"ab @@ -69,14 +70,14 @@ </pre> <h4 id="high-rank-layout"><a class="header" href="#high-rank-layout">High-rank layout</a></h4> <p>We've seen already that elements of a list are placed side by side, while the rows of a table (rank-2 array) are stacked on top of each other.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=PMKoIOKGlTUgICAgICAgICMgQSBsaXN0IG9mIHVuaXRzCgoy4oC/M+KAvzTiiY0x4oC/MOKAvzUgICMgQSB0YWJsZQ==">↗️</a><pre> <span class='Function'><</span><span class='Modifier'>¨</span> <span class='Function'>↕</span><span class='Number'>5</span> <span class='Comment'># A list of units +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=PMKoIOKGlTUgICAgICAgICAgIyBBIGxpc3Qgb2YgdW5pdHMKClsy4oC/M+KAvzQsMeKAvzDigL81XSAgIyBBIHRhYmxl">↗️</a><pre> <span class='Function'><</span><span class='Modifier'>¨</span> <span class='Function'>↕</span><span class='Number'>5</span> <span class='Comment'># A list of units </span>┌─ · ┌· ┌· ┌· ┌· ┌· · 0 · 1 · 2 · 3 · 4 ┘ ┘ ┘ ┘ ┘ ┘ - <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Function'>≍</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>5</span> <span class='Comment'># A table + <span class='Bracket'>[</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Separator'>,</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>5</span><span class='Bracket'>]</span> <span class='Comment'># A table </span>┌─ ╵ 2 3 4 1 0 5 @@ -181,16 +182,17 @@ ┘ </pre> <p>BQN's separator rules give list notation a very flexible structure. You can put all the elements on one line or spread them across lines, with the option of adding blank lines between elements. A separator at the end of a line is never needed, but leading and trailing separators are allowed.</p> -<pre><span class='Bracket'>⟨</span> - <span class='String'>"e0"</span><span class='Separator'>,</span> <span class='String'>"e1"</span> - <span class='Bracket'>⟨</span> - <span class='String'>'e'</span> - <span class='String'>'2'</span> - <span class='Bracket'>⟩</span> - <span class='String'>"e3"</span><span class='Separator'>,</span> <span class='String'>"e4"</span><span class='Separator'>,</span> <span class='String'>"e5"</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oCiAgImUwIiwgImUxIgogIOKfqAogICAgJ2UnCiAgICAnMicKICDin6kKICAiZTMiLCAiZTQiLCAiZTUiCgogICJlNiIK4p+p">↗️</a><pre> <span class='Bracket'>⟨</span> + <span class='String'>"e0"</span><span class='Separator'>,</span> <span class='String'>"e1"</span> + <span class='Bracket'>⟨</span> + <span class='String'>'e'</span> + <span class='String'>'2'</span> + <span class='Bracket'>⟩</span> + <span class='String'>"e3"</span><span class='Separator'>,</span> <span class='String'>"e4"</span><span class='Separator'>,</span> <span class='String'>"e5"</span> - <span class='String'>"e6"</span> -<span class='Bracket'>⟩</span> + <span class='String'>"e6"</span> + <span class='Bracket'>⟩</span> +⟨ "e0" "e1" "e2" "e3" "e4" "e5" "e6" ⟩ </pre> <h4 id="high-rank-arrays"><a class="header" href="#high-rank-arrays">High-rank arrays</a></h4> <p>Higher-rank arrays can be written with <code><span class='Bracket'>[]</span></code>, an <strong>array notation</strong> that indicates each element is to be used as a <a href="array.html#cells">cell</a> of its result. It's identical to forming a list and applying <a href="couple.html">Merge</a> (<code><span class='Bracket'>[</span><span class='Value'>…</span><span class='Bracket'>]</span></code> is the same as <code><span class='Function'>></span><span class='Bracket'>⟨</span><span class='Value'>…</span><span class='Bracket'>⟩</span></code>).</p> 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 @@ </pre> <h2 id="headerless-blocks"><a class="header" href="#headerless-blocks">Headerless blocks</a></h2> <p>In the simplest case a block is just a list of statements, which are executed to <em>evaluate</em> the block. A block with no special names like <code><span class='Value'>𝕨</span></code> or <code><span class='Value'>𝕩</span></code> is called an <em>immediate block</em>, 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.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=dXBkb3duIOKGkCB7IHVw4oaQ4oaVNSDii4QgZG93buKGkOKMvXVwIOKLhCB1cOKIvmRvd24gfQp1cGRvd24=">↗️</a><pre> <span class='Value'>updown</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Value'>up</span><span class='Gets'>←</span><span class='Function'>↕</span><span class='Number'>5</span> <span class='Separator'>⋄</span> <span class='Value'>down</span><span class='Gets'>←</span><span class='Function'>⌽</span><span class='Value'>up</span> <span class='Separator'>⋄</span> <span class='Value'>up</span><span class='Function'>∾</span><span class='Value'>down</span> <span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=dXBkb3duIOKGkCB7CiAgdXAg4oaQIOKGlTUKICBkb3duIOKGkCDijL11cAogIHVw4oi+ZG93bgp9CnVwZG93bg==">↗️</a><pre> <span class='Value'>updown</span> <span class='Gets'>←</span> <span class='Brace'>{</span> + <span class='Value'>up</span> <span class='Gets'>←</span> <span class='Function'>↕</span><span class='Number'>5</span> + <span class='Value'>down</span> <span class='Gets'>←</span> <span class='Function'>⌽</span><span class='Value'>up</span> + <span class='Value'>up</span><span class='Function'>∾</span><span class='Value'>down</span> + <span class='Brace'>}</span> <span class='Value'>updown</span> ⟨ 0 1 2 3 4 4 3 2 1 0 ⟩ </pre> @@ -139,9 +143,11 @@ <p>Because <code><span class='Value'>𝕣</span></code> 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 <code><span class='Value'>ℝ</span></code> is not recognized by BQN. To allow <code><span class='Value'>𝕣</span></code> to be spelled as a 1-modifier <code><span class='Modifier'>_𝕣</span></code> or 2-modifier <code><span class='Modifier2'>_𝕣_</span></code>, it's tokenized as an ordinary identifier character, so it has to be separated from adjacent letters or numbers with a space.</p> <h2 id="block-headers"><a class="header" href="#block-headers">Block headers</a></h2> <p>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 <em>block header</em>, which is separated from the body of a block by a colon <code><span class='Head'>:</span></code>, specifies the kind of block and can declare names for the block and its inputs.</p> -<pre><span class='Function'>Fact</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Function'>F</span> <span class='Value'>n</span><span class='Head'>:</span> - <span class='Value'>n</span> <span class='Function'>×</span> <span class='Paren'>(</span><span class='Number'>0</span><span class='Modifier2'>⊸</span><span class='Function'><</span><span class='Paren'>)</span><span class='Modifier2'>◶</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Function'>F</span> <span class='Value'>n</span><span class='Function'>-</span><span class='Number'>1</span> -<span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=RmFjdF9oZWFkIOKGkCB7IEYgbjoKICBuIMOXICgw4oq4PCnil7Yx4oC/RiBuLTEKfQpGYWN0X2hlYWQgNw==">↗️</a><pre> <span class='Function'>Fact_head</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Function'>F</span> <span class='Value'>n</span><span class='Head'>:</span> + <span class='Value'>n</span> <span class='Function'>×</span> <span class='Paren'>(</span><span class='Number'>0</span><span class='Modifier2'>⊸</span><span class='Function'><</span><span class='Paren'>)</span><span class='Modifier2'>◶</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Function'>F</span> <span class='Value'>n</span><span class='Function'>-</span><span class='Number'>1</span> + <span class='Brace'>}</span> + <span class='Function'>Fact_head</span> <span class='Number'>7</span> +5040 </pre> <p>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 <code><span class='Function'>F</span></code> above is only defined inside the <code><span class='Brace'>{}</span></code> braces while <code><span class='Function'>Fact</span></code> could be used either outside or inside. Some other possibilites are given below.</p> <pre><span class='Comment'># A dyadic function that refers to itself as Func @@ -197,7 +203,11 @@ ⟨ 2 'a' 'b' ⟩ </pre> <p>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.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Q2FzZUFkZCDihpAgeyAy8J2VijM6MOKAvzUgOyAy8J2VivCdlak64p+oMSwyK/Cdlanin6kgOyDwnZWK8J2VqToy4oC/8J2VqSB9CgoyIENhc2VBZGQgMwoKMiBDYXNlQWRkIDQKCiAgQ2FzZUFkZCA0">↗️</a><pre> <span class='Function'>CaseAdd</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Number'>2</span><span class='Function'>𝕊</span><span class='Number'>3</span><span class='Head'>:</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>5</span> <span class='Head'>;</span> <span class='Number'>2</span><span class='Function'>𝕊</span><span class='Value'>𝕩</span><span class='Head'>:</span><span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Separator'>,</span><span class='Number'>2</span><span class='Function'>+</span><span class='Value'>𝕩</span><span class='Bracket'>⟩</span> <span class='Head'>;</span> <span class='Function'>𝕊</span><span class='Value'>𝕩</span><span class='Head'>:</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Value'>𝕩</span> <span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Q2FzZUFkZCDihpAgewogIDLwnZWKMzogMOKAvzUgOwogIDLwnZWK8J2VqTog4p+oMSwyK/Cdlanin6kgOwogICDwnZWK8J2VqTogMuKAv/CdlakKfQoKMiBDYXNlQWRkIDMKCjIgQ2FzZUFkZCA0CgogIENhc2VBZGQgNA==">↗️</a><pre> <span class='Function'>CaseAdd</span> <span class='Gets'>←</span> <span class='Brace'>{</span> + <span class='Number'>2</span><span class='Function'>𝕊</span><span class='Number'>3</span><span class='Head'>:</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>5</span> <span class='Head'>;</span> + <span class='Number'>2</span><span class='Function'>𝕊</span><span class='Value'>𝕩</span><span class='Head'>:</span> <span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Separator'>,</span><span class='Number'>2</span><span class='Function'>+</span><span class='Value'>𝕩</span><span class='Bracket'>⟩</span> <span class='Head'>;</span> + <span class='Function'>𝕊</span><span class='Value'>𝕩</span><span class='Head'>:</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Value'>𝕩</span> + <span class='Brace'>}</span> <span class='Number'>2</span> <span class='Function'>CaseAdd</span> <span class='Number'>3</span> ⟨ 0 5 ⟩ @@ -214,12 +224,14 @@ </pre> <h3 id="case-headers"><a class="header" href="#case-headers">Case headers</a></h3> <p>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 <em>not</em> a plain identifier—it must be <code><span class='Value'>𝕩</span></code> or a compound value like a list to distinguish it from an immediate block label.</p> -<pre><span class='Function'>Test</span> <span class='Gets'>←</span> <span class='Brace'>{</span> - <span class='String'>"abc"</span><span class='Head'>:</span> <span class='String'>"string"</span> <span class='Head'>;</span> - <span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Value'>b</span><span class='Bracket'>⟩</span><span class='Head'>:</span> <span class='Function'>⌽</span><span class='Value'>𝕩</span> <span class='Head'>;</span> - <span class='Number'>5</span><span class='Head'>:</span> <span class='String'>"number"</span> <span class='Head'>;</span> - <span class='Value'>𝕩</span><span class='Head'>:</span> <span class='String'>"default"</span> -<span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=VGVzdCDihpAgewogICJhYmMiOiAic3RyaW5nIiA7CiAg4p+oMixi4p+pOiDijL3wnZWpICAgICAgIDsKICA1OiAgICAgIm51bWJlciIgOwogIPCdlak6ICAgICAiZGVmYXVsdCIKfQpUZXN0IDU=">↗️</a><pre> <span class='Function'>Test</span> <span class='Gets'>←</span> <span class='Brace'>{</span> + <span class='String'>"abc"</span><span class='Head'>:</span> <span class='String'>"string"</span> <span class='Head'>;</span> + <span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Value'>b</span><span class='Bracket'>⟩</span><span class='Head'>:</span> <span class='Function'>⌽</span><span class='Value'>𝕩</span> <span class='Head'>;</span> + <span class='Number'>5</span><span class='Head'>:</span> <span class='String'>"number"</span> <span class='Head'>;</span> + <span class='Value'>𝕩</span><span class='Head'>:</span> <span class='String'>"default"</span> + <span class='Brace'>}</span> + <span class='Function'>Test</span> <span class='Number'>5</span> +"number" </pre> <p>These case-style headers function exactly the same as if they were preceded by <code><span class='Function'>𝕊</span></code>, and can be mixed with other kinds of headers.</p> <h3 id="predicates"><a class="header" href="#predicates">Predicates</a></h3> diff --git a/docs/doc/functional.html b/docs/doc/functional.html index ea4d18ca..f3eea496 100644 --- a/docs/doc/functional.html +++ b/docs/doc/functional.html @@ -70,14 +70,13 @@ <p>What does functional programming in BQN look like? How is it different from the typical APL style of manipulating functions with operators?</p> <h3 id="working-with-roles"><a class="header" href="#working-with-roles">Working with roles</a></h3> <p>First, let's look at the basics: a small program that has functions as its argument and result. The function <code><span class='Function'>Lin</span></code> below gives a <a href="https://en.wikipedia.org/wiki/Linear_approximation">linear approximation</a> to its function argument based on the values at 0 and 1. To find these two values, we call the argument as a function by using its uppercase spelling, <code><span class='Function'>𝕏</span></code>.</p> -<pre><span class='Function'>Lin</span> <span class='Gets'>←</span> <span class='Brace'>{</span> - <span class='Value'>v0</span> <span class='Gets'>←</span> <span class='Function'>𝕏</span> <span class='Number'>0</span> - <span class='Value'>v0</span> <span class='Function'>+</span> <span class='Paren'>((</span><span class='Function'>𝕏</span> <span class='Number'>1</span><span class='Paren'>)</span> <span class='Function'>-</span> <span class='Value'>v0</span><span class='Paren'>)</span> <span class='Function'>×</span> <span class='Function'>⊢</span> -<span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=TGluIOKGkCB7CiAgdjAg4oaQIPCdlY8gMAogIHYwICsgKCjwnZWPIDEpIC0gdjApIMOXIOKKogp9">↗️</a><pre> <span class='Function'>Lin</span> <span class='Gets'>←</span> <span class='Brace'>{</span> + <span class='Value'>v0</span> <span class='Gets'>←</span> <span class='Function'>𝕏</span> <span class='Number'>0</span> + <span class='Value'>v0</span> <span class='Function'>+</span> <span class='Paren'>((</span><span class='Function'>𝕏</span> <span class='Number'>1</span><span class='Paren'>)</span> <span class='Function'>-</span> <span class='Value'>v0</span><span class='Paren'>)</span> <span class='Function'>×</span> <span class='Function'>⊢</span> + <span class='Brace'>}</span> </pre> <p>We can pass it the <a href="arithmetic.html#basic-arithmetic">exponential</a> function as an argument by giving it the name <code><span class='Function'>Exp</span></code> and then referring to it in lowercase (that is, in a subject role). The result is a <a href="train.html">train</a> that adds 1 to <em>e</em>-1 times the argument (we'll discuss only tacit functions here; for blocks see <a href="lexical.html">lexical scoping</a>).</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=TGluIOKGkCB7IHYw4oaQ8J2VjzAg4ouEIHYwKygo8J2VjzEpLXYwKcOX4oqiIH0gICMgKGNvcHkgb2YgYWJvdmUpCkV4cCDihpAg4ouGCkxpbiBleHA=">↗️</a><pre> <span class='Function'>Lin</span> <span class='Gets'>←</span> <span class='Brace'>{</span> <span class='Value'>v0</span><span class='Gets'>←</span><span class='Function'>𝕏</span><span class='Number'>0</span> <span class='Separator'>⋄</span> <span class='Value'>v0</span><span class='Function'>+</span><span class='Paren'>((</span><span class='Function'>𝕏</span><span class='Number'>1</span><span class='Paren'>)</span><span class='Function'>-</span><span class='Value'>v0</span><span class='Paren'>)</span><span class='Function'>×⊢</span> <span class='Brace'>}</span> <span class='Comment'># (copy of above) -</span> <span class='Function'>Exp</span> <span class='Gets'>←</span> <span class='Function'>⋆</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=RXhwIOKGkCDii4YKTGluIGV4cA==">↗️</a><pre> <span class='Function'>Exp</span> <span class='Gets'>←</span> <span class='Function'>⋆</span> <span class='Function'>Lin</span> <span class='Value'>exp</span> 1+1.718281828459045×⊢ </pre> @@ -95,14 +94,13 @@ 148.4131591025766 </pre> <p>Note also in this case that we could have used a modifier with a very similar definition to <code><span class='Function'>Lin</span></code>. The modifier is identical in definition except that <code><span class='Function'>𝕏</span></code> is replaced with <code><span class='Function'>𝔽</span></code>.</p> -<pre><span class='Modifier'>_lin</span> <span class='Gets'>↩</span> <span class='Brace'>{</span> - <span class='Value'>v0</span> <span class='Gets'>←</span> <span class='Function'>𝔽</span> <span class='Number'>0</span> - <span class='Value'>v0</span> <span class='Function'>+</span> <span class='Paren'>((</span><span class='Function'>𝔽</span> <span class='Number'>1</span><span class='Paren'>)</span> <span class='Function'>-</span> <span class='Value'>v0</span><span class='Paren'>)</span> <span class='Function'>×</span> <span class='Function'>⊢</span> -<span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=X2xpbiDihqkgewogIHYwIOKGkCDwnZS9IDAKICB2MCArICgo8J2UvSAxKSAtIHYwKSDDlyDiiqIKfQ==">↗️</a><pre> <span class='Modifier'>_lin</span> <span class='Gets'>↩</span> <span class='Brace'>{</span> + <span class='Value'>v0</span> <span class='Gets'>←</span> <span class='Function'>𝔽</span> <span class='Number'>0</span> + <span class='Value'>v0</span> <span class='Function'>+</span> <span class='Paren'>((</span><span class='Function'>𝔽</span> <span class='Number'>1</span><span class='Paren'>)</span> <span class='Function'>-</span> <span class='Value'>v0</span><span class='Paren'>)</span> <span class='Function'>×</span> <span class='Function'>⊢</span> + <span class='Brace'>}</span> </pre> <p>Its call syntax is simpler as well. In other cases, however, the function version might be preferable, for example when dealing with arrays of functions or many arguments including a function.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=X2xpbiDihqkgeyB2MOKGkPCdlL0wIOKLhCB2MCsoKPCdlL0xKS12MCnDl+KKoiB9ICAjIChjb3B5IGFnYWluKQpFeHAgX2xpbiA1">↗️</a><pre> <span class='Modifier'>_lin</span> <span class='Gets'>↩</span> <span class='Brace'>{</span> <span class='Value'>v0</span><span class='Gets'>←</span><span class='Function'>𝔽</span><span class='Number'>0</span> <span class='Separator'>⋄</span> <span class='Value'>v0</span><span class='Function'>+</span><span class='Paren'>((</span><span class='Function'>𝔽</span><span class='Number'>1</span><span class='Paren'>)</span><span class='Function'>-</span><span class='Value'>v0</span><span class='Paren'>)</span><span class='Function'>×⊢</span> <span class='Brace'>}</span> <span class='Comment'># (copy again) -</span> <span class='Function'>Exp</span> <span class='Modifier'>_lin</span> <span class='Number'>5</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=RXhwIF9saW4gNQ==">↗️</a><pre> <span class='Function'>Exp</span> <span class='Modifier'>_lin</span> <span class='Number'>5</span> 9.591409142295225 </pre> <h3 id="arrays-of-functions"><a class="header" href="#arrays-of-functions">Arrays of functions</a></h3> diff --git a/docs/doc/oop.html b/docs/doc/oop.html index 5915f033..4102ddc1 100644 --- a/docs/doc/oop.html +++ b/docs/doc/oop.html @@ -66,39 +66,39 @@ </table> <h2 id="objects"><a class="header" href="#objects">Objects</a></h2> <p>An object in BQN is simply a namespace: its fields and methods are variables in the namespace, and a variable can be accessed outside of the namespace with dot syntax if it's exported with <code><span class='Gets'>⇐</span></code>. Unexported variables are instance-private in OOP parlance, meaning that they're only visible to the object containing them. They could be utilities, or hold state for the object. As an example, the object below implements the <a href="https://en.wikipedia.org/wiki/Tower_of_Hanoi">Tower of Hanoi</a> puzzle with five disks. You can view the state (a list of disks occupying each of the three rods) with <code><span class='Value'>towerOfHanoi.</span><span class='Function'>View</span></code>, or move the top disk from one rod to another with <code><span class='Value'>towerOfHanoi.</span><span class='Function'>Move</span></code>.</p> -<pre><span class='Value'>towerOfHanoi</span> <span class='Gets'>←</span> <span class='Brace'>{</span> - <span class='Value'>l</span> <span class='Gets'>←</span> <span class='Function'>↕</span><span class='Modifier'>¨</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>0</span> - <span class='Function'>View</span> <span class='Gets'>⇐</span> <span class='Brace'>{</span><span class='Value'>𝕤</span> - <span class='Value'>l</span> - <span class='Brace'>}</span> - <span class='Function'>Move</span> <span class='Gets'>⇐</span> <span class='Brace'>{</span><span class='Value'>from</span><span class='Ligature'>‿</span><span class='Value'>to</span><span class='Head'>:</span> - <span class='Value'>l</span> <span class='Gets'>↩</span> <span class='Function'>Transfer</span><span class='Modifier'>´</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Value'>𝕩</span><span class='Modifier2'>⊸</span><span class='Function'>⊏</span><span class='Paren'>)</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Function'>≠</span><span class='Modifier'>´</span><span class='Value'>𝕩</span><span class='Paren'>)</span> <span class='Value'>l</span> - <span class='Brace'>}</span> - <span class='Comment'># Move a disk from 𝕨 to 𝕩 -</span> <span class='Function'>Transfer</span> <span class='Gets'>←</span> <span class='Brace'>{</span> - <span class='String'>"No disk to move"</span><span class='Function'>!</span><span class='Number'>0</span><span class='Function'><≠</span><span class='Value'>𝕨</span> - <span class='String'>"Can't place larger disk on smaller one"</span><span class='Function'>!</span><span class='Paren'>(</span><span class='Number'>0</span><span class='Function'><≠</span><span class='Paren'>)</span><span class='Modifier2'>◶</span><span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Separator'>,</span><span class='Value'>𝕨</span><span class='Function'><</span><span class='Modifier2'>○</span><span class='Function'>⊑⊢</span><span class='Bracket'>⟩</span><span class='Value'>𝕩</span> - <span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Function'>↓</span><span class='Value'>𝕨</span><span class='Separator'>,</span> <span class='Value'>𝕨</span><span class='Function'>⊏</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span><span class='Value'>𝕩</span><span class='Bracket'>⟩</span> - <span class='Brace'>}</span> -<span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=dG93ZXJPZkhhbm9pIOKGkCB7CiAgbCDihpAg4oaVwqg14oC/MOKAvzAKICBWaWV3IOKHkCB78J2VpAogICAgbAogIH0KICBNb3ZlIOKHkCB7ZnJvbeKAv3RvOgogICAgbCDihqkgVHJhbnNmZXLCtOKMvijwnZWp4oq44oqPKeKNnyjiiaDCtPCdlakpIGwKICB9CiAgIyBNb3ZlIGEgZGlzayBmcm9tIPCdlaggdG8g8J2VqQogIFRyYW5zZmVyIOKGkCB7CiAgICAiTm8gZGlzayB0byBtb3ZlIiEwPOKJoPCdlagKICAgICJDYW4ndCBwbGFjZSBsYXJnZXIgZGlzayBvbiBzbWFsbGVyIG9uZSIhKDA84omgKeKXtuKfqDEs8J2VqDzil4viipHiiqLin6nwnZWpCiAgICDin6gx4oaT8J2VqCwg8J2VqOKKj+KKuOKIvvCdlanin6kKICB9Cn0=">↗️</a><pre> <span class='Value'>towerOfHanoi</span> <span class='Gets'>←</span> <span class='Brace'>{</span> + <span class='Value'>l</span> <span class='Gets'>←</span> <span class='Function'>↕</span><span class='Modifier'>¨</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>0</span> + <span class='Function'>View</span> <span class='Gets'>⇐</span> <span class='Brace'>{</span><span class='Value'>𝕤</span> + <span class='Value'>l</span> + <span class='Brace'>}</span> + <span class='Function'>Move</span> <span class='Gets'>⇐</span> <span class='Brace'>{</span><span class='Value'>from</span><span class='Ligature'>‿</span><span class='Value'>to</span><span class='Head'>:</span> + <span class='Value'>l</span> <span class='Gets'>↩</span> <span class='Function'>Transfer</span><span class='Modifier'>´</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Value'>𝕩</span><span class='Modifier2'>⊸</span><span class='Function'>⊏</span><span class='Paren'>)</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Function'>≠</span><span class='Modifier'>´</span><span class='Value'>𝕩</span><span class='Paren'>)</span> <span class='Value'>l</span> + <span class='Brace'>}</span> + <span class='Comment'># Move a disk from 𝕨 to 𝕩 +</span> <span class='Function'>Transfer</span> <span class='Gets'>←</span> <span class='Brace'>{</span> + <span class='String'>"No disk to move"</span><span class='Function'>!</span><span class='Number'>0</span><span class='Function'><≠</span><span class='Value'>𝕨</span> + <span class='String'>"Can't place larger disk on smaller one"</span><span class='Function'>!</span><span class='Paren'>(</span><span class='Number'>0</span><span class='Function'><≠</span><span class='Paren'>)</span><span class='Modifier2'>◶</span><span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Separator'>,</span><span class='Value'>𝕨</span><span class='Function'><</span><span class='Modifier2'>○</span><span class='Function'>⊑⊢</span><span class='Bracket'>⟩</span><span class='Value'>𝕩</span> + <span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Function'>↓</span><span class='Value'>𝕨</span><span class='Separator'>,</span> <span class='Value'>𝕨</span><span class='Function'>⊏</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span><span class='Value'>𝕩</span><span class='Bracket'>⟩</span> + <span class='Brace'>}</span> + <span class='Brace'>}</span> </pre> <p>Two variables <code><span class='Value'>l</span></code> and <code><span class='Function'>Transfer</span></code> aren't exported, for two different reasons. <code><span class='Value'>l</span></code> encodes the state of the tower, but it's only exposed with the function <code><span class='Function'>View</span></code>, which allows the internal representation to be changed freely. <code><span class='Function'>Transfer</span></code> is just a utility function. While it's not dangerous to use outside of the object, there's no reason to expose it through <code><span class='Value'>towerOfHanoi</span></code>'s interface. If it's wanted in another place it should be moved to a common location.</p> <p>Here are the results of a few applications of these functions.</p> -<pre> <span class='Value'>t</span> <span class='Gets'>←</span> <span class='Value'>towerOfHanoi</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=dCDihpAgdG93ZXJPZkhhbm9pCnQuVmlld0AKCnQuTW92ZSAw4oC/MgoKdC5Nb3ZlIDHigL8yCgp0Lk1vdmUgMOKAvzEKCnQuTW92ZSAy4oC/MQ==">↗️</a><pre> <span class='Value'>t</span> <span class='Gets'>←</span> <span class='Value'>towerOfHanoi</span> <span class='Value'>t.</span><span class='Function'>View</span><span class='String'>@</span> -<span class='Bracket'>⟨</span> <span class='Bracket'>⟨</span> <span class='Number'>0</span> <span class='Number'>1</span> <span class='Number'>2</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨⟩</span> <span class='Bracket'>⟨⟩</span> <span class='Bracket'>⟩</span> +⟨ ⟨ 0 1 2 3 4 ⟩ ⟨⟩ ⟨⟩ ⟩ <span class='Value'>t.</span><span class='Function'>Move</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>2</span> -<span class='Bracket'>⟨</span> <span class='Bracket'>⟨</span> <span class='Number'>1</span> <span class='Number'>2</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨⟩</span> <span class='Bracket'>⟨</span> <span class='Number'>0</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟩</span> +⟨ ⟨ 1 2 3 4 ⟩ ⟨⟩ ⟨ 0 ⟩ ⟩ <span class='Value'>t.</span><span class='Function'>Move</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</span> -<span class='Function'>!</span> <span class='String'>"No disk to move"</span> +<span class='Error'>Error: No disk to move</span> <span class='Value'>t.</span><span class='Function'>Move</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span> -<span class='Bracket'>⟨</span> <span class='Bracket'>⟨</span> <span class='Number'>2</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨</span> <span class='Number'>1</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨</span> <span class='Number'>0</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟩</span> +⟨ ⟨ 2 3 4 ⟩ ⟨ 1 ⟩ ⟨ 0 ⟩ ⟩ <span class='Value'>t.</span><span class='Function'>Move</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span> -<span class='Bracket'>⟨</span> <span class='Bracket'>⟨</span> <span class='Number'>2</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨</span> <span class='Number'>0</span> <span class='Number'>1</span> <span class='Bracket'>⟩</span> <span class='Bracket'>⟨⟩</span> <span class='Bracket'>⟩</span> +⟨ ⟨ 2 3 4 ⟩ ⟨ 0 1 ⟩ ⟨⟩ ⟩ </pre> <h2 id="classes"><a class="header" href="#classes">Classes</a></h2> <p>The object above is a singleton: there's just one of it, at least in the scope it occupies. It's often more useful to have a class that can be used to create objects. What we'll call a "class" is a namespace function, that is, a function that contains <code><span class='Gets'>⇐</span></code> and so returns a namespace. It's very easy to convert a singleton object to a class: <a href="control.html#blocks-and-functions">just add</a> a no-op <code><span class='Value'>𝕤</span></code> line to force it to be a function, and call it with <code><span class='String'>@</span></code> when needed.</p> diff --git a/docs/doc/quick.html b/docs/doc/quick.html index 28ff1248..8a13379b 100644 --- a/docs/doc/quick.html +++ b/docs/doc/quick.html @@ -39,12 +39,13 @@ <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'>"hello.bqn"</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> -<pre><span class='Comment'># Case conversion utilities -</span><span class='Value'>case</span> <span class='Gets'>←</span> <span class='Brace'>{</span> - <span class='Value'>diff</span> <span class='Gets'>←</span> <span class='Function'>-</span><span class='Modifier'>´</span> <span class='String'>"Aa"</span> - <span class='Function'>Lower</span> <span class='Gets'>⇐</span> <span class='Function'>-</span><span class='Modifier2'>⟜</span><span class='Value'>diff</span> - <span class='Function'>Upper</span> <span class='Gets'>⇐</span> <span class='Function'>Lower</span><span class='Modifier'>⁼</span> -<span class='Brace'>}</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=IyBDYXNlIGNvbnZlcnNpb24gdXRpbGl0aWVzCmNhc2Ug4oaQIHsKICBkaWZmIOKGkCAtwrQgIkFhIgogIExvd2VyIOKHkCAt4p+cZGlmZgogIFVwcGVyIOKHkCBMb3dlcuKBvAp9">↗️</a><pre> <span class='Comment'># Case conversion utilities +</span><span class='Error'>Error: Empty program</span> + <span class='Value'>case</span> <span class='Gets'>←</span> <span class='Brace'>{</span> + <span class='Value'>diff</span> <span class='Gets'>←</span> <span class='Function'>-</span><span class='Modifier'>´</span> <span class='String'>"Aa"</span> + <span class='Function'>Lower</span> <span class='Gets'>⇐</span> <span class='Function'>-</span><span class='Modifier2'>⟜</span><span class='Value'>diff</span> + <span class='Function'>Upper</span> <span class='Gets'>⇐</span> <span class='Function'>Lower</span><span class='Modifier'>⁼</span> + <span class='Brace'>}</span> </pre> <p>This part of the code defines a <a href="namespace.html">namespace</a> using braces <code><span class='Brace'>{}</span></code>, then <a href="expression.html#assignment">assigns</a> it to the name <code><span class='Value'>case</span></code>. There are three assignments inside the namespace too. Since BQN uses <a href="lexical.html">lexical scoping</a>, code outside the namespace can't access the variables <code><span class='Value'>diff</span></code>, <code><span class='Function'>Lower</span></code>, and <code><span class='Function'>Upper</span></code> directly. Oh, and the first line is a <a href="token.html#comments">comment</a>.</p> <p>The value <code><span class='Value'>diff</span></code> is the result of applying a <a href="ops.html#functions">function</a> <code><span class='Function'>-</span><span class='Modifier'>´</span></code> to the argument <code><span class='String'>"Aa"</span></code>. Function application is always written just by placing a function next to its arguments like this—a prefix application if there's one argument, infix if there are two, and that's the most arguments you can have. This doesn't limit BQN's capabilities because it's easy to pass a list as an argument. In fact, <code><span class='String'>"Aa"</span></code> is a <a href="token.html#characters-and-strings">string</a>, which means a list of characters. Characters are written with single quotes, so it's a list of <code><span class='String'>'A'</span></code> and <code><span class='String'>'a'</span></code>.</p> @@ -138,27 +139,26 @@ <pre><span class='Value'>hw</span> <span class='Value'>case.</span><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Paren'>)</span><span class='Gets'>↩</span> </pre> <p>This statement consists of the name <code><span class='Value'>hw</span></code> just defined, a compound function, and then the new character <code><span class='Gets'>↩</span></code>. This is another form of <a href="expression.html#assignment">assignment</a>, like <code><span class='Gets'>←</span></code>, but it changes the value of an existing variable instead of defining a new one. There's also some special <code><span class='Gets'>↩</span></code> syntax here: the expression <code><span class='Value'>val</span> <span class='Function'>Fn</span><span class='Gets'>↩</span></code> is shorthand for <code><span class='Value'>val</span> <span class='Gets'>↩</span> <span class='Function'>Fn</span> <span class='Value'>val</span></code>, avoiding the need to write the name <code><span class='Value'>hw</span></code> twice (and <code><span class='Value'>val</span> <span class='Function'>Fn</span><span class='Gets'>↩</span> <span class='Value'>arg</span></code> means <code><span class='Value'>val</span> <span class='Gets'>↩</span> <span class='Value'>val</span> <span class='Function'>Fn</span> <span class='Value'>arg</span></code>, like <code><span class='Function'>+=</span></code> and so on from C). So we are modifying <code><span class='Value'>hw</span></code> by applying this function <code><span class='Value'>case.</span><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Paren'>)</span></code>.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=aHcg4oaQIDzLmCAy4oC/4oiYIOKliiAiaGVsbG93b3JsZCIKVXBwZXIg4oaQIC3in5woLcK0IkFhIinigbwKClVwcGVy4oy+KOKKkcKoKSBodwoKaHcgVXBwZXLijL4o4oqRwqgp4oapICAjIFNldHMgbmV3IHZhbHVlIGZvciBodw==">↗️</a><pre> <span class='Value'>hw</span> <span class='Gets'>←</span> <span class='Function'><</span><span class='Modifier'>˘</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Modifier2'>∘</span> <span class='Function'>⥊</span> <span class='String'>"helloworld"</span> - <span class='Function'>Upper</span> <span class='Gets'>←</span> <span class='Function'>-</span><span class='Modifier2'>⟜</span><span class='Paren'>(</span><span class='Function'>-</span><span class='Modifier'>´</span><span class='String'>"Aa"</span><span class='Paren'>)</span><span class='Modifier'>⁼</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=aHcg4oaQIDzLmCAy4oC/4oiYIOKliiAiaGVsbG93b3JsZCIKCmNhc2UuVXBwZXLijL4o4oqRwqgpIGh3CgpodyBjYXNlLlVwcGVy4oy+KOKKkcKoKeKGqSAgIyBTZXRzIG5ldyB2YWx1ZSBmb3IgaHc=">↗️</a><pre> <span class='Value'>hw</span> <span class='Gets'>←</span> <span class='Function'><</span><span class='Modifier'>˘</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Modifier2'>∘</span> <span class='Function'>⥊</span> <span class='String'>"helloworld"</span> - <span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Paren'>)</span> <span class='Value'>hw</span> + <span class='Value'>case.</span><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Paren'>)</span> <span class='Value'>hw</span> ⟨ "Hello" "World" ⟩ - <span class='Value'>hw</span> <span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Paren'>)</span><span class='Gets'>↩</span> <span class='Comment'># Sets new value for hw + <span class='Value'>hw</span> <span class='Value'>case.</span><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Paren'>)</span><span class='Gets'>↩</span> <span class='Comment'># Sets new value for hw </span>⟨ "Hello" "World" ⟩ </pre> <p>That converts the first character of each string to uppercase! <code><span class='Value'>case.</span><span class='Function'>Upper</span></code> is the case conversion function defined before, so that part makes sense. The rest of the function, <code><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Paren'>)</span></code>, would be pronounced "<a href="under.html">Under</a> the <a href="pick.html#first">First</a> of <a href="map.html#one-argument-mapping">Each</a>", which… pretty much makes sense too? The First Each function extracts the first element of each list in <code><span class='Value'>hw</span></code>, the part that used to be <code><span class='String'>"hw"</span></code> but is now <code><span class='String'>"HW"</span></code>.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqRwqggaHcKClVwcGVyICJodyI=">↗️</a><pre> <span class='Function'>⊑</span><span class='Modifier'>¨</span> <span class='Value'>hw</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqRwqggaHcKCmNhc2UuVXBwZXIgImh3Ig==">↗️</a><pre> <span class='Function'>⊑</span><span class='Modifier'>¨</span> <span class='Value'>hw</span> "HW" - <span class='Function'>Upper</span> <span class='String'>"hw"</span> + <span class='Value'>case.</span><span class='Function'>Upper</span> <span class='String'>"hw"</span> "HW" </pre> -<p>The Under modifier keeps track of where that string came from and puts it <em>back</em>, to produce a new, altered array. It's kind of special, like Undo, but works on all sorts of fancy selections. It's also worth pointing out that <code><span class='Function'>Upper</span></code> applies to a string here, not an individual character. That's because arithmetic is <a href="arithmetic.html#pervasion">pervasive</a>, so that functions made of arithmetic naturally work on arrays. Although in this case it wasn't really necessary, because it's also possible to map over the two strings and uppercase the first character of each separately:</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=VXBwZXLijL7iipHCqCAiaGVsbG8i4oC/IndvcmxkIg==">↗️</a><pre> <span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Function'>⊑</span><span class='Modifier'>¨</span> <span class='String'>"hello"</span><span class='Ligature'>‿</span><span class='String'>"world"</span> +<p>The Under modifier keeps track of where that string came from and puts it <em>back</em>, to produce a new, altered array. It's kind of special, like Undo, but works on all sorts of fancy selections. It's also worth pointing out that <code><span class='Value'>case.</span><span class='Function'>Upper</span></code> applies to a string here, not an individual character. That's because arithmetic is <a href="arithmetic.html#pervasion">pervasive</a>, so that functions made of arithmetic naturally work on arrays. Although in this case it wasn't really necessary, because it's also possible to map over the two strings and uppercase the first character of each separately:</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Y2FzZS5VcHBlcuKMvuKKkcKoICJoZWxsbyLigL8id29ybGQi">↗️</a><pre> <span class='Value'>case.</span><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Function'>⊑</span><span class='Modifier'>¨</span> <span class='String'>"hello"</span><span class='Ligature'>‿</span><span class='String'>"world"</span> ⟨ "Hello" "World" ⟩ </pre> -<p>Modifiers are applied from left to right, opposite to functions (1-modifiers also take the operand on the left while prefix functions have the argument on the right). So <code><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Function'>⊑</span><span class='Modifier'>¨</span></code> means <code><span class='Paren'>(</span><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Function'>⊑</span><span class='Paren'>)</span><span class='Modifier'>¨</span></code>.</p> +<p>Modifiers are applied from left to right, opposite to functions (1-modifiers also take the operand on the left while prefix functions have the argument on the right). So <code><span class='Value'>case.</span><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Function'>⊑</span><span class='Modifier'>¨</span></code> means <code><span class='Paren'>(</span><span class='Value'>case.</span><span class='Function'>Upper</span><span class='Modifier2'>⌾</span><span class='Function'>⊑</span><span class='Paren'>)</span><span class='Modifier'>¨</span></code>.</p> <h3 id="punctuation-and-printing"><a class="header" href="#punctuation-and-printing">Punctuation and printing</a></h3> <p>The variable <code><span class='Value'>hw</span></code> is modified one more time, then printed, producing the output Hello, World!</p> <pre><span class='Function'>•Out</span> <span class='Value'>hw</span> <span class='Gets'>↩</span> <span class='Function'>∾</span> <span class='Function'>⥊⍉</span> <span class='Bracket'>[</span><span class='Value'>hw</span><span class='Separator'>,</span> <span class='String'>", "</span><span class='Ligature'>‿</span><span class='String'>"!"</span><span class='Bracket'>]</span> <span class='Comment'># Hello, World! |
