diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-04-13 22:28:55 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-04-13 22:28:55 -0400 |
| commit | 7273e5bec783772f6d61e056b5c138c70fd58663 (patch) | |
| tree | 050d63a412d86d7b0f7a12509d601d09262dbc50 /docs/doc | |
| parent | d291cb7faf2c1856e2cea486b0d935bbb16db2c9 (diff) | |
Documentation for Constant
Diffstat (limited to 'docs/doc')
| -rw-r--r-- | docs/doc/constant.html | 55 | ||||
| -rw-r--r-- | docs/doc/index.html | 1 | ||||
| -rw-r--r-- | docs/doc/primitive.html | 2 |
3 files changed, 57 insertions, 1 deletions
diff --git a/docs/doc/constant.html b/docs/doc/constant.html new file mode 100644 index 00000000..524a13f5 --- /dev/null +++ b/docs/doc/constant.html @@ -0,0 +1,55 @@ +<head> + <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/> + <link href="../style.css" rel="stylesheet"/> + <title>BQN: Constant</title> +</head> +<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">doc</a></div> +<h1 id="constant"><a class="header" href="#constant">Constant</a></h1> +<svg viewBox='-191 0 672 270'> + <g font-size='20px' text-anchor='middle' transform='translate(145,20)'> + <rect class='code' stroke-width='1' rx='12' x='-120.4' y='1' width='240.8' height='205'/> + <text dy='0.32em' y='223' fill='currentColor'>Constant</text> + <g font-size='21px' font-family='BQN,monospace' transform='translate(-60.87,25)'> + <text dy='0.32em' y='155' font-size='19px'><tspan class='Value'>๐</tspan><tspan class='Modifier'>ห</tspan> <tspan class='Value'>๐ฉ</tspan></text> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0L0 57'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='57'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='114'/> + <text dy='0.32em' x='0' y='57'><tspan class='Value'>๐</tspan></text> + <text dy='0.32em' x='0' y='114'><tspan class='Value'>๐ฉ</tspan></text> + </g> + <g font-size='21px' font-family='BQN,monospace' transform='translate(60.87,25)'> + <text dy='0.32em' y='155' font-size='19px'><tspan class='Value'>๐จ</tspan> <tspan class='Value'>๐</tspan><tspan class='Modifier'>ห</tspan> <tspan class='Value'>๐ฉ</tspan></text> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0L0 57'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='57'/> + <circle r='12' class='code' stroke-width='0' cx='-32' cy='114'/> + <circle r='12' class='code' stroke-width='0' cx='32' cy='114'/> + <text dy='0.32em' x='0' y='57'><tspan class='Value'>๐</tspan></text> + <text dy='0.32em' x='-32' y='114'><tspan class='Value'>๐จ</tspan></text> + <text dy='0.32em' x='32' y='114'><tspan class='Value'>๐ฉ</tspan></text> + </g> + </g> +</svg> + +<p>It's one of the simple ones: <code><span class='Value'>f</span><span class='Modifier'>ห</span><span class='Value'>๐ฉ</span></code> is <code><span class='Value'>f</span></code>. And <code><span class='Value'>๐จf</span><span class='Modifier'>ห</span><span class='Value'>๐ฉ</span></code>? It's <code><span class='Value'>f</span></code>. Like the <a href="identity.html">identity functions</a>, Constant doesn't compute anything but just returns one of its inputs. It's somewhat different in that it's a deferred modifier, so you have to first apply Constant to its operand and <em>then</em> to some arguments for that non-event to happen.</p> +<p>The design of BQN makes Constant unnecessary in most cases, because when a non-operation (number, character, array, namespace) is applied it already returns itself: <code><span class='Number'>ฯ</span><span class='Modifier'>ห</span></code> is the same function as <code><span class='Number'>ฯ</span></code>. If you've used much <a href="tacit.html">tacit</a> programming, you've probably written a few <a href="train.html">trains</a> like <code><span class='Number'>2</span><span class='Function'>ร+</span></code> (twice the sum), which is nicer than the equivalent <code><span class='Number'>2</span><span class='Modifier'>ห</span><span class='Function'>ร+</span></code>. However, a train has to end with a function, so you can't just put a number at the end. Applying <code><span class='Modifier'>ห</span></code> is a convenient way to change the number from a subject to a function role.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K8O3MiAgICMgQSBudW1iZXIKCivDtzLLmSAgIyBBIGZ1bmN0aW9uCgozICgrw7cyy5kpIDc=">โ๏ธ</a><pre> <span class='Function'>+รท</span><span class='Number'>2</span> <span class='Comment'># A number +</span>0.5 + + <span class='Function'>+รท</span><span class='Number'>2</span><span class='Modifier'>ห</span> <span class='Comment'># A function +</span>+รท2ห + + <span class='Number'>3</span> <span class='Paren'>(</span><span class='Function'>+รท</span><span class='Number'>2</span><span class='Modifier'>ห</span><span class='Paren'>)</span> <span class='Number'>7</span> +5 +</pre> +<p>When programming with <a href="functional.html">first-class functions</a>, the constant application shortcut becomes a hazard! Consider the program <code><span class='Brace'>{</span><span class='Value'>๐จ</span><span class='Modifier2'>โพ</span><span class='Paren'>(</span><span class='Number'>2</span><span class='Modifier2'>โธ</span><span class='Function'>โ</span><span class='Paren'>)</span> <span class='Value'>๐ฉ</span><span class='Brace'>}</span></code> to insert <code><span class='Value'>๐จ</span></code> into an array <code><span class='Value'>๐ฉ</span></code> as an element. It works fine with a number, but with a function it's broken:</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oieIHvwnZWo4oy+KDLiirjiipEpIPCdlal9IDHigL8y4oC/M+KAvzQKCk0g4oaQIC0KbSB78J2VqOKMvigy4oq44oqRKSDwnZWpfSAx4oC/MuKAvzPigL80">โ๏ธ</a><pre> <span class='Number'>โ</span> <span class='Brace'>{</span><span class='Value'>๐จ</span><span class='Modifier2'>โพ</span><span class='Paren'>(</span><span class='Number'>2</span><span class='Modifier2'>โธ</span><span class='Function'>โ</span><span class='Paren'>)</span> <span class='Value'>๐ฉ</span><span class='Brace'>}</span> <span class='Number'>1</span><span class='Ligature'>โฟ</span><span class='Number'>2</span><span class='Ligature'>โฟ</span><span class='Number'>3</span><span class='Ligature'>โฟ</span><span class='Number'>4</span> +โจ 1 2 โ 4 โฉ + + <span class='Function'>M</span> <span class='Gets'>โ</span> <span class='Function'>-</span> + <span class='Value'>m</span> <span class='Brace'>{</span><span class='Value'>๐จ</span><span class='Modifier2'>โพ</span><span class='Paren'>(</span><span class='Number'>2</span><span class='Modifier2'>โธ</span><span class='Function'>โ</span><span class='Paren'>)</span> <span class='Value'>๐ฉ</span><span class='Brace'>}</span> <span class='Number'>1</span><span class='Ligature'>โฟ</span><span class='Number'>2</span><span class='Ligature'>โฟ</span><span class='Number'>3</span><span class='Ligature'>โฟ</span><span class='Number'>4</span> +โจ 1 2 ยฏ3 4 โฉ +</pre> +<p>Here <code><span class='Value'>m</span></code> is applied to <code><span class='Number'>2</span><span class='Function'>โ</span><span class='Value'>๐ฉ</span></code> even though we want to discard that value. Spelled as <code><span class='Value'>m</span></code>, our <a href="context.html">context-free grammar</a> knows it's a function argument, but this <a href="../problems.html#syntactic-type-erasure">doesn't affect</a> later usage. Under always applies <code><span class='Function'>๐ฝ</span></code> as a function. The proper definition of the insertion function should use a <code><span class='Modifier'>ห</span></code>, like this:</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=bSB78J2VqMuZ4oy+KDLiirjiipEpIPCdlal9IDHigL8y4oC/M+KAvzQ=">โ๏ธ</a><pre> <span class='Value'>m</span> <span class='Brace'>{</span><span class='Value'>๐จ</span><span class='Modifier'>ห</span><span class='Modifier2'>โพ</span><span class='Paren'>(</span><span class='Number'>2</span><span class='Modifier2'>โธ</span><span class='Function'>โ</span><span class='Paren'>)</span> <span class='Value'>๐ฉ</span><span class='Brace'>}</span> <span class='Number'>1</span><span class='Ligature'>โฟ</span><span class='Number'>2</span><span class='Ligature'>โฟ</span><span class='Number'>3</span><span class='Ligature'>โฟ</span><span class='Number'>4</span> +โจ 1 2 - 4 โฉ +</pre> diff --git a/docs/doc/index.html b/docs/doc/index.html index 38f7d2cd..5d303de3 100644 --- a/docs/doc/index.html +++ b/docs/doc/index.html @@ -48,6 +48,7 @@ <li><a href="shape.html">Array dimensions</a> (<code><span class='Function'>โข=โ </span></code>)</li> <li><a href="assert.html">Assert and Catch</a> (<code><span class='Function'>!</span></code> and <code><span class='Modifier2'>โ</span></code>)</li> <li><a href="compose.html">Atop and Over</a> (<code><span class='Modifier2'>โโ</span></code>)</li> +<li><a href="constant.html">Constant</a> (<code><span class='Modifier'>ห</span></code>)</li> <li><a href="reshape.html">Deshape and Reshape</a> (<code><span class='Function'>โฅ</span></code>)</li> <li><a href="enclose.html">Enclose</a> (<code><span class='Function'><</span></code>)</li> <li><a href="find.html">Find</a> (<code><span class='Function'>โท</span></code>)</li> diff --git a/docs/doc/primitive.html b/docs/doc/primitive.html index c4b48a20..1601ed08 100644 --- a/docs/doc/primitive.html +++ b/docs/doc/primitive.html @@ -425,7 +425,7 @@ <tbody> <tr> <td><code><span class='Modifier'>ห</span></code></td> -<td>Constant</td> +<td><a href="constant.html">Constant</a></td> <td><code><span class='Brace'>{</span><span class='Value'>๐ฉ</span><span class='Separator'>โ</span><span class='Value'>๐</span><span class='Brace'>}</span></code></td> <td>Return a function that returns the operand</td> </tr> |
