diff options
| -rw-r--r-- | docs/tutorial/combinator.html | 15 | ||||
| -rw-r--r-- | docs/tutorial/index.html | 2 | ||||
| -rw-r--r-- | tutorial/README.md | 2 | ||||
| -rw-r--r-- | tutorial/combinator.md | 10 |
4 files changed, 26 insertions, 3 deletions
diff --git a/docs/tutorial/combinator.html b/docs/tutorial/combinator.html index 65b223ab..23a2d410 100644 --- a/docs/tutorial/combinator.html +++ b/docs/tutorial/combinator.html @@ -14,6 +14,16 @@ 6 </pre> <p>This composition starts with the three values <code><span class='Function'>|</span></code>, <code><span class='Function'>-</span></code>, and <code><span class='Number'>6</span></code>. To produce its result, it first applies <code><span class='Function'>-</span></code> to <code><span class='Number'>6</span></code>, giving <code><span class='Number'>¯6</span></code>, a new value that it's free to use later. Then it applies <code><span class='Function'>|</span></code> to <code><span class='Number'>¯6</span></code>, giving <code><span class='Number'>6</span></code> again. Bit of a waste.</p> +<table class='primitives'> + <tr> + <td><span class='Function'>|</span></td> + <td></td> + <td>Absolute Value</td> + <td></td> + </tr> +</table> + +<p>Oh, right, <code><span class='Function'>|</span></code> is another one of those math class things, the absolute value. It makes negative numbers positive, and leaves positive ones alone, so |-6| is 6. But Iverson worked out a neat trick when he turned his mathematical notation into a programming language: if we write <code><span class='Function'>|</span><span class='Number'>¯6</span></code> without the trailing bar, then <code><span class='Function'>|</span></code> can be an ordinary one-argument function. Which means it can be used as an operand to the combinator <code><span class='Modifier2'>∘</span></code> for example.</p> <p>In BQN's combinators, the result of a function application is never used as a function itself. This allows us to use a graphic like the one below to represent a combinator. In each graph, function applications are illustrated with the name of the function linked by yellow lines to its arguments below (this is the same view as the expression diagrams we've been using, flipped upside down and cleaned up a little).</p> <svg viewBox='-191 0 672 270'> <g font-size='20px' text-anchor='middle' transform='translate(145,20)'> @@ -609,6 +619,11 @@ </thead> <tbody> <tr> +<td><code><span class='Function'>|</span></code></td> +<td><a href="../doc/arithmetic.html#additional-arithmetic">Absolute Value</a></td> +<td></td> +</tr> +<tr> <td><code><span class='Function'><</span></code></td> <td></td> <td><a href="../doc/arithmetic.html#comparisons">Less Than</a></td> diff --git a/docs/tutorial/index.html b/docs/tutorial/index.html index ded09fb1..b0aabdc7 100644 --- a/docs/tutorial/index.html +++ b/docs/tutorial/index.html @@ -30,7 +30,7 @@ <tr> <td><a href="combinator.html">Combinators</a></td> <td>Tacit programming, booleans</td> -<td><code><span class='Function'><>≠=≤≥≡≢</span><span class='Modifier2'>○⊸⟜</span></code></td> +<td><code><span class='Function'>|<>≠=≤≥≡≢</span><span class='Modifier2'>○⊸⟜</span></code></td> </tr> <tr> <td><a href="variable.html">Variables</a></td> diff --git a/tutorial/README.md b/tutorial/README.md index 98813365..c02c4725 100644 --- a/tutorial/README.md +++ b/tutorial/README.md @@ -12,5 +12,5 @@ The tutorials available so far: |------------------------------|----------|----------- | [Expressions](expression.md) | Arithmetic, syntax, affine characters | `+-×÷⋆√˜⁼˙∘` | [List manipulation](list.md) | Lists, strings, and strands; pervasion | `∾⋈⌽↕¨´` -| [Combinators](combinator.md) | Tacit programming, booleans | `<>≠=≤≥≡≢○⊸⟜` +| [Combinators](combinator.md) | Tacit programming, booleans | `\|<>≠=≤≥≡≢○⊸⟜` | [Variables](variable.md) | Declarations, cross-roles | `∧∨¬⊣⊢↑↓«»⌾` diff --git a/tutorial/combinator.md b/tutorial/combinator.md index 7ae8237c..70f03cfa 100644 --- a/tutorial/combinator.md +++ b/tutorial/combinator.md @@ -16,6 +16,13 @@ There are benefits to being tightly restricted and horribly confined! In program This composition starts with the three values `|`, `-`, and `6`. To produce its result, it first applies `-` to `6`, giving `¯6`, a new value that it's free to use later. Then it applies `|` to `¯6`, giving `6` again. Bit of a waste. +<!--GEN prim.bqn +Primitives ⟨ + "|%%Absolute Value%" +⟩ +--> +Oh, right, `|` is another one of those math class things, the absolute value. It makes negative numbers positive, and leaves positive ones alone, so |-6| is 6. But Iverson worked out a neat trick when he turned his mathematical notation into a programming language: if we write `|¯6` without the trailing bar, then `|` can be an ordinary one-argument function. Which means it can be used as an operand to the combinator `∘` for example. + In BQN's combinators, the result of a function application is never used as a function itself. This allows us to use a graphic like the one below to represent a combinator. In each graph, function applications are illustrated with the name of the function linked by yellow lines to its arguments below (this is the same view as the expression diagrams we've been using, flipped upside down and cleaned up a little). <!--GEN ../doc/combinator.bqn @@ -33,7 +40,7 @@ So `|∘-` is the absolute difference: a useful function for a change! If we hav This means that if you are at 14th and 8th, and want to get to 19th and 6th, or vice-versa, you must walk at least seven blocks total: five to get from 14th to 19th and two from 8th to 6th, not necessarily in that order. The function `+´∘|∘-` actually uses both cases of `∘`: the one-argument case for `+´∘|`, and the two argument case for the `∘-` part. -<!--GEN prim.bqn +<!--GEN Primitives ⟨ "˜%`%Self%Swap" "˙%""%Constant" @@ -297,6 +304,7 @@ BQN has a full complement of comparison functions, which are pervasive (work on Glyph | 1 arg | 2 args ------|---------------------------|-------- +`\|` | [Absolute Value](../doc/arithmetic.md#additional-arithmetic) | `<` | | [Less Than](../doc/arithmetic.md#comparisons) `>` | | [Greater Than](../doc/arithmetic.md#comparisons) `≠` | [Length](../doc/shape.md) | [Not Equals](../doc/arithmetic.md#comparisons) |
