1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
<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>
<h2 id="combinations"><a class="header" href="#combinations">Combinations</a></h2>
<p>If you like to go <a href="tacit.html">tacit</a>, you'll likely end up stringing together a few <code><span class='Modifier2'>βΈ</span></code>s and <code><span class='Modifier2'>β</span></code>s at times. Of course the effects are entirely determined by the left-to-right precedence rule for modifiers, but it's interesting to examine what happens in more detail.</p>
<p>In the pattern <code><span class='Function'>F</span><span class='Modifier2'>βΈ</span><span class='Function'>G</span><span class='Modifier2'>β</span><span class='Function'>H</span></code>, the ordering doesn't matter at all! That is, it means <code><span class='Paren'>(</span><span class='Function'>F</span><span class='Modifier2'>βΈ</span><span class='Function'>G</span><span class='Paren'>)</span><span class='Modifier2'>β</span><span class='Function'>H</span></code>, but this is exactly the same function as <code><span class='Function'>F</span><span class='Modifier2'>βΈ</span><span class='Paren'>(</span><span class='Function'>G</span><span class='Modifier2'>β</span><span class='Function'>H</span><span class='Paren'>)</span></code>. In both cases, <code><span class='Function'>F</span></code> is applied to <code><span class='Value'>π¨</span></code>, <code><span class='Function'>H</span></code> is applied to <code><span class='Value'>π©</span></code>, and <code><span class='Function'>G</span></code> acts on both the results.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=NCAt4oq44ouI4p+c4ouGIDI=">βοΈ</a><pre> <span class='Number'>4</span> <span class='Function'>-</span><span class='Modifier2'>βΈ</span><span class='Function'>β</span><span class='Modifier2'>β</span><span class='Function'>β</span> <span class='Number'>2</span>
β¨ Β―4 7.38905609893065 β©
</pre>
<p>I once named this pattern "split compose", but now I think it makes more sense to think of it as two pre-functions added separately to one central function (<code><span class='Function'>β</span></code> above). The whole is exactly the sum of its parts. When applied to just one argument, <code><span class='Value'>π©</span></code> is reused on both sides, making the composition equivalent to a 3-<a href="train.html">train</a>.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LeKKuOKLiOKfnOKLhiAyCgooLeKLiOKLhikgMiAgIyBTYW1lIHRoaW5n">βοΈ</a><pre> <span class='Function'>-</span><span class='Modifier2'>βΈ</span><span class='Function'>β</span><span class='Modifier2'>β</span><span class='Function'>β</span> <span class='Number'>2</span>
β¨ Β―2 7.38905609893065 β©
<span class='Paren'>(</span><span class='Function'>-ββ</span><span class='Paren'>)</span> <span class='Number'>2</span> <span class='Comment'># Same thing
</span>β¨ Β―2 7.38905609893065 β©
</pre>
<p>More <code><span class='Modifier2'>β</span></code>s can be added on the right, making <code><span class='Value'>π©</span></code> flow through all the added functions. So for example <code><span class='Function'>F</span><span class='Modifier2'>β</span><span class='Function'>G</span><span class='Modifier2'>β</span><span class='Function'>H</span> <span class='Value'>x</span></code> is <code><span class='Value'>x</span> <span class='Function'>F</span> <span class='Function'>G</span> <span class='Function'>H</span> <span class='Value'>x</span></code>, and could also be written <code><span class='Function'>F</span><span class='Modifier2'>β</span><span class='Paren'>(</span><span class='Function'>G</span> <span class='Function'>H</span><span class='Paren'>)</span> <span class='Value'>x</span></code>.</p>
<p>A sequence of <code><span class='Modifier2'>βΈ</span></code>s is more interesting. It doesn't just compose the functions (for that you need <code><span class='Function'>G</span><span class='Modifier2'>β</span><span class='Function'>F</span><span class='Modifier2'>βΈ</span><span class='Function'>H</span></code>, but note the weird orderingβ<code><span class='Function'>F</span></code> applies before <code><span class='Function'>G</span></code>!), but instead passes the current value <em>and</em> the initial function each time. Consider <code><span class='Function'>F</span><span class='Modifier2'>βΈ</span><span class='Function'>G</span><span class='Modifier2'>βΈ</span><span class='Function'>H</span><span class='Modifier2'>βΈ</span><span class='Function'>I</span></code>, or <code><span class='Paren'>((</span><span class='Function'>F</span><span class='Modifier2'>βΈ</span><span class='Function'>G</span><span class='Paren'>)</span><span class='Modifier2'>βΈ</span><span class='Function'>H</span><span class='Paren'>)</span><span class='Modifier2'>βΈ</span><span class='Function'>I</span></code>: every function but <code><span class='Function'>F</span></code> is on the ring side, meaning it's dyadic!</p>
<p>Here's a long example, that might show up if you want to <a href="order.html#sort">sort</a> an array but have an intolerance for the character <code><span class='Function'>β§</span></code>. In quicksort, you select a partition element from the array, then divide it into elements less than, and greater than or equal to, the pivot. You'd probably pick a <a href="../spec/system.html#random-generation">random</a> element for the pivot, but here I'll go with the middle element to avoid having a webpage that generates differently every time!</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KOKMiuKJoMO3MsuZKSAgICAgICAicXVpY2tzb3J0IiAgIyBJbmRleCBvZiB0aGUgcGl2b3QKCijijIriiaDDtzLLmSniirjiipEgICAgICJxdWlja3NvcnQiICAjIFNlbGVjdCBwaXZvdCBmcm9tIPCdlakKCijijIriiaDDtzLLmSniirjiipHiirjiiaQgICAicXVpY2tzb3J0IiAgIyBDb21wYXJlIHdpdGgg8J2VqQoKKOKMiuKJoMO3MsuZKeKKuOKKkeKKuOKJpOKKuOKKlCAicXVpY2tzb3J0IiAgIyBVc2UgdG8gcGFydGl0aW9uIPCdlak=">βοΈ</a><pre> <span class='Paren'>(</span><span class='Function'>ββ Γ·</span><span class='Number'>2</span><span class='Modifier'>Λ</span><span class='Paren'>)</span> <span class='String'>"quicksort"</span> <span class='Comment'># Index of the pivot
</span>4
<span class='Paren'>(</span><span class='Function'>ββ Γ·</span><span class='Number'>2</span><span class='Modifier'>Λ</span><span class='Paren'>)</span><span class='Modifier2'>βΈ</span><span class='Function'>β</span> <span class='String'>"quicksort"</span> <span class='Comment'># Select pivot from π©
</span>'k'
<span class='Paren'>(</span><span class='Function'>ββ Γ·</span><span class='Number'>2</span><span class='Modifier'>Λ</span><span class='Paren'>)</span><span class='Modifier2'>βΈ</span><span class='Function'>β</span><span class='Modifier2'>βΈ</span><span class='Function'>β€</span> <span class='String'>"quicksort"</span> <span class='Comment'># Compare with π©
</span>β¨ 1 1 0 0 1 1 1 1 1 β©
<span class='Paren'>(</span><span class='Function'>ββ Γ·</span><span class='Number'>2</span><span class='Modifier'>Λ</span><span class='Paren'>)</span><span class='Modifier2'>βΈ</span><span class='Function'>β</span><span class='Modifier2'>βΈ</span><span class='Function'>β€</span><span class='Modifier2'>βΈ</span><span class='Function'>β</span> <span class='String'>"quicksort"</span> <span class='Comment'># Use to partition π©
</span>β¨ "ic" "quksort" β©
</pre>
<p>Three is rare, but I use two <code><span class='Modifier2'>βΈ</span></code>s all the time, as well as <code><span class='Modifier2'>β</span></code> followed by <code><span class='Modifier2'>βΈ</span></code>, for example the <code><span class='Function'><</span><span class='Modifier2'>β</span><span class='String'>'a'</span><span class='Modifier2'>βΈ</span><span class='Function'>/</span></code> filter on the <a href="../index.html">front page</a>. I think a combination like <code><span class='Value'>lots</span><span class='Modifier2'>β</span><span class='Value'>of</span><span class='Modifier2'>β</span><span class='Value'>stuff</span><span class='Modifier2'>βΈ</span><span class='Function'>/</span> <span class='Value'>x</span></code> reads very nicely when moving from left to right. When I see <code><span class='Modifier2'>βΈ</span><span class='Function'>/</span></code> I know that I'm filtering <code><span class='Value'>x</span></code> and can read the rest with that context. The reason <code><span class='Modifier2'>βΈ</span></code> that has all this power, but not <code><span class='Modifier2'>β</span></code>, has nothing to do with the modifiers themselves, as they're completely symmetrical. It's all in the way BQN defines modifier grammar, left to right.</p>
|