diff options
| -rw-r--r-- | doc/README.md | 1 | ||||
| -rw-r--r-- | doc/hook.md | 61 | ||||
| -rw-r--r-- | doc/primitive.md | 4 | ||||
| -rw-r--r-- | docs/doc/hook.html | 161 | ||||
| -rw-r--r-- | docs/doc/index.html | 1 | ||||
| -rw-r--r-- | docs/doc/primitive.html | 4 | ||||
| -rw-r--r-- | docs/help/after_bind.html | 3 | ||||
| -rw-r--r-- | docs/help/before_bind.html | 3 | ||||
| -rw-r--r-- | help/after_bind.md | 3 | ||||
| -rw-r--r-- | help/before_bind.md | 3 |
10 files changed, 240 insertions, 4 deletions
diff --git a/doc/README.md b/doc/README.md index 98c61d51..51b00436 100644 --- a/doc/README.md +++ b/doc/README.md @@ -42,6 +42,7 @@ Primitives: - [Array dimensions](shape.md) (`≢=≠`) - [Assert and Catch](assert.md) (`!` and `⎊`) - [Atop and Over](compose.md) (`∘○`) +- [Before and After](hook.md) (`⊸⟜`) - [Choose](choose.md) (`◶`) - [Constant](constant.md) (`˙`) - [Deshape and Reshape](reshape.md) (`⥊`) diff --git a/doc/hook.md b/doc/hook.md new file mode 100644 index 00000000..0eb5d5ce --- /dev/null +++ b/doc/hook.md @@ -0,0 +1,61 @@ +*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/doc/hook.html).* + +# Before and After + +([This joke](https://aplwiki.com/wiki/File:Before_and_after.jpg) has already been claimed by APL, unfortunately) + +*Also see [this tutorial section](../tutorial/combinator.md#before-and-after) for an introduction that doesn't require so much context to understand.* + +<!--GEN combinator.bqn +DrawComp ≍"⊸⟜" +--> + +The "hook" combinators Before and After serve a few purposes in BQN. The important thing to remember: the pointy side goes towards the first function to be executed, and the next function that returns the final result is at the ring side. If the pointy-side function is actually a constant like a number, then the ring-side function just gets applied to that constant and one of the arguments. This is the thing Haskell programmers are constantly telling each other isn't called currying, or "Bind" in BQN. + +| Name | `Cmp` | `Cmp 𝕩` | `𝕨 Cmp 𝕩` | Unified | Train +|--------|-------|------------|------------|--------------|-------- +| Before | `F⊸G` | `(F𝕩) G 𝕩` | `(F𝕨) G 𝕩` | `{(𝔽𝕨⊣𝕩)𝔾𝕩}` | `F∘⊣ G ⊢` +| After | `F⟜G` | `𝕩 F (G𝕩)` | `𝕨 F (G𝕩)` | `{(𝕨⊣𝕩)𝔽𝔾𝕩}` | `⊣ F G∘⊢` + +## Description + +In the general case, I think of Before as using `𝔽` as a preprocessing function applied to `𝕨` (when there are two arguments) and After as using `𝔾` as preprocessing for `𝕩`. Then the other operand is called on the result and remaining argument. Here are some simple calls with Pair (`⋈`): the result is a pair that corresponds to `𝕨‿𝕩`, but one or the other result has been modified by the pointy-side function. + + 9 √⊸⋈ 2 + + 9 ⋈⟜↕ 2 + +When only one argument is given, it's used in both positions, so that the arguments to the final function are `𝕩` and a function applied to `𝕩`. + + ⋈⟜↕ 5 + +This can be used to make a "filter" pattern using [Replicate](replicate.md) (`/`). The difference is that Replicate takes a list `𝕩` and boolean list `𝕨` indicating which elements to keep, but filter should take a list and a function that says whether to keep each element. The pattern is `F¨⊸/ x`, expanding to `(F¨x) / x`. Here's a list filtered with the function `{𝕩<0}`. + + {𝕩<0}¨⊸/ 4‿¯2‿1‿¯3‿¯3 + +As `<` is a pervasive function, there's no need for the Each (`¨`) in this case, and the clunky block function `{𝕩<0}` can also be written smaller with a combinator, as `<⟜0`. More on that in the next section… + + <⟜0⊸/ 4‿¯2‿1‿¯3‿¯3 + +## Bind + +"Bind" isn't a special case of Before and After, but instead a description of one way to use them. Let's take a look at the example from the previous section: + + <⟜0 4‿¯2‿1‿¯3‿¯3 + +If we expand `<⟜0 x`, we get `x < (0 x)`, which doesn't quite make sense. That's because `0` has a subject role, but `⟜` always applies its operands as functions. It's more accurate to use `x < (0{𝔽} x)`, or just skip ahead to `x < 0`. + +Similar reasoning gives the following expansions: + +| `Cmp` | `0⊸<` | `<⟜0` +|-----------|---------|--------- +| ` Cmp x` | `0 < x` | `x < 0` +| `w Cmp x` | `0 < x` | `w < 0` + +Note that when there are two arguments, the constant "swallows" the one on the same side, so that the function is applied to the constant and the argument on the *opposite* side. + +As in a train, if you want to use a function as a constant then you need to be explicity about it, with the [Constant](constant.md) (`˙`) modifier. + + 3 ⋈⟜(⌊˙)⊸⥊ 'a'+↕12 + +In the more extreme case of wanting a *modifier* operand, you might try `⋈⟜({∘}˙)⊸⥊`, or `(⊣⋈{∘}˙)⊸⥊`, or just cheat with `∾⟜⟨∘⟩⊸⥊`. diff --git a/doc/primitive.md b/doc/primitive.md index 79d6120b..f29dea71 100644 --- a/doc/primitive.md +++ b/doc/primitive.md @@ -71,8 +71,8 @@ Glyph | Name(s) | Definition | Description `˜` | [Self/Swap](swap.md) | `{𝕩𝔽𝕨⊣𝕩}` | Duplicate one argument or exchange two `∘` | [Atop](compose.md) | `{𝔽𝕨𝔾𝕩}` | Apply `𝔾` to both arguments and `𝔽` to the result `○` | [Over](compose.md) | `{(𝔾𝕨)𝔽𝔾𝕩}` | Apply `𝔾` to each argument and `𝔽` to the results -`⊸` | Before/Bind | `{(𝔽𝕨⊣𝕩)𝔾𝕩}` | `𝔾`'s left argument comes from `𝔽` -`⟜` | After/Bind | `{(𝕨⊣𝕩)𝔽𝔾𝕩}` | `𝔽`'s right argument comes from `𝔾` +`⊸` | [Before/Bind](hook.md) | `{(𝔽𝕨⊣𝕩)𝔾𝕩}` | `𝔾`'s left argument comes from `𝔽` +`⟜` | [After/Bind](hook.md) | `{(𝕨⊣𝕩)𝔽𝔾𝕩}` | `𝔽`'s right argument comes from `𝔾` `⌾` | Under | `{𝔾⁼∘𝔽○𝔾}` OR `{(𝔾𝕩)↩𝕨𝔽○𝔾𝕩⋄𝕩}` | Apply `𝔽` over `𝔾`, then undo `𝔾` `⊘` | [Valences](valences.md) | `{𝔽𝕩;𝕨𝔾𝕩}` | Apply `𝔽` if there's one argument but `𝔾` if there are two `◶` | [Choose](choose.md) | `{f←(𝕨𝔽𝕩)⊑𝕘 ⋄ 𝕨F𝕩}` | Select one of the functions in list `𝕘` based on `𝔽` diff --git a/docs/doc/hook.html b/docs/doc/hook.html new file mode 100644 index 00000000..22054800 --- /dev/null +++ b/docs/doc/hook.html @@ -0,0 +1,161 @@ +<head> + <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/> + <link href="../style.css" rel="stylesheet"/> + <title>BQN: Before and After</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="before-and-after"><a class="header" href="#before-and-after">Before and After</a></h1> +<p>(<a href="https://aplwiki.com/wiki/File:Before_and_after.jpg">This joke</a> has already been claimed by APL, unfortunately)</p> +<p><em>Also see <a href="../tutorial/combinator.html#before-and-after">this tutorial section</a> for an introduction that doesn't require so much context to understand.</em></p> +<svg viewBox='-51 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'>Before</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='Function'>𝔽</tspan><tspan class='Modifier2'>⊸</tspan><tspan class='Function'>𝔾</tspan> <tspan class='Value'>𝕩</tspan></text> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0L-32 57'/> + <path class='yellow' style='fill:none' stroke-width='2' d='M-32 57L0 114'/> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0Q41.6 57 0 114'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='0'/> + <circle r='12' class='code' stroke-width='0' cx='-32' cy='57'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='114'/> + <text dy='0.32em' x='0' y='0'><tspan class='Function'>𝔾</tspan></text> + <text dy='0.32em' x='-32' y='57'><tspan class='Function'>𝔽</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='Function'>𝔽</tspan><tspan class='Modifier2'>⊸</tspan><tspan class='Function'>𝔾</tspan> <tspan class='Value'>𝕩</tspan></text> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0L-32 57'/> + <path class='yellow' style='fill:none' stroke-width='2' d='M-32 57L-32 114'/> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0C40 57 32 51.3 32 114'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='0'/> + <circle r='12' class='code' stroke-width='0' cx='-32' 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='0'><tspan class='Function'>𝔾</tspan></text> + <text dy='0.32em' x='-32' y='57'><tspan class='Function'>𝔽</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> + <g font-size='20px' text-anchor='middle' transform='translate(425,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'>After</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='Function'>𝔽</tspan><tspan class='Modifier2'>⟜</tspan><tspan class='Function'>𝔾</tspan> <tspan class='Value'>𝕩</tspan></text> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0Q-41.6 57 0 114'/> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0L32 57'/> + <path class='yellow' style='fill:none' stroke-width='2' d='M32 57L0 114'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='0'/> + <circle r='12' class='code' stroke-width='0' cx='32' cy='57'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='114'/> + <text dy='0.32em' x='0' y='0'><tspan class='Function'>𝔽</tspan></text> + <text dy='0.32em' x='32' y='57'><tspan class='Function'>𝔾</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='Function'>𝔽</tspan><tspan class='Modifier2'>⟜</tspan><tspan class='Function'>𝔾</tspan> <tspan class='Value'>𝕩</tspan></text> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0C-40 57 -32 51.3 -32 114'/> + <path class='yellow' style='fill:none' stroke-width='2' d='M0 0L32 57'/> + <path class='yellow' style='fill:none' stroke-width='2' d='M32 57L32 114'/> + <circle r='12' class='code' stroke-width='0' cx='0' cy='0'/> + <circle r='12' class='code' stroke-width='0' cx='32' 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='0'><tspan class='Function'>𝔽</tspan></text> + <text dy='0.32em' x='32' y='57'><tspan class='Function'>𝔾</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>The "hook" combinators Before and After serve a few purposes in BQN. The important thing to remember: the pointy side goes towards the first function to be executed, and the next function that returns the final result is at the ring side. If the pointy-side function is actually a constant like a number, then the ring-side function just gets applied to that constant and one of the arguments. This is the thing Haskell programmers are constantly telling each other isn't called currying, or "Bind" in BQN.</p> +<table> +<thead> +<tr> +<th>Name</th> +<th><code><span class='Function'>Cmp</span></code></th> +<th><code><span class='Function'>Cmp</span> <span class='Value'>𝕩</span></code></th> +<th><code><span class='Value'>𝕨</span> <span class='Function'>Cmp</span> <span class='Value'>𝕩</span></code></th> +<th>Unified</th> +<th>Train</th> +</tr> +</thead> +<tbody> +<tr> +<td>Before</td> +<td><code><span class='Function'>F</span><span class='Modifier2'>⊸</span><span class='Function'>G</span></code></td> +<td><code><span class='Paren'>(</span><span class='Function'>F</span><span class='Value'>𝕩</span><span class='Paren'>)</span> <span class='Function'>G</span> <span class='Value'>𝕩</span></code></td> +<td><code><span class='Paren'>(</span><span class='Function'>F</span><span class='Value'>𝕨</span><span class='Paren'>)</span> <span class='Function'>G</span> <span class='Value'>𝕩</span></code></td> +<td><code><span class='Brace'>{</span><span class='Paren'>(</span><span class='Function'>𝔽</span><span class='Value'>𝕨</span><span class='Function'>⊣</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>𝔾</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code></td> +<td><code><span class='Function'>F</span><span class='Modifier2'>∘</span><span class='Function'>⊣</span> <span class='Function'>G</span> <span class='Function'>⊢</span></code></td> +</tr> +<tr> +<td>After</td> +<td><code><span class='Function'>F</span><span class='Modifier2'>⟜</span><span class='Function'>G</span></code></td> +<td><code><span class='Value'>𝕩</span> <span class='Function'>F</span> <span class='Paren'>(</span><span class='Function'>G</span><span class='Value'>𝕩</span><span class='Paren'>)</span></code></td> +<td><code><span class='Value'>𝕨</span> <span class='Function'>F</span> <span class='Paren'>(</span><span class='Function'>G</span><span class='Value'>𝕩</span><span class='Paren'>)</span></code></td> +<td><code><span class='Brace'>{</span><span class='Paren'>(</span><span class='Value'>𝕨</span><span class='Function'>⊣</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>𝔽𝔾</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code></td> +<td><code><span class='Function'>⊣</span> <span class='Function'>F</span> <span class='Function'>G</span><span class='Modifier2'>∘</span><span class='Function'>⊢</span></code></td> +</tr> +</tbody> +</table> +<h2 id="description"><a class="header" href="#description">Description</a></h2> +<p>In the general case, I think of Before as using <code><span class='Function'>𝔽</span></code> as a preprocessing function applied to <code><span class='Value'>𝕨</span></code> (when there are two arguments) and After as using <code><span class='Function'>𝔾</span></code> as preprocessing for <code><span class='Value'>𝕩</span></code>. Then the other operand is called on the result and remaining argument. Here are some simple calls with Pair (<code><span class='Function'>⋈</span></code>): the result is a pair that corresponds to <code><span class='Value'>𝕨</span><span class='Ligature'>‿</span><span class='Value'>𝕩</span></code>, but one or the other result has been modified by the pointy-side function.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=OSDiiJriirjii4ggMgoKOSDii4jin5zihpUgMg==">↗️</a><pre> <span class='Number'>9</span> <span class='Function'>√</span><span class='Modifier2'>⊸</span><span class='Function'>⋈</span> <span class='Number'>2</span> +⟨ 3 2 ⟩ + + <span class='Number'>9</span> <span class='Function'>⋈</span><span class='Modifier2'>⟜</span><span class='Function'>↕</span> <span class='Number'>2</span> +⟨ 9 ⟨ 0 1 ⟩ ⟩ +</pre> +<p>When only one argument is given, it's used in both positions, so that the arguments to the final function are <code><span class='Value'>𝕩</span></code> and a function applied to <code><span class='Value'>𝕩</span></code>.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4ouI4p+c4oaVIDU=">↗️</a><pre> <span class='Function'>⋈</span><span class='Modifier2'>⟜</span><span class='Function'>↕</span> <span class='Number'>5</span> +⟨ 5 ⟨ 0 1 2 3 4 ⟩ ⟩ +</pre> +<p>This can be used to make a "filter" pattern using <a href="replicate.html">Replicate</a> (<code><span class='Function'>/</span></code>). The difference is that Replicate takes a list <code><span class='Value'>𝕩</span></code> and boolean list <code><span class='Value'>𝕨</span></code> indicating which elements to keep, but filter should take a list and a function that says whether to keep each element. The pattern is <code><span class='Function'>F</span><span class='Modifier'>¨</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Value'>x</span></code>, expanding to <code><span class='Paren'>(</span><span class='Function'>F</span><span class='Modifier'>¨</span><span class='Value'>x</span><span class='Paren'>)</span> <span class='Function'>/</span> <span class='Value'>x</span></code>. Here's a list filtered with the function <code><span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>0</span><span class='Brace'>}</span></code>.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=e/Cdlak8MH3CqOKKuC8gNOKAv8KvMuKAvzHigL/CrzPigL/CrzM=">↗️</a><pre> <span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>0</span><span class='Brace'>}</span><span class='Modifier'>¨</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>¯2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>¯3</span><span class='Ligature'>‿</span><span class='Number'>¯3</span> +⟨ ¯2 ¯3 ¯3 ⟩ +</pre> +<p>As <code><span class='Function'><</span></code> is a pervasive function, there's no need for the Each (<code><span class='Modifier'>¨</span></code>) in this case, and the clunky block function <code><span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>0</span><span class='Brace'>}</span></code> can also be written smaller with a combinator, as <code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span></code>. More on that in the next section…</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=POKfnDDiirgvIDTigL/CrzLigL8x4oC/wq8z4oC/wq8z">↗️</a><pre> <span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>¯2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>¯3</span><span class='Ligature'>‿</span><span class='Number'>¯3</span> +⟨ ¯2 ¯3 ¯3 ⟩ +</pre> +<h2 id="bind"><a class="header" href="#bind">Bind</a></h2> +<p>"Bind" isn't a special case of Before and After, but instead a description of one way to use them. Let's take a look at the example from the previous section:</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=POKfnDAgIDTigL/CrzLigL8x4oC/wq8z4oC/wq8z">↗️</a><pre> <span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>¯2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>¯3</span><span class='Ligature'>‿</span><span class='Number'>¯3</span> +⟨ 0 1 0 1 1 ⟩ +</pre> +<p>If we expand <code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span> <span class='Value'>x</span></code>, we get <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Paren'>(</span><span class='Number'>0</span> <span class='Value'>x</span><span class='Paren'>)</span></code>, which doesn't quite make sense. That's because <code><span class='Number'>0</span></code> has a subject role, but <code><span class='Modifier2'>⟜</span></code> always applies its operands as functions. It's more accurate to use <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Paren'>(</span><span class='Number'>0</span><span class='Brace'>{</span><span class='Function'>𝔽</span><span class='Brace'>}</span> <span class='Value'>x</span><span class='Paren'>)</span></code>, or just skip ahead to <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Number'>0</span></code>.</p> +<p>Similar reasoning gives the following expansions:</p> +<table> +<thead> +<tr> +<th><code><span class='Function'>Cmp</span></code></th> +<th><code><span class='Number'>0</span><span class='Modifier2'>⊸</span><span class='Function'><</span></code></th> +<th><code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span></code></th> +</tr> +</thead> +<tbody> +<tr> +<td><code> <span class='Function'>Cmp</span> <span class='Value'>x</span></code></td> +<td><code><span class='Number'>0</span> <span class='Function'><</span> <span class='Value'>x</span></code></td> +<td><code><span class='Value'>x</span> <span class='Function'><</span> <span class='Number'>0</span></code></td> +</tr> +<tr> +<td><code><span class='Value'>w</span> <span class='Function'>Cmp</span> <span class='Value'>x</span></code></td> +<td><code><span class='Number'>0</span> <span class='Function'><</span> <span class='Value'>x</span></code></td> +<td><code><span class='Value'>w</span> <span class='Function'><</span> <span class='Number'>0</span></code></td> +</tr> +</tbody> +</table> +<p>Note that when there are two arguments, the constant "swallows" the one on the same side, so that the function is applied to the constant and the argument on the <em>opposite</em> side.</p> +<p>As in a train, if you want to use a function as a constant then you need to be explicity about it, with the <a href="constant.html">Constant</a> (<code><span class='Modifier'>˙</span></code>) modifier.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MyDii4jin5wo4oyKy5kp4oq44qWKICdhJyvihpUxMg==">↗️</a><pre> <span class='Number'>3</span> <span class='Function'>⋈</span><span class='Modifier2'>⟜</span><span class='Paren'>(</span><span class='Function'>⌊</span><span class='Modifier'>˙</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⥊</span> <span class='String'>'a'</span><span class='Function'>+↕</span><span class='Number'>12</span> +┌─ +╵"abcd + efgh + ijkl" + ┘ +</pre> +<p>In the more extreme case of wanting a <em>modifier</em> operand, you might try <code><span class='Function'>⋈</span><span class='Modifier2'>⟜</span><span class='Paren'>(</span><span class='Brace'>{</span><span class='Modifier2'>∘</span><span class='Brace'>}</span><span class='Modifier'>˙</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⥊</span></code>, or <code><span class='Paren'>(</span><span class='Function'>⊣⋈</span><span class='Brace'>{</span><span class='Modifier2'>∘</span><span class='Brace'>}</span><span class='Modifier'>˙</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⥊</span></code>, or just cheat with <code><span class='Function'>∾</span><span class='Modifier2'>⟜</span><span class='Bracket'>⟨</span><span class='Modifier2'>∘</span><span class='Bracket'>⟩</span><span class='Modifier2'>⊸</span><span class='Function'>⥊</span></code>.</p> diff --git a/docs/doc/index.html b/docs/doc/index.html index 66bdbfec..82af1d4c 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="hook.html">Before and After</a> (<code><span class='Modifier2'>⊸⟜</span></code>)</li> <li><a href="choose.html">Choose</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> diff --git a/docs/doc/primitive.html b/docs/doc/primitive.html index aa3fd087..fd153f5a 100644 --- a/docs/doc/primitive.html +++ b/docs/doc/primitive.html @@ -449,13 +449,13 @@ </tr> <tr> <td><code><span class='Modifier2'>⊸</span></code></td> -<td>Before/Bind</td> +<td><a href="hook.html">Before/Bind</a></td> <td><code><span class='Brace'>{</span><span class='Paren'>(</span><span class='Function'>𝔽</span><span class='Value'>𝕨</span><span class='Function'>⊣</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>𝔾</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code></td> <td><code><span class='Function'>𝔾</span></code>'s left argument comes from <code><span class='Function'>𝔽</span></code></td> </tr> <tr> <td><code><span class='Modifier2'>⟜</span></code></td> -<td>After/Bind</td> +<td><a href="hook.html">After/Bind</a></td> <td><code><span class='Brace'>{</span><span class='Paren'>(</span><span class='Value'>𝕨</span><span class='Function'>⊣</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>𝔽𝔾</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code></td> <td><code><span class='Function'>𝔽</span></code>'s right argument comes from <code><span class='Function'>𝔾</span></code></td> </tr> diff --git a/docs/help/after_bind.html b/docs/help/after_bind.html index 8ef227af..490f105e 100644 --- a/docs/help/after_bind.html +++ b/docs/help/after_bind.html @@ -6,6 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="left-multimap-"><a class="header" href="#left-multimap-">Left Multimap (<code><span class='Modifier2'>⟜</span></code>)</a></h1> <h2 id="𝔽𝕘-𝕩-bind"><a class="header" href="#𝔽𝕘-𝕩-bind"><code><span class='Function'>𝔽</span><span class='Modifier2'>⟜</span><span class='Value'>𝕘</span> <span class='Value'>𝕩</span></code>: Bind</a></h2> +<p><a class="fulldoc" href="../doc/hook.html#bind">→full documentation</a></p> <p>Supply <code><span class='Value'>𝕘</span></code> as a right argument to <code><span class='Function'>𝔽</span></code> (<code><span class='Value'>𝕩</span> <span class='Function'>𝔽</span> <span class='Value'>𝕘</span></code>).</p> <p><code><span class='Value'>𝕘</span></code> is a constant, <code><span class='Function'>𝔽</span></code> must be dyadic.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LeKfnDMgOQoKLSAzIDkKCjkgLSAz">↗️</a><pre> <span class='Function'>-</span><span class='Modifier2'>⟜</span><span class='Number'>3</span> <span class='Number'>9</span> @@ -18,6 +19,7 @@ 6 </pre> <h2 id="𝔽𝔾-𝕩-after"><a class="header" href="#𝔽𝔾-𝕩-after"><code><span class='Function'>𝔽</span><span class='Modifier2'>⟜</span><span class='Function'>𝔾</span> <span class='Value'>𝕩</span></code>: After</a></h2> +<p><a class="fulldoc" href="../doc/hook.html">→full documentation</a></p> <p>Apply <code><span class='Function'>𝔾</span></code> to <code><span class='Value'>𝕩</span></code>, and supply it as a right argument to <code><span class='Function'>𝔽</span></code> (<code><span class='Value'>𝕩</span> <span class='Function'>𝔽</span> <span class='Paren'>(</span><span class='Function'>𝔾</span> <span class='Value'>𝕩</span><span class='Paren'>)</span></code>).</p> <p><code><span class='Function'>𝔽</span></code> must be dyadic, <code><span class='Function'>𝔾</span></code> must be monadic.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=w5fin5wtIDkKCsOXIC0gOQoKOSDDlyAoLSA5KQ==">↗️</a><pre> <span class='Function'>×</span><span class='Modifier2'>⟜</span><span class='Function'>-</span> <span class='Number'>9</span> @@ -30,6 +32,7 @@ ¯81 </pre> <h2 id="𝕨-𝔽𝔾-𝕩-dyadic-after"><a class="header" href="#𝕨-𝔽𝔾-𝕩-dyadic-after"><code><span class='Value'>𝕨</span> <span class='Function'>𝔽</span><span class='Modifier2'>⟜</span><span class='Function'>𝔾</span> <span class='Value'>𝕩</span></code>: Dyadic After</a></h2> +<p><a class="fulldoc" href="../doc/hook.html">→full documentation</a></p> <p>Apply <code><span class='Function'>𝔾</span></code> to <code><span class='Value'>𝕩</span></code>, and supply it as a right argument to <code><span class='Function'>𝔽</span></code> (<code><span class='Value'>𝕨</span> <span class='Function'>𝔽</span> <span class='Paren'>(</span><span class='Function'>𝔾</span> <span class='Value'>𝕩</span><span class='Paren'>)</span></code>).</p> <p><code><span class='Function'>𝔽</span></code> must be dyadic, <code><span class='Function'>𝔾</span></code> must be monadic.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MiDDl+KfnC0gMQoKMiDDlyAoLSAxKQ==">↗️</a><pre> <span class='Number'>2</span> <span class='Function'>×</span><span class='Modifier2'>⟜</span><span class='Function'>-</span> <span class='Number'>1</span> diff --git a/docs/help/before_bind.html b/docs/help/before_bind.html index c9f0ca0b..d240921b 100644 --- a/docs/help/before_bind.html +++ b/docs/help/before_bind.html @@ -6,6 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="multimap-"><a class="header" href="#multimap-">Multimap (<code><span class='Modifier2'>⊸</span></code>)</a></h1> <h2 id="𝕗𝔾-𝕩-bind-left"><a class="header" href="#𝕗𝔾-𝕩-bind-left"><code><span class='Value'>𝕗</span><span class='Modifier2'>⊸</span><span class='Function'>𝔾</span> <span class='Value'>𝕩</span></code>: Bind Left</a></h2> +<p><a class="fulldoc" href="../doc/hook.html#bind">→full documentation</a></p> <p>Supply <code><span class='Value'>𝕗</span></code> as a left argument to <code><span class='Function'>𝔾</span></code> (<code><span class='Value'>𝕗</span> <span class='Function'>𝔾</span> <span class='Value'>𝕩</span></code>).</p> <p><code><span class='Value'>𝕗</span></code> is a constant, <code><span class='Function'>𝔾</span></code> must be dyadic.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=M+KKuC0gOQoKMyAtIDk=">↗️</a><pre> <span class='Number'>3</span><span class='Modifier2'>⊸</span><span class='Function'>-</span> <span class='Number'>9</span> @@ -15,6 +16,7 @@ ¯6 </pre> <h2 id="𝔽𝔾-𝕩-before"><a class="header" href="#𝔽𝔾-𝕩-before"><code><span class='Function'>𝔽</span><span class='Modifier2'>⊸</span><span class='Function'>𝔾</span> <span class='Value'>𝕩</span></code>: Before</a></h2> +<p><a class="fulldoc" href="../doc/hook.html">→full documentation</a></p> <p>Apply <code><span class='Function'>𝔽</span></code> to <code><span class='Value'>𝕩</span></code>, and supply it as a left argument to <code><span class='Function'>𝔾</span></code> (<code><span class='Paren'>(</span><span class='Function'>𝔽</span> <span class='Value'>𝕩</span><span class='Paren'>)</span> <span class='Function'>𝔾</span> <span class='Value'>𝕩</span></code>).</p> <p><code><span class='Function'>𝔽</span></code> must be monadic, <code><span class='Function'>𝔾</span></code> must be dyadic.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LeKKuCsgOQoKLSArIDkKCigtIDkpICsgOQ==">↗️</a><pre> <span class='Function'>-</span><span class='Modifier2'>⊸</span><span class='Function'>+</span> <span class='Number'>9</span> @@ -27,6 +29,7 @@ 0 </pre> <h2 id="𝕨-𝔽𝔾-𝕩-dyadic-before"><a class="header" href="#𝕨-𝔽𝔾-𝕩-dyadic-before"><code><span class='Value'>𝕨</span> <span class='Function'>𝔽</span><span class='Modifier2'>⊸</span><span class='Function'>𝔾</span> <span class='Value'>𝕩</span></code>: Dyadic Before</a></h2> +<p><a class="fulldoc" href="../doc/hook.html">→full documentation</a></p> <p>Apply <code><span class='Function'>𝔽</span></code> to <code><span class='Value'>𝕨</span></code>, and supply it as a left argument to <code><span class='Function'>𝔾</span></code> (<code><span class='Paren'>(</span><span class='Function'>𝔽</span> <span class='Value'>𝕨</span><span class='Paren'>)</span> <span class='Function'>𝔾</span> <span class='Value'>𝕩</span></code>).</p> <p><code><span class='Function'>𝔽</span></code> must be monadic, <code><span class='Function'>𝔾</span></code> must be dyadic.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MiAt4oq4KyAxCgoyIC0gKyAxCgooLSAyKSArIDE=">↗️</a><pre> <span class='Number'>2</span> <span class='Function'>-</span><span class='Modifier2'>⊸</span><span class='Function'>+</span> <span class='Number'>1</span> diff --git a/help/after_bind.md b/help/after_bind.md index b18cc729..727ed83e 100644 --- a/help/after_bind.md +++ b/help/after_bind.md @@ -3,6 +3,7 @@ # Left Multimap (`⟜`) ## `𝔽⟜𝕘 𝕩`: Bind +[→full documentation](../doc/hook.md#bind) Supply `𝕘` as a right argument to `𝔽` (`𝕩 𝔽 𝕘`). @@ -17,6 +18,7 @@ Supply `𝕘` as a right argument to `𝔽` (`𝕩 𝔽 𝕘`). ## `𝔽⟜𝔾 𝕩`: After +[→full documentation](../doc/hook.md) Apply `𝔾` to `𝕩`, and supply it as a right argument to `𝔽` (`𝕩 𝔽 (𝔾 𝕩)`). @@ -31,6 +33,7 @@ Apply `𝔾` to `𝕩`, and supply it as a right argument to `𝔽` (`𝕩 𝔽 ## `𝕨 𝔽⟜𝔾 𝕩`: Dyadic After +[→full documentation](../doc/hook.md) Apply `𝔾` to `𝕩`, and supply it as a right argument to `𝔽` (`𝕨 𝔽 (𝔾 𝕩)`). diff --git a/help/before_bind.md b/help/before_bind.md index 78073413..403e7092 100644 --- a/help/before_bind.md +++ b/help/before_bind.md @@ -3,6 +3,7 @@ # Multimap (`⊸`) ## `𝕗⊸𝔾 𝕩`: Bind Left +[→full documentation](../doc/hook.md#bind) Supply `𝕗` as a left argument to `𝔾` (`𝕗 𝔾 𝕩`). @@ -15,6 +16,7 @@ Supply `𝕗` as a left argument to `𝔾` (`𝕗 𝔾 𝕩`). ## `𝔽⊸𝔾 𝕩`: Before +[→full documentation](../doc/hook.md) Apply `𝔽` to `𝕩`, and supply it as a left argument to `𝔾` (`(𝔽 𝕩) 𝔾 𝕩`). @@ -29,6 +31,7 @@ Apply `𝔽` to `𝕩`, and supply it as a left argument to `𝔾` (`(𝔽 𝕩) ## `𝕨 𝔽⊸𝔾 𝕩`: Dyadic Before +[→full documentation](../doc/hook.md) Apply `𝔽` to `𝕨`, and supply it as a left argument to `𝔾` (`(𝔽 𝕨) 𝔾 𝕩`). |
