OSDN Git Service

Give it it's own CSS file.
[joypy/Thun.git] / docs / reference / FuncRef.html
1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
3 <head>
4   <meta charset="utf-8" />
5   <meta name="generator" content="pandoc" />
6   <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7   <title>Thun Function Reference</title>
8   <style>
9     code{white-space: pre-wrap;}
10     span.smallcaps{font-variant: small-caps;}
11     span.underline{text-decoration: underline;}
12     div.column{display: inline-block; vertical-align: top; width: 50%;}
13     div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14     ul.task-list{list-style: none;}
15   </style>
16   <link rel="stylesheet" href="/css/fonts.css" />
17   <link rel="stylesheet" href="/css/func_ref.css" />
18 </head>
19 <body>
20 <header id="title-block-header">
21 <h1 class="title">Thun Function Reference</h1>
22 </header>
23 <nav id="TOC" role="doc-toc">
24 <ul>
25 <li><a href="#abs">abs</a></li>
26 <li><a href="#add">add</a></li>
27 <li><a href="#section">&amp;&amp;</a></li>
28 <li><a href="#section-1">&amp;</a></li>
29 <li><a href="#anamorphism">anamorphism</a></li>
30 <li><a href="#and">and</a></li>
31 <li><a href="#app1">app1</a></li>
32 <li><a href="#app2">app2</a></li>
33 <li><a href="#app3">app3</a></li>
34 <li><a href="#appn">appN</a></li>
35 <li><a href="#section-2">*</a></li>
36 <li><a href="#at">at</a></li>
37 <li><a href="#average">average</a></li>
38 <li><a href="#binary">binary</a></li>
39 <li><a href="#b">b</a></li>
40 <li><a href="#bool">bool</a></li>
41 <li><a href="#branch">branch</a></li>
42 <li><a href="#section-3">&#x2022;</a></li>
43 <li><a href="#ccccons">ccccons</a></li>
44 <li><a href="#ccons">ccons</a></li>
45 <li><a href="#choice">choice</a></li>
46 <li><a href="#section-4">^</a></li>
47 <li><a href="#clear">clear</a></li>
48 <li><a href="#cleave">cleave</a></li>
49 <li><a href="#clop">clop</a></li>
50 <li><a href="#cmp">cmp</a></li>
51 <li><a href="#codi">codi</a></li>
52 <li><a href="#codireco">codireco</a></li>
53 <li><a href="#concat">concat</a></li>
54 <li><a href="#cond">cond</a></li>
55 <li><a href="#cons">cons</a></li>
56 <li><a href="#dinfrirst">dinfrirst</a></li>
57 <li><a href="#dipdd">dipdd</a></li>
58 <li><a href="#dipd">dipd</a></li>
59 <li><a href="#dip">dip</a></li>
60 <li><a href="#disenstacken">disenstacken</a></li>
61 <li><a href="#div">div</a></li>
62 <li><a href="#divmod">divmod</a></li>
63 <li><a href="#down_to_zero">down_to_zero</a></li>
64 <li><a href="#drop">drop</a></li>
65 <li><a href="#dupdd">dupdd</a></li>
66 <li><a href="#dupdipd">dupdipd</a></li>
67 <li><a href="#dupdip">dupdip</a></li>
68 <li><a href="#dupd">dupd</a></li>
69 <li><a href="#dup">dup</a></li>
70 <li><a href="#enstacken">enstacken</a></li>
71 <li><a href="#eq">eq</a></li>
72 <li><a href="#section-5">=</a></li>
73 <li><a href="#section-6">!=</a></li>
74 <li><a href="#section-7">!-</a></li>
75 <li><a href="#first">first</a></li>
76 <li><a href="#first_two">first_two</a></li>
77 <li><a href="#flatten">flatten</a></li>
78 <li><a href="#floordiv">floordiv</a></li>
79 <li><a href="#floor">floor</a></li>
80 <li><a href="#fork">fork</a></li>
81 <li><a href="#fourth">fourth</a></li>
82 <li><a href="#gcd2">gcd2</a></li>
83 <li><a href="#gcd">gcd</a></li>
84 <li><a href="#ge">ge</a></li>
85 <li><a href="#genrec">genrec</a></li>
86 <li><a href="#getitem">getitem</a></li>
87 <li><a href="#grabn">grabN</a></li>
88 <li><a href="#grba">grba</a></li>
89 <li><a href="#section-8">&gt;=</a></li>
90 <li><a href="#section-9">&gt;&gt;</a></li>
91 <li><a href="#section-10">&gt;</a></li>
92 <li><a href="#gt">gt</a></li>
93 <li><a href="#help">help</a></li>
94 <li><a href="#section-11">&#x2013;</a></li>
95 <li><a href="#section-12">-</a></li>
96 <li><a href="#hypot">hypot</a></li>
97 <li><a href="#id">id</a></li>
98 <li><a href="#ifte">ifte</a></li>
99 <li><a href="#ii">ii</a></li>
100 <li><a href="#i">i</a></li>
101 <li><a href="#infra">infra</a></li>
102 <li><a href="#infrst">infrst</a></li>
103 <li><a href="#inscribe">inscribe</a></li>
104 <li><a href="#le">le</a></li>
105 <li><a href="#section-13">&lt;=</a></li>
106 <li><a href="#section-14">&lt;&gt;</a></li>
107 <li><a href="#section-15">&lt;{}</a></li>
108 <li><a href="#section-16">&lt;&lt;{}</a></li>
109 <li><a href="#section-17">&lt;&lt;</a></li>
110 <li><a href="#section-18">&lt;</a></li>
111 <li><a href="#loop">loop</a></li>
112 <li><a href="#lshift">lshift</a></li>
113 <li><a href="#lt">lt</a></li>
114 <li><a href="#make_generator">make_generator</a></li>
115 <li><a href="#map">map</a></li>
116 <li><a href="#max">max</a></li>
117 <li><a href="#min">min</a></li>
118 <li><a href="#mod">mod</a></li>
119 <li><a href="#modulus">modulus</a></li>
120 <li><a href="#mul">mul</a></li>
121 <li><a href="#neg">neg</a></li>
122 <li><a href="#ne">ne</a></li>
123 <li><a href="#not">not</a></li>
124 <li><a href="#nulco">nulco</a></li>
125 <li><a href="#nullary">nullary</a></li>
126 <li><a href="#of">of</a></li>
127 <li><a href="#or">or</a></li>
128 <li><a href="#over">over</a></li>
129 <li><a href="#pam">pam</a></li>
130 <li><a href="#section-19">%</a></li>
131 <li><a href="#pick">pick</a></li>
132 <li><a href="#section-20">+</a></li>
133 <li><a href="#section-21">++</a></li>
134 <li><a href="#pm">pm</a></li>
135 <li><a href="#popdd">popdd</a></li>
136 <li><a href="#popd">popd</a></li>
137 <li><a href="#pop">pop</a></li>
138 <li><a href="#popopdd">popopdd</a></li>
139 <li><a href="#popopd">popopd</a></li>
140 <li><a href="#popop">popop</a></li>
141 <li><a href="#popopop">popopop</a></li>
142 <li><a href="#pow">pow</a></li>
143 <li><a href="#pred">pred</a></li>
144 <li><a href="#primrec">primrec</a></li>
145 <li><a href="#product">product</a></li>
146 <li><a href="#section-22">?</a></li>
147 <li><a href="#quoted">quoted</a></li>
148 <li><a href="#range">range</a></li>
149 <li><a href="#range_to_zero">range_to_zero</a></li>
150 <li><a href="#reco">reco</a></li>
151 <li><a href="#remainder">remainder</a></li>
152 <li><a href="#rem">rem</a></li>
153 <li><a href="#remove">remove</a></li>
154 <li><a href="#rest">rest</a></li>
155 <li><a href="#reverse">reverse</a></li>
156 <li><a href="#rolldown">rolldown</a></li>
157 <li><a href="#roll">roll&gt;</a></li>
158 <li><a href="#roll-1">roll&lt;</a></li>
159 <li><a href="#rollup">rollup</a></li>
160 <li><a href="#round">round</a></li>
161 <li><a href="#rrest">rrest</a></li>
162 <li><a href="#rshift">rshift</a></li>
163 <li><a href="#run">run</a></li>
164 <li><a href="#second">second</a></li>
165 <li><a href="#select">select</a></li>
166 <li><a href="#sharing">sharing</a></li>
167 <li><a href="#shift">shift</a></li>
168 <li><a href="#shunt">shunt</a></li>
169 <li><a href="#size">size</a></li>
170 <li><a href="#floor-1">/floor</a></li>
171 <li><a href="#section-23">/</a></li>
172 <li><a href="#section-24">//</a></li>
173 <li><a href="#sort">sort</a></li>
174 <li><a href="#spiral_next">spiral_next</a></li>
175 <li><a href="#split_at">split_at</a></li>
176 <li><a href="#split_list">split_list</a></li>
177 <li><a href="#sqr">sqr</a></li>
178 <li><a href="#sqrt">sqrt</a></li>
179 <li><a href="#stackd">stackd</a></li>
180 <li><a href="#stack">stack</a></li>
181 <li><a href="#step">step</a></li>
182 <li><a href="#step_zero">step_zero</a></li>
183 <li><a href="#stuncons">stuncons</a></li>
184 <li><a href="#stununcons">stununcons</a></li>
185 <li><a href="#sub">sub</a></li>
186 <li><a href="#succ">succ</a></li>
187 <li><a href="#sum">sum</a></li>
188 <li><a href="#swaack">swaack</a></li>
189 <li><a href="#swapd">swapd</a></li>
190 <li><a href="#swap">swap</a></li>
191 <li><a href="#swoncat">swoncat</a></li>
192 <li><a href="#swons">swons</a></li>
193 <li><a href="#tailrec">tailrec</a></li>
194 <li><a href="#take">take</a></li>
195 <li><a href="#ternary">ternary</a></li>
196 <li><a href="#third">third</a></li>
197 <li><a href="#times">times</a></li>
198 <li><a href="#truthy">truthy</a></li>
199 <li><a href="#tuck">tuck</a></li>
200 <li><a href="#unary">unary</a></li>
201 <li><a href="#uncons">uncons</a></li>
202 <li><a href="#unique">unique</a></li>
203 <li><a href="#unit">unit</a></li>
204 <li><a href="#unquoted">unquoted</a></li>
205 <li><a href="#unswons">unswons</a></li>
206 <li><a href="#section-25">||</a></li>
207 <li><a href="#void">void</a></li>
208 <li><a href="#warranty">warranty</a></li>
209 <li><a href="#while">while</a></li>
210 <li><a href="#words">words</a></li>
211 <li><a href="#x">x</a></li>
212 <li><a href="#xor">xor</a></li>
213 <li><a href="#zip">zip</a></li>
214 </ul>
215 </nav>
216 <p><a href="/">Home</a></p>
217 <p>Version -10.0.0</p>
218 <p>Each function, combinator, or definition should be documented here.</p>
219 <hr />
220 <h2 id="abs">abs</h2>
221 <p>Function</p>
222 <p>Return the absolute value of the argument.</p>
223 <h3 id="definition">Definition</h3>
224 <blockquote>
225 <p><a href="#dup">dup</a> 0 &lt; [] [<a href="#neg">neg</a>] <a href="#branch">branch</a></p>
226 </blockquote>
227 <hr />
228 <h2 id="add">add</h2>
229 <p>Basis Function</p>
230 <p>Add two numbers together: a + b.</p>
231 <hr />
232 <h2 id="section">&amp;&amp;</h2>
233 <p>Combinator</p>
234 <p>Short-circuiting Boolean AND</p>
235 <p>Accept two quoted programs, run the first and expect a Boolean value, if it&#x2019;s <code>true</code> pop it and run the second program (which should also return a Boolean value) otherwise pop the second program (leaving <code>false</code> on the stack.)</p>
236 <pre><code>   [A] [B] &amp;&amp;
237 ---------------- true
238         B
239
240
241    [A] [B] &amp;&amp;
242 ---------------- false
243      false</code></pre>
244 <h3 id="definition-1">Definition</h3>
245 <pre><code>nulco [nullary [false]] dip branch</code></pre>
246 <h3 id="derivation">Derivation</h3>
247 <p>TODO: this is derived in one of the notebooks I think, look it up and link to it, or copy the content here.</p>
248 <h3 id="discussion">Discussion</h3>
249 <p>This is seldom useful, I suspect, but this way you have it.</p>
250 <h3 id="crosslinks">Crosslinks</h3>
251 <p><a href="#section-25">||</a></p>
252 <hr />
253 <h2 id="section-1">&amp;</h2>
254 <p>See <a href="#and">and</a>.</p>
255 <hr />
256 <h2 id="anamorphism">anamorphism</h2>
257 <p>Combinator</p>
258 <p>Build a list of values from a generator program <code>G</code> and a stopping predicate <code>P</code>.</p>
259 <pre><code>           [P] [G] anamorphism
260 -----------------------------------------
261    [P] [pop []] [G] [dip swons] genrec</code></pre>
262 <h3 id="definition-2">Definition</h3>
263 <blockquote>
264 <p>[<a href="#pop">pop</a> []] <a href="#swap">swap</a> [<a href="#dip">dip</a> <a href="#swons">swons</a>] <a href="#genrec">genrec</a></p>
265 </blockquote>
266 <h3 id="example">Example</h3>
267 <p>The <code>range</code> function generates a list of the integers from 0 to n - 1:</p>
268 <blockquote>
269 <p>[0 &lt;=] [-- dup] anamorphism</p>
270 </blockquote>
271 <h3 id="discussion-1">Discussion</h3>
272 <p>See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.</p>
273 <hr />
274 <h2 id="and">and</h2>
275 <p>Basis Function</p>
276 <p>Logical bit-wise AND.</p>
277 <h3 id="crosslinks-1">Crosslinks</h3>
278 <p><a href="#or">or</a> <a href="#xor">xor</a></p>
279 <hr />
280 <h2 id="app1">app1</h2>
281 <p>&#x201C;apply one&#x201D;</p>
282 <p>Combinator</p>
283 <p>Given a quoted program on TOS and anything as the second stack item run the program without disturbing the stack and replace the two args with the first result of the program.</p>
284 <pre><code>         ... x [Q] app1
285 ---------------------------------
286    ... [x ...] [Q] infra first</code></pre>
287 <p>This is the same effect as the <a href="#unary">unary</a> combinator.</p>
288 <h3 id="definition-3">Definition</h3>
289 <blockquote>
290 <p><a href="#nullary">nullary</a> <a href="#popd">popd</a></p>
291 </blockquote>
292 <h3 id="discussion-2">Discussion</h3>
293 <p>Just a specialization of <code>nullary</code> really. Its parallelizable cousins are more useful.</p>
294 <h3 id="crosslinks-2">Crosslinks</h3>
295 <p><a href="#app2">app2</a> <a href="#app3">app3</a> <a href="#appN">appN</a> <a href="#unary">unary</a></p>
296 <hr />
297 <h2 id="app2">app2</h2>
298 <p>Combinator</p>
299 <p>Like <a href="#app1">app1</a> with two items.</p>
300 <pre><code>   ... y x [Q] . app2
301 -----------------------------------
302    ... [y ...] [Q] . infra first
303        [x ...] [Q]   infra first</code></pre>
304 <h3 id="definition-4">Definition</h3>
305 <blockquote>
306 <p>[<a href="#grba">grba</a> <a href="#swap">swap</a> <a href="#grba">grba</a> <a href="#swap">swap</a>] <a href="#dip">dip</a> [<a href="#infrst">infrst</a>] <a href="#cons">cons</a> <a href="#ii">ii</a></p>
307 </blockquote>
308 <h3 id="discussion-3">Discussion</h3>
309 <p>Unlike <a href="#app1">app1</a>, which is essentially an alias for <a href="#unary">unary</a>, this function is not the same as <a href="#binary">binary</a>. Instead of running one program using exactly two items from the stack and pushing one result (as <a href="#binary">binary</a> does) this function takes two items from the stack and runs the program twice, separately for each of the items, then puts both results onto the stack.</p>
310 <p>This is not currently implemented as parallel processes but it can (and should) be done.</p>
311 <h3 id="crosslinks-3">Crosslinks</h3>
312 <p><a href="#app1">app1</a> <a href="#app3">app3</a> <a href="#appN">appN</a> <a href="#unary">unary</a></p>
313 <hr />
314 <h2 id="app3">app3</h2>
315 <p>Combinator</p>
316 <p>Like <a href="#app1">app1</a> with three items.</p>
317 <pre><code>     ... z y x [Q] . app3
318 -----------------------------------
319    ... [z ...] [Q] . infra first
320        [y ...] [Q]   infra first
321        [x ...] [Q]   infra first</code></pre>
322 <h3 id="definition-5">Definition</h3>
323 <blockquote>
324 <p>3 <a href="#appn">appN</a></p>
325 </blockquote>
326 <h3 id="discussion-4">Discussion</h3>
327 <p>See <a href="#app2">app2</a>.</p>
328 <h3 id="crosslinks-4">Crosslinks</h3>
329 <p><a href="#app1">app1</a> <a href="#app2">app2</a> <a href="#appN">appN</a> <a href="#unary">unary</a></p>
330 <hr />
331 <h2 id="appn">appN</h2>
332 <p>Combinator</p>
333 <p>Like <a href="#app1">app1</a> with any number of items.</p>
334 <pre><code>   ... xN ... x2 x1 x0 [Q] n . appN
335 --------------------------------------
336    ... [xN ...] [Q] . infra first
337                    ...
338        [x2 ...] [Q]   infra first
339        [x1 ...] [Q]   infra first
340        [x0 ...] [Q]   infra first</code></pre>
341 <h3 id="definition-6">Definition</h3>
342 <blockquote>
343 <p>[<a href="#grabn">grabN</a>] <a href="#codi">codi</a> <a href="#map">map</a> <a href="#disenstacken">disenstacken</a></p>
344 </blockquote>
345 <h3 id="discussion-5">Discussion</h3>
346 <p>This function takes a quoted function <code>Q</code> and an integer and runs the function that many times on that many stack items. See also <a href="#app2">app2</a>.</p>
347 <h3 id="crosslinks-5">Crosslinks</h3>
348 <p><a href="#app1">app1</a> <a href="#app2">app2</a> <a href="#app3">app3</a> <a href="#unary">unary</a></p>
349 <hr />
350 <h2 id="section-2">*</h2>
351 <p>See <a href="#mul">mul</a>.</p>
352 <hr />
353 <h2 id="at">at</h2>
354 <p>See <a href="#getitem">getitem</a>.</p>
355 <hr />
356 <h2 id="average">average</h2>
357 <p>Function</p>
358 <p>Compute the average of a list of numbers. (Currently broken until I can figure out what to do about &#x201C;numeric tower&#x201D; in Thun.)</p>
359 <h3 id="definition-7">Definition</h3>
360 <blockquote>
361 <p>[<a href="#sum">sum</a>] [<a href="#size">size</a>] <a href="#cleave">cleave</a> <a href="#section-23">/</a></p>
362 </blockquote>
363 <h3 id="discussion-6">Discussion</h3>
364 <p>Theoretically this function would compute the sum and the size in two separate threads, then divide. This works but a compiled version would probably do better to sum and count the list once, in one thread, eh?</p>
365 <p>As an exercise in Functional Programming in Joy it would be fun to convert this into a catamorphism. See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.</p>
366 <hr />
367 <h2 id="binary">binary</h2>
368 <p>Combinator</p>
369 <p>Run a quoted program using exactly two stack values and leave the first item of the result on the stack.</p>
370 <pre><code>   ... y x [P] binary
371 -----------------------
372         ... a</code></pre>
373 <h3 id="definition-8">Definition</h3>
374 <blockquote>
375 <p><a href="#unary">unary</a> <a href="#popd">popd</a></p>
376 </blockquote>
377 <h3 id="discussion-7">Discussion</h3>
378 <p>Runs any other quoted function and returns its first result while consuming exactly two items from the stack.</p>
379 <h3 id="crosslinks-6">Crosslinks</h3>
380 <p><a href="#nullary">nullary</a> <a href="#ternary">ternary</a> <a href="#unary">unary</a></p>
381 <hr />
382 <h2 id="b">b</h2>
383 <p>Combinator</p>
384 <p>Run two quoted programs</p>
385 <pre><code>   [P] [Q] b
386 ---------------
387       P Q</code></pre>
388 <h3 id="definition-9">Definition</h3>
389 <blockquote>
390 <p>[<a href="#i">i</a>] <a href="#dip">dip</a> <a href="#i">i</a></p>
391 </blockquote>
392 <h3 id="discussion-8">Discussion</h3>
393 <p>This combinator may seem trivial but it comes in handy.</p>
394 <h3 id="crosslinks-7">Crosslinks</h3>
395 <p><a href="#dupdip">dupdip</a> <a href="#ii">ii</a></p>
396 <hr />
397 <h2 id="bool">bool</h2>
398 <p>Basis Function</p>
399 <p>Convert the item on the top of the stack to a Boolean value.</p>
400 <h3 id="discussion-9">Discussion</h3>
401 <p>For integers 0 is <code>false</code> and any other number is <code>true</code>; for lists the empty list is <code>false</code> and all other lists are <code>true</code>.</p>
402 <h3 id="crosslinks-8">Crosslinks</h3>
403 <p><a href="#not">not</a></p>
404 <hr />
405 <h2 id="branch">branch</h2>
406 <p>Basis Combinator</p>
407 <p>Use a Boolean value to select and run one of two quoted programs.</p>
408 <pre><code>   false [F] [T] branch
409 --------------------------
410           F
411
412    true [F] [T] branch
413 -------------------------
414              T</code></pre>
415 <h3 id="definition-10">Definition</h3>
416 <blockquote>
417 <p><a href="#rolldown">rolldown</a> <a href="#choice">choice</a> <a href="#i">i</a></p>
418 </blockquote>
419 <h3 id="discussion-10">Discussion</h3>
420 <p>This is one of the fundamental operations (although it can be defined in terms of <a href="#choice">choice</a> as above). The more common &#x201C;if..then..else&#x201D; construct <a href="#ifte">ifte</a> adds a predicate function that is evaluated <a href="#nullary">nullary</a>.</p>
421 <h3 id="crosslinks-9">Crosslinks</h3>
422 <p><a href="#choice">choice</a> <a href="#ifte">ifte</a> <a href="#select">select</a></p>
423 <hr />
424 <h2 id="section-3">&#x2022;</h2>
425 <p>See <a href="#id">id</a>.</p>
426 <hr />
427 <h2 id="ccccons">ccccons</h2>
428 <p>Function</p>
429 <pre><code>   a b c d [...] ccccons
430 ---------------------------
431        [a b c d ...]</code></pre>
432 <p>Do <a href="#cons">cons</a> four times.</p>
433 <h3 id="definition-11">Definition</h3>
434 <blockquote>
435 <p><a href="#ccons">ccons</a> <a href="#ccons">ccons</a></p>
436 </blockquote>
437 <h3 id="crosslinks-10">Crosslinks</h3>
438 <p><a href="#ccons">ccons</a> <a href="#cons">cons</a> <a href="#times">times</a></p>
439 <hr />
440 <h2 id="ccons">ccons</h2>
441 <p>Function</p>
442 <pre><code>   a b [...] ccons
443 ---------------------
444       [a b ...]</code></pre>
445 <p>Do <a href="#cons">cons</a> two times.</p>
446 <h3 id="definition-12">Definition</h3>
447 <blockquote>
448 <p><a href="#cons">cons</a> <a href="#cons">cons</a></p>
449 </blockquote>
450 <h3 id="crosslinks-11">Crosslinks</h3>
451 <p><a href="#cons">cons</a> <a href="#ccons">ccons</a></p>
452 <hr />
453 <h2 id="choice">choice</h2>
454 <p>Basis Function</p>
455 <p>Use a Boolean value to select one of two items.</p>
456 <pre><code>   a b false choice
457 ----------------------
458           a
459
460    a b true choice
461 ---------------------
462           b</code></pre>
463 <h3 id="definition-13">Definition</h3>
464 <blockquote>
465 <p>[<a href="#pop">pop</a>] [<a href="#popd">popd</a>] <a href="#branch">branch</a></p>
466 </blockquote>
467 <h3 id="discussion-11">Discussion</h3>
468 <p>It&#x2019;s a matter of taste whether you implement this in terms of <a href="#branch">branch</a> or the other way around.</p>
469 <h3 id="crosslinks-12">Crosslinks</h3>
470 <p><a href="#branch">branch</a> <a href="#select">select</a></p>
471 <hr />
472 <h2 id="section-4">^</h2>
473 <p>See <a href="#xor">xor</a>.</p>
474 <hr />
475 <h2 id="clear">clear</h2>
476 <p>Basis Function</p>
477 <p>Clear everything from the stack.</p>
478 <h3 id="definition-14">Definition</h3>
479 <blockquote>
480 <p><a href="#stack">stack</a> <a href="#bool">bool</a> [<a href="#pop">pop</a> <a href="#stack">stack</a> <a href="#bool">bool</a>] <a href="#loop">loop</a></p>
481 </blockquote>
482 <h3 id="crosslinks-13">Crosslinks</h3>
483 <p><a href="#stack">stack</a> <a href="#swaack">swaack</a></p>
484 <hr />
485 <h2 id="cleave">cleave</h2>
486 <p>Combinator</p>
487 <p>Run two programs in parallel, consuming one additional item, and put their results on the stack.</p>
488 <pre><code>   ... x [A] [B] cleave
489 ------------------------
490         ... a b</code></pre>
491 <h3 id="derivation-1">Derivation</h3>
492 <blockquote>
493 <p><a href="#fork">fork</a> <a href="#popdd">popdd</a></p>
494 </blockquote>
495 <h3 id="example-1">Example</h3>
496 <pre><code>   1 2 3 [+] [-] cleave
497 --------------------------
498          1 2 5 -1</code></pre>
499 <h3 id="discussion-12">Discussion</h3>
500 <p>One of a handful of useful parallel combinators.</p>
501 <h3 id="crosslinks-14">Crosslinks</h3>
502 <p><a href="#clop">clop</a> <a href="#fork">fork</a> <a href="#map">map</a></p>
503 <hr />
504 <h2 id="clop">clop</h2>
505 <p>Combinator</p>
506 <p>Run two programs in parallel, consuming two additional items, and put their results on the stack.</p>
507 <pre><code>   ... x y [A] [B] clop
508 --------------------------
509         ... a b</code></pre>
510 <h3 id="definition-15">Definition</h3>
511 <blockquote>
512 <p><a href="#cleave">cleave</a> <a href="#popdd">popdd</a></p>
513 </blockquote>
514 <h3 id="discussion-13">Discussion</h3>
515 <p>Like <a href="#cleave">cleave</a> but consumes an additional item from the stack.</p>
516 <pre><code>   1 2 3 4 [+] [-] clop
517 --------------------------
518          1 2 7 -1</code></pre>
519 <h3 id="crosslinks-15">Crosslinks</h3>
520 <p><a href="#cleave">cleave</a> <a href="#fork">fork</a> <a href="#map">map</a></p>
521 <hr />
522 <h2 id="cmp">cmp</h2>
523 <p>Combinator</p>
524 <p>Take two values and three quoted programs on the stack and run one of the three depending on the results of comparing the two values.</p>
525 <pre><code>   a b [G] [E] [L] cmp
526 ------------------------- a &gt; b
527         G
528
529    a b [G] [E] [L] cmp
530 ------------------------- a = b
531             E
532
533    a b [G] [E] [L] cmp
534 ------------------------- a &lt; b
535                 L</code></pre>
536 <h3 id="discussion-14">Discussion</h3>
537 <p>This is useful sometimes, and you can <a href="#dup">dup</a> or <a href="#dupd">dupd</a> with two quoted programs to handle the cases when you just want to deal with <a href="#section-13">&lt;=</a> or <a href="#section-8">&gt;=</a> and not all three possibilities, e.g.:</p>
538 <pre><code>[G] [EL] dup cmp
539
540 [GE] [L] dupd cmp</code></pre>
541 <p>Or even:</p>
542 <pre><code>[GL] [E] over cmp</code></pre>
543 <h3 id="crosslinks-16">Crosslinks</h3>
544 <p>TODO: link to tree notebooks where this was used.</p>
545 <hr />
546 <h2 id="codi">codi</h2>
547 <p>Combinator</p>
548 <p>Take a quoted program from the stack, <a href="#cons">cons</a> the next item onto it, then <a href="#dip">dip</a> the whole thing under what was the third item on the stack.</p>
549 <pre><code>   a b [F] . codi
550 --------------------
551          b . F a</code></pre>
552 <h3 id="definition-16">Definition</h3>
553 <blockquote>
554 <p><a href="#cons">cons</a> <a href="#dip">dip</a></p>
555 </blockquote>
556 <h3 id="discussion-15">Discussion</h3>
557 <p>This is one of those weirdly specific functions that turns out to be useful in a few places.</p>
558 <h3 id="crosslinks-17">Crosslinks</h3>
559 <p><a href="#appn">appN</a> <a href="#codireco">codireco</a></p>
560 <hr />
561 <h2 id="codireco">codireco</h2>
562 <p>Combinator</p>
563 <p>This is part of the <a href="#make_generator">make_generator</a> function. You would not use this combinator directly.</p>
564 <h3 id="definition-17">Definition</h3>
565 <blockquote>
566 <p><a href="#codi">codi</a> <a href="#reco">reco</a></p>
567 </blockquote>
568 <h3 id="discussion-16">Discussion</h3>
569 <p>See <a href="#make_generator">make_generator</a> and the <a href="https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation">&#x201C;Using <code>x</code> to Generate Values&#x201D; notebook</a> as well as <a href="https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html">Recursion Theory and Joy</a> by Manfred von Thun.</p>
570 <h3 id="crosslinks-18">Crosslinks</h3>
571 <p><a href="#make_generator">make_generator</a></p>
572 <hr />
573 <h2 id="concat">concat</h2>
574 <p>Function</p>
575 <p>Concatinate two lists.</p>
576 <pre><code>   [a b c] [d e f] concat
577 ----------------------------
578        [a b c d e f]</code></pre>
579 <h3 id="crosslinks-19">Crosslinks</h3>
580 <p><a href="#first">first</a> <a href="#first_two">first_two</a> <a href="#flatten">flatten</a> <a href="#fourth">fourth</a> <a href="#getitem">getitem</a> <a href="#remove">remove</a> <a href="#rest">rest</a> <a href="#reverse">reverse</a> <a href="#rrest">rrest</a> <a href="#second">second</a> <a href="#shift">shift</a> <a href="#shunt">shunt</a> <a href="#size">size</a> <a href="#sort">sort</a> <a href="#split_at">split_at</a> <a href="#split_list">split_list</a> <a href="#swaack">swaack</a> <a href="#third">third</a> <a href="#zip">zip</a></p>
581 <hr />
582 <h2 id="cond">cond</h2>
583 <p>Combinator</p>
584 <p>This combinator works like a case statement. It expects a single quote on the stack that must contain zero or more condition quotes and a default quote. Each condition quote should contain a quoted predicate followed by the function expression to run if that predicate returns <code>true</code>. If no predicates return <code>true</code> the default function runs.</p>
585 <pre><code>[
586     [ [Predicate0] Function0 ]
587     [ [Predicate1] Function1 ]
588     ...
589     [ [PredicateN] FunctionN ]
590     [Default]
591 ]
592 cond</code></pre>
593 <h3 id="discussion-17">Discussion</h3>
594 <p>It works by rewriting into a chain of nested <span class="title-ref">ifte</span> expressions, e.g.:</p>
595 <pre><code>      [[[B0] T0] [[B1] T1] [D]] cond
596 -----------------------------------------
597    [B0] [T0] [[B1] [T1] [D] ifte] ifte</code></pre>
598 <h3 id="crosslinks-20">Crosslinks</h3>
599 <p><a href="#ifte">ifte</a></p>
600 <hr />
601 <h2 id="cons">cons</h2>
602 <p>Basis Function</p>
603 <p>Given an item and a list, append the item to the list to make a new list.</p>
604 <pre><code>   a [...] cons
605 ------------------
606      [a ...]</code></pre>
607 <h3 id="discussion-18">Discussion</h3>
608 <p>Cons is a <a href="https://en.wikipedia.org/wiki/Cons#Lists">venerable old function from Lisp</a>. Its inverse operation is <a href="#uncons">uncons</a>.</p>
609 <h3 id="crosslinks-21">Crosslinks</h3>
610 <p><a href="#uncons">uncons</a></p>
611 <hr />
612 <h2 id="dinfrirst">dinfrirst</h2>
613 <p>Combinator</p>
614 <p>Specialist function (that means I forgot what it does and why.)</p>
615 <h3 id="definition-18">Definition</h3>
616 <blockquote>
617 <p><a href="#dip">dip</a> <a href="#infrst">infrst</a></p>
618 </blockquote>
619 <hr />
620 <h2 id="dipdd">dipdd</h2>
621 <p>Combinator</p>
622 <p>Like <a href="#dip">dip</a> but expects three items. :</p>
623 <pre><code>   ... z y x [Q] . dip
624 -----------------------------
625              ... . Q z y x</code></pre>
626 <h3 id="discussion-19">Discussion</h3>
627 <p>See <a href="#dip">dip</a>.</p>
628 <h3 id="crosslinks-22">Crosslinks</h3>
629 <p><a href="#dip">dip</a> <a href="#dipd">dipd</a> <a href="#dupdip">dupdip</a> <a href="#dupdipd">dupdipd</a> <a href="#infra">infra</a></p>
630 <hr />
631 <h2 id="dipd">dipd</h2>
632 <p>Combinator</p>
633 <p>Like <a href="#dip">dip</a> but expects two items.</p>
634 <pre><code>   ... y x [Q] . dipd
635 -------------------------
636            ... . Q y x</code></pre>
637 <h3 id="discussion-20">Discussion</h3>
638 <p>See <a href="#dip">dip</a>.</p>
639 <h3 id="crosslinks-23">Crosslinks</h3>
640 <p><a href="#dip">dip</a> <a href="#dipdd">dipdd</a> <a href="#dupdip">dupdip</a> <a href="#dupdipd">dupdipd</a> <a href="#infra">infra</a></p>
641 <hr />
642 <h2 id="dip">dip</h2>
643 <p>Basis Combinator</p>
644 <p>The <code>dip</code> combinator expects a quoted program on the stack and below it some item, it hoists the item into the expression and runs the program on the rest of the stack.</p>
645 <pre><code>   ... x [Q] . dip
646 ---------------------
647          ... . Q x</code></pre>
648 <h3 id="discussion-21">Discussion</h3>
649 <p>This along with <a href="#infra">infra</a> are enough to update any datastructure. See the <a href="https://joypy.osdn.io/notebooks/Zipper.html">&#x201C;Traversing Datastructures with Zippers&#x201D; notebook</a>.</p>
650 <p>Note that the item that was on the top of the stack (<code>x</code> in the example above) will not be treated specially by the interpreter when it is reached again. This is something of a footgun. My advice is to avoid putting bare unquoted symbols onto the stack, but then you can&#x2019;t use symbols as &#x201C;atoms&#x201D; and also use <code>dip</code> and <code>infra</code> to operate on compound datastructures with atoms in them. This is a kind of side-effect of the Continuation-Passing Style. The <code>dip</code> combinator could &#x201C;set aside&#x201D; the item and replace it after running <code>Q</code> but that means that there is an &#x201C;extra space&#x201D; where the item resides while <code>Q</code> runs. One of the nice things about CPS is that the whole state is recorded in the stack and pending expression (not counting modifications to the dictionary.)</p>
651 <h3 id="crosslinks-24">Crosslinks</h3>
652 <p><a href="#dipd">dipd</a> <a href="#dipdd">dipdd</a> <a href="#dupdip">dupdip</a> <a href="#dupdipd">dupdipd</a> <a href="#infra">infra</a></p>
653 <hr />
654 <h2 id="disenstacken">disenstacken</h2>
655 <p>Function</p>
656 <p>The <code>disenstacken</code> function expects a list on top of the stack and makes that the stack discarding the rest of the stack.</p>
657 <pre><code>   1 2 3 [4 5 6] disenstacken
658 --------------------------------
659             6 5 4</code></pre>
660 <h3 id="definition-19">Definition</h3>
661 <blockquote>
662 <p>[<a href="#clear">clear</a>] <a href="#dip">dip</a> <a href="#reverse">reverse</a> <a href="#unstack">unstack</a></p>
663 </blockquote>
664 <h3 id="discussion-22">Discussion</h3>
665 <p>Note that the order of the list is not changed, it just looks that way because the stack is printed with the top on the right while lists are printed with the top or head on the left.</p>
666 <h3 id="crosslinks-25">Crosslinks</h3>
667 <p><a href="#enstacken">enstacken</a> <a href="#stack">stack</a> <a href="#unstack">unstack</a></p>
668 <hr />
669 <h2 id="div">div</h2>
670 <p>See <a href="#floordiv">floordiv</a>.</p>
671 <hr />
672 <h2 id="divmod">divmod</h2>
673 <p>Function</p>
674 <pre><code>    x y divmod
675 ------------------
676      q      r
677    (x/y)  (x%y)</code></pre>
678 <p>Invariant: <code>qy + r = x</code>.</p>
679 <h3 id="definition-20">Definition</h3>
680 <blockquote>
681 <p>[<a href="#floordiv">floordiv</a>] [<a href="#mod">mod</a>] <a href="#clop">clop</a></p>
682 </blockquote>
683 <hr />
684 <h2 id="down_to_zero">down_to_zero</h2>
685 <p>Function</p>
686 <p>Given a number greater than zero put all the Natural numbers (including zero) less than that onto the stack.</p>
687 <h3 id="example-2">Example</h3>
688 <pre><code>   3 down_to_zero
689 --------------------
690       3 2 1 0</code></pre>
691 <h3 id="definition-21">Definition</h3>
692 <blockquote>
693 <p>[0 &gt;] [<a href="#dup">dup</a> <a href="#section-11">&#x2013;</a>] <a href="#while">while</a></p>
694 </blockquote>
695 <h3 id="crosslinks-26">Crosslinks</h3>
696 <p><a href="#range">range</a></p>
697 <hr />
698 <h2 id="drop">drop</h2>
699 <p>Function</p>
700 <p>Expects an integer and a quote on the stack and returns the quote with n items removed off the top.</p>
701 <h3 id="example-3">Example</h3>
702 <pre><code>   [a b c d] 2 drop
703 ----------------------
704        [c d]</code></pre>
705 <h3 id="definition-22">Definition</h3>
706 <blockquote>
707 <p>[<a href="#rest">rest</a>] <a href="#times">times</a></p>
708 </blockquote>
709 <h3 id="crosslinks-27">Crosslinks</h3>
710 <p><a href="#take">take</a></p>
711 <hr />
712 <h2 id="dupdd">dupdd</h2>
713 <p>Function</p>
714 <p><a href="#dup">dup</a> the third item down on the stack.</p>
715 <pre><code>   a b c dupdd
716 -----------------
717      a a b c</code></pre>
718 <h3 id="definition-23">Definition</h3>
719 <blockquote>
720 <p>[<a href="#dup">dup</a>] <a href="#dipd">dipd</a></p>
721 </blockquote>
722 <h3 id="crosslinks-28">Crosslinks</h3>
723 <p><a href="#dup">dup</a> <a href="#dupd">dupd</a> <a href="#dupdip">dupdip</a> <a href="#dupdipd">dupdipd</a></p>
724 <hr />
725 <h2 id="dupdipd">dupdipd</h2>
726 <p>Combinator</p>
727 <p>Run a copy of program <code>F</code> under the next item down on the stack.</p>
728 <pre><code>   a [F] dupdipd
729 -------------------
730       F a [F]</code></pre>
731 <h3 id="definition-24">Definition</h3>
732 <blockquote>
733 <p><a href="#dup">dup</a> <a href="#dipd">dipd</a></p>
734 </blockquote>
735 <h3 id="crosslinks-29">Crosslinks</h3>
736 <p><a href="#dupdip">dupdip</a></p>
737 <hr />
738 <h2 id="dupdip">dupdip</h2>
739 <p>Combinator</p>
740 <p>Apply a function <code>F</code> and <a href="#dup">dup</a> the item under it on the stack.</p>
741 <pre><code>   a [F] dupdip
742 ------------------
743       a F a</code></pre>
744 <h3 id="definition-25">Definition</h3>
745 <blockquote>
746 <p><a href="#dupd">dupd</a> <a href="#dip">dip</a></p>
747 </blockquote>
748 <h3 id="derivation-2">Derivation</h3>
749 <pre><code>a [F] dupdip
750 a [F] dupd dip
751 a [F] [dup] dip dip
752 a dup [F] dip
753 a a [F] dip
754 a F a</code></pre>
755 <h3 id="discussion-23">Discussion</h3>
756 <p>A very common and useful combinator.</p>
757 <h3 id="crosslinks-30">Crosslinks</h3>
758 <p><a href="#dupdipd">dupdipd</a></p>
759 <hr />
760 <h2 id="dupd">dupd</h2>
761 <p>Function</p>
762 <p><a href="#dup">dup</a> the second item down on the stack.</p>
763 <pre><code>   a b dupd
764 --------------
765     a a b</code></pre>
766 <h3 id="definition-26">Definition</h3>
767 <blockquote>
768 <p>[<a href="#dup">dup</a>] <a href="#dip">dip</a></p>
769 </blockquote>
770 <h3 id="crosslinks-31">Crosslinks</h3>
771 <p><a href="#dup">dup</a> <a href="#dupdd">dupdd</a> <a href="#dupdip">dupdip</a> <a href="#dupdipd">dupdipd</a></p>
772 <hr />
773 <h2 id="dup">dup</h2>
774 <p>Basis Function</p>
775 <p>&#x201C;Dup&#x201D;licate the top item on the stack.</p>
776 <pre><code>   a dup
777 -----------
778     a a</code></pre>
779 <h3 id="crosslinks-32">Crosslinks</h3>
780 <p><a href="#dupd">dupd</a> <a href="#dupdd">dupdd</a> <a href="#dupdip">dupdip</a> <a href="#dupdipd">dupdipd</a></p>
781 <hr />
782 <h2 id="enstacken">enstacken</h2>
783 <p>Function</p>
784 <p>Put the stack onto the stack replacing the contents of the stack.</p>
785 <pre><code>   ... a b c enstacken
786 -------------------------
787        [c b a ...]</code></pre>
788 <h3 id="definition-27">Definition</h3>
789 <blockquote>
790 <p><a href="#stack">stack</a> [<a href="#clear">clear</a>] <a href="#dip">dip</a></p>
791 </blockquote>
792 <h3 id="discussion-24">Discussion</h3>
793 <p>This is a destructive version of <a href="#stack">stack</a>. See the note under <a href="#disenstacken">disenstacken</a> about the apparent but illusory reversal of the stack.</p>
794 <h3 id="crosslinks-33">Crosslinks</h3>
795 <p><a href="#stack">stack</a> [unstack] <a href="#disenstacken">disenstacken</a></p>
796 <hr />
797 <h2 id="eq">eq</h2>
798 <p>Basis Function</p>
799 <p>Compare the two items on the top of the stack for equality and replace them with a Boolean value.</p>
800 <pre><code>   a b eq
801 -------------
802    Boolean
803    (a = b)</code></pre>
804 <h3 id="crosslinks-34">Crosslinks</h3>
805 <p><a href="#cmp">cmp</a> <a href="#ge">ge</a> <a href="#gt">gt</a> <a href="#le">le</a> <a href="#lt">lt</a> <a href="#ne">ne</a></p>
806 <hr />
807 <h2 id="section-5">=</h2>
808 <p>See <a href="#eq">eq</a>.</p>
809 <hr />
810 <h2 id="section-6">!=</h2>
811 <p>See <a href="#ne">ne</a>.</p>
812 <hr />
813 <h2 id="section-7">!-</h2>
814 <p>Function</p>
815 <p>Not negative.</p>
816 <pre><code>    n !-
817 ----------- n &lt; 0
818    false
819
820
821    n !-
822 ---------- n &gt;= 0
823    true</code></pre>
824 <h3 id="definition-28">Definition</h3>
825 <pre><code>0 \&gt;=</code></pre>
826 <h3 id="discussion-25">Discussion</h3>
827 <p>Return a Boolean value indicating if a number is greater than or equal to zero.</p>
828 <hr />
829 <h2 id="first">first</h2>
830 <p>Function</p>
831 <p>Replace a list with its first item.</p>
832 <pre><code>   [a ...]
833 --------------
834       a</code></pre>
835 <h3 id="definition-29">Definition</h3>
836 <blockquote>
837 <p><a href="#uncons">uncons</a> <a href="#pop">pop</a></p>
838 </blockquote>
839 <h3 id="crosslinks-35">Crosslinks</h3>
840 <p><a href="#second">second</a> <a href="#third">third</a> <a href="#fourth">fourth</a> <a href="#rest">rest</a></p>
841 <hr />
842 <h2 id="first_two">first_two</h2>
843 <p>Function</p>
844 <p>Replace a list with its first two items.</p>
845 <pre><code>   [a b ...] first_two
846 -------------------------
847            a b</code></pre>
848 <h3 id="definition-30">Definition</h3>
849 <blockquote>
850 <p><a href="#uncons">uncons</a> <a href="#first">first</a></p>
851 </blockquote>
852 <h3 id="crosslinks-36">Crosslinks</h3>
853 <p><a href="#first">first</a> <a href="#second">second</a> <a href="#third">third</a> <a href="#fourth">fourth</a> <a href="#rest">rest</a></p>
854 <hr />
855 <h2 id="flatten">flatten</h2>
856 <p>Function</p>
857 <p>Given a list of lists, concatinate them.</p>
858 <h3 id="example-4">Example</h3>
859 <pre><code>   [[1 2] [3 [4] 5] [6 7]] flatten
860 -------------------------------------
861           [1 2 3 [4] 5 6 7]</code></pre>
862 <h3 id="definition-31">Definition</h3>
863 <blockquote>
864 <p><a href="#section-15">&lt;{}</a> [<a href="#concat">concat</a>] <a href="#step">step</a></p>
865 </blockquote>
866 <h3 id="discussion-26">Discussion</h3>
867 <p>Note that only one &#x201C;level&#x201D; of lists is flattened. In the example above <code>[4]</code> is not unquoted.</p>
868 <h3 id="crosslinks-37">Crosslinks</h3>
869 <p><a href="#concat">concat</a> <a href="#first">first</a> <a href="#first_two">first_two</a> <a href="#fourth">fourth</a> <a href="#getitem">getitem</a> <a href="#remove">remove</a> <a href="#rest">rest</a> <a href="#reverse">reverse</a> <a href="#rrest">rrest</a> <a href="#second">second</a> <a href="#shift">shift</a> <a href="#shunt">shunt</a> <a href="#size">size</a> <a href="#sort">sort</a> <a href="#split_at">split_at</a> <a href="#split_list">split_list</a> <a href="#swaack">swaack</a> <a href="#third">third</a> <a href="#zip">zip</a></p>
870 <hr />
871 <h2 id="floordiv">floordiv</h2>
872 <p>Basis Function</p>
873 <p>I don&#x2019;t know why this is called &#x201C;floor&#x201D; div, I think it rounds its result down (not towards zero or up.)</p>
874 <pre><code>   a b floordiv
875 ------------------
876       (a/b)</code></pre>
877 <h3 id="discussion-27">Discussion</h3>
878 <p>All the division commands need to be revisited when the &#x201C;numeric tower&#x201D; for Thun gets nailed down.</p>
879 <h3 id="crosslinks-38">Crosslinks</h3>
880 <p><a href="#divmod">divmod</a></p>
881 <hr />
882 <h2 id="floor">floor</h2>
883 <p>Basis Function</p>
884 <p>Return the largest integer &lt;= x.</p>
885 <h3 id="discussion-28">Discussion</h3>
886 <p>This function doesn&#x2019;t make sense (yet) to have because there are (as yet) only integers in the system.</p>
887 <hr />
888 <h2 id="fork">fork</h2>
889 <p>Combinator</p>
890 <p>Run two quoted programs in parallel and replace them with their results.</p>
891 <pre><code>   ... [F] [G] fork
892 ----------------------
893        ... f g</code></pre>
894 <h3 id="definition-32">Definition</h3>
895 <blockquote>
896 <p>[<a href="#i">i</a>] <a href="#app2">app2</a></p>
897 </blockquote>
898 <h3 id="discussion-29">Discussion</h3>
899 <p>The basic parallelism combinator, the two programs are run independently.</p>
900 <h3 id="crosslinks-39">Crosslinks</h3>
901 <p><a href="#cleave">cleave</a> <a href="#clop">clop</a> <a href="#map">map</a></p>
902 <hr />
903 <h2 id="fourth">fourth</h2>
904 <p>Function</p>
905 <p>Replace a list with its fourth item.</p>
906 <pre><code>   [a b c d ...] fourth
907 --------------------------
908           d</code></pre>
909 <h3 id="definition-33">Definition</h3>
910 <blockquote>
911 <p><a href="#rest">rest</a> <a href="#third">third</a></p>
912 </blockquote>
913 <h3 id="crosslinks-40">Crosslinks</h3>
914 <p><a href="#first">first</a> <a href="#second">second</a> <a href="#third">third</a> <a href="#rest">rest</a></p>
915 <hr />
916 <h2 id="gcd2">gcd2</h2>
917 <p>Function</p>
918 <p>Compiled GCD function.</p>
919 <h3 id="discussion-30">Discussion</h3>
920 <p>See <a href="#gcd">gcd</a>.</p>
921 <h3 id="crosslinks-41">Crosslinks</h3>
922 <p><a href="#gcd">gcd</a></p>
923 <hr />
924 <h2 id="gcd">gcd</h2>
925 <p>Function</p>
926 <p>Take two integers from the stack and replace them with their Greatest Common Denominator.</p>
927 <h3 id="definition-34">Definition</h3>
928 <blockquote>
929 <p>true [<a href="#tuck">tuck</a> <a href="#mod">mod</a> <a href="#dup">dup</a> 0 <a href="#section-10">&gt;</a>] <a href="#loop">loop</a> <a href="#pop">pop</a></p>
930 </blockquote>
931 <h3 id="discussion-31">Discussion</h3>
932 <p>Euclid&#x2019;s Algorithm</p>
933 <hr />
934 <h2 id="ge">ge</h2>
935 <p>Basis Function</p>
936 <p>Greater-than-or-equal-to comparison of two numbers.</p>
937 <pre><code>   a b ge
938 --------------
939    Boolean
940    (a &gt;= b)</code></pre>
941 <h3 id="crosslinks-42">Crosslinks</h3>
942 <p><a href="#cmp">cmp</a> <a href="#eq">eq</a> <a href="#gt">gt</a> <a href="#le">le</a> <a href="#lt">lt</a> <a href="#ne">ne</a></p>
943 <hr />
944 <h2 id="genrec">genrec</h2>
945 <p>Combinator</p>
946 <p><strong>Gen</strong>eral <strong>Rec</strong>ursion Combinator.</p>
947 <pre><code>                      [if] [then] [rec1] [rec2] genrec
948 ---------------------------------------------------------------------
949    [if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte</code></pre>
950 <h3 id="definition-35">Definition</h3>
951 <blockquote>
952 <p>[[<a href="#genrec">genrec</a>] <a href="#ccccons">ccccons</a>] <a href="#nullary">nullary</a> <a href="#swons">swons</a> <a href="#concat">concat</a> <a href="#ifte">ifte</a></p>
953 </blockquote>
954 <p>(Note that this definition includes the <code>genrec</code> symbol itself, it is self-referential. This is possible because the definition machinery does not check that symbols in defs are in the dictionary. <code>genrec</code> is the only self-referential definition.)</p>
955 <h3 id="discussion-32">Discussion</h3>
956 <p>See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.</p>
957 <p>From <a href="https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html">&#x201C;Recursion Theory and Joy&#x201D;</a> by Manfred von Thun:</p>
958 <blockquote>
959 <p>&#x201C;The genrec combinator takes four program parameters in addition to whatever data parameters it needs. Fourth from the top is an if-part, followed by a then-part. If the if-part yields true, then the then-part is executed and the combinator terminates. The other two parameters are the rec1-part and the rec2-part. If the if-part yields false, the rec1-part is executed. Following that the four program parameters and the combinator are again pushed onto the stack bundled up in a quoted form. Then the rec2-part is executed, where it will find the bundled form. Typically it will then execute the bundled form, either with i or with app2, or some other combinator.&#x201D;</p>
960 </blockquote>
961 <p>The way to design one of these is to fix your base case <code>[then]</code> and the test <code>[if]</code>, and then treat <code>rec1</code> and <code>rec2</code> as an else-part &#x201C;sandwiching&#x201D; a quotation of the whole function.</p>
962 <p>For example, given a (general recursive) function <code>F</code>:</p>
963 <pre><code>F == [I] [T] [R1] [R2] genrec</code></pre>
964 <p>If the <code>[I]</code> if-part fails you must derive <code>R1</code> and <code>R2</code> from: :</p>
965 <pre><code>... R1 [F] R2</code></pre>
966 <p>Just set the stack arguments in front, and figure out what <code>R1</code> and <code>R2</code> have to do to apply the quoted <code>[F]</code> in the proper way. In effect, the <code>genrec</code> combinator turns into an <a href="#ifte">ifte</a> combinator with a quoted copy of the original definition in the else-part:</p>
967 <pre><code>F == [I] [T] [R1]   [R2] genrec
968   == [I] [T] [R1 [F] R2] ifte</code></pre>
969 <p>Tail recursive functions are those where <code>R2</code> is the <code>i</code> combinator:</p>
970 <pre><code>P == [I] [T] [R] tailrec
971   == [I] [T] [R [P] i] ifte
972   == [I] [T] [R P] ifte</code></pre>
973 <h3 id="crosslinks-43">Crosslinks</h3>
974 <p><a href="#anamorphism">anamorphism</a> <a href="#tailrec">tailrec</a> <a href="#x">x</a></p>
975 <hr />
976 <h2 id="getitem">getitem</h2>
977 <p>Function</p>
978 <p>Expects an integer and a quote on the stack and returns the item at the nth position in the quote counting from 0.</p>
979 <h3 id="example-5">Example</h3>
980 <pre><code>   [a b c d] 2 getitem
981 -------------------------
982         c</code></pre>
983 <h3 id="definition-36">Definition</h3>
984 <blockquote>
985 <p><a href="#drop">drop</a> <a href="#first">first</a></p>
986 </blockquote>
987 <h3 id="discussion-33">Discussion</h3>
988 <p>If the number isn&#x2019;t a valid index into the quote <code>getitem</code> will cause some sort of problem (the exact nature of which is implementation-dependant.)</p>
989 <h3 id="crosslinks-44">Crosslinks</h3>
990 <p><a href="#concat">concat</a> <a href="#first">first</a> <a href="#first_two">first_two</a> <a href="#flatten">flatten</a> <a href="#fourth">fourth</a> <a href="#remove">remove</a> <a href="#rest">rest</a> <a href="#reverse">reverse</a> <a href="#rrest">rrest</a> <a href="#second">second</a> <a href="#shift">shift</a> <a href="#shunt">shunt</a> <a href="#size">size</a> <a href="#sort">sort</a> <a href="#split_at">split_at</a> <a href="#split_list">split_list</a> <a href="#swaack">swaack</a> <a href="#third">third</a> <a href="#zip">zip</a></p>
991 <hr />
992 <h2 id="grabn">grabN</h2>
993 <p>Function</p>
994 <p>Expect a number on the top of the stack and <a href="#cons">cons</a> that many items from under it onto a new list.</p>
995 <h3 id="example-6">Example</h3>
996 <pre><code>   a b c d e 3 grabN
997 -----------------------
998       a b [c d e]</code></pre>
999 <h3 id="definition-37">Definition</h3>
1000 <blockquote>
1001 <p><a href="#section-15">&lt;{}</a> [<a href="#cons">cons</a>] <a href="#times">times</a></p>
1002 </blockquote>
1003 <hr />
1004 <h2 id="grba">grba</h2>
1005 <p>Function</p>
1006 <p>A weird function used in <a href="#app2">app2</a> that does this:</p>
1007 <pre><code>      ... 1 2 3 4 5 grba
1008 -------------------------------
1009    ... 1 2 3 [4 3 2 1 ...] 5</code></pre>
1010 <p>It grabs the stack under the top item, and substitutes it for the second item down on the stack.</p>
1011 <h3 id="definition-38">Definition</h3>
1012 <blockquote>
1013 <p>[<a href="#stack">stack</a> <a href="#popd">popd</a>] <a href="#dip">dip</a></p>
1014 </blockquote>
1015 <h3 id="discussion-34">Discussion</h3>
1016 <p>This function &#x201C;grabs&#x201D; an item from the stack along with a copy of the stack. It&#x2019;s part of the <a href="#app2">app2</a> definition.</p>
1017 <h3 id="crosslinks-45">Crosslinks</h3>
1018 <p><a href="#app2">app2</a></p>
1019 <hr />
1020 <h2 id="section-8">&gt;=</h2>
1021 <p>See <a href="#ge">ge</a>.</p>
1022 <hr />
1023 <h2 id="section-9">&gt;&gt;</h2>
1024 <p>See <a href="#rshift">rshift</a>.</p>
1025 <hr />
1026 <h2 id="section-10">&gt;</h2>
1027 <p>See <a href="#gt">gt</a>.</p>
1028 <hr />
1029 <h2 id="gt">gt</h2>
1030 <p>Basis Function</p>
1031 <p>Greater-than comparison of two numbers.</p>
1032 <pre><code>   a b gt
1033 --------------
1034    Boolean
1035    (a &gt; b)</code></pre>
1036 <h3 id="crosslinks-46">Crosslinks</h3>
1037 <p><a href="#cmp">cmp</a> <a href="#eq">eq</a> <a href="#ge">ge</a> <a href="#le">le</a> <a href="#lt">lt</a> <a href="#ne">ne</a></p>
1038 <hr />
1039 <h2 id="help">help</h2>
1040 <p>Function</p>
1041 <p>Accepts a quoted symbol on the top of the stack and prints its documentation.</p>
1042 <pre><code>   [foo] help
1043 ----------------</code></pre>
1044 <h3 id="discussion-35">Discussion</h3>
1045 <p>Technically this is equivalent to <code>pop</code>, but it will only work if the item on the top of the stack is a quoted symbol.</p>
1046 <hr />
1047 <h2 id="section-11">&#x2013;</h2>
1048 <p>See <a href="#pred">pred</a>.</p>
1049 <hr />
1050 <h2 id="section-12">-</h2>
1051 <p>See <a href="#sub">sub</a>.</p>
1052 <hr />
1053 <h2 id="hypot">hypot</h2>
1054 <p>Function</p>
1055 <pre><code>         x y hypot
1056 ---------------------------
1057    sqrt(sqr(x) + sqr(y))</code></pre>
1058 <h3 id="definition-39">Definition</h3>
1059 <blockquote>
1060 <p>[<a href="#sqr">sqr</a>] <a href="#ii">ii</a> <a href="#section-20">+</a> <a href="#sqrt">sqrt</a></p>
1061 </blockquote>
1062 <h3 id="discussion-36">Discussion</h3>
1063 <p>This is another function that has to wait on the numeric tower.</p>
1064 <h3 id="crosslinks-47">Crosslinks</h3>
1065 <p><a href="#sqrt">sqrt</a></p>
1066 <hr />
1067 <h2 id="id">id</h2>
1068 <p>Basis Function</p>
1069 <p>The identity function.</p>
1070 <h3 id="discussion-37">Discussion</h3>
1071 <p>Does nothing. It&#x2019;s kind of a mathematical thing, but it occasionally comes in handy.</p>
1072 <hr />
1073 <h2 id="ifte">ifte</h2>
1074 <p>Combinator</p>
1075 <p>If-Then-Else combinator, a common and convenient specialization of <a href="#branch">branch</a>.</p>
1076 <pre><code>        [if] [then] [else] ifte
1077 ---------------------------------------
1078    [if] nullary [else] [then] branch</code></pre>
1079 <h3 id="definition-40">Definition</h3>
1080 <blockquote>
1081 <p>[<a href="#nullary">nullary</a>] <a href="#dipd">dipd</a> <a href="#swap">swap</a> <a href="#branch">branch</a></p>
1082 </blockquote>
1083 <h3 id="crosslinks-48">Crosslinks</h3>
1084 <p><a href="#branch">branch</a> <a href="#loop">loop</a> <a href="#while">while</a></p>
1085 <hr />
1086 <h2 id="ii">ii</h2>
1087 <p>Combinator</p>
1088 <p>Take a quoted program from the stack and run it twice, first under the top item, then again with the top item.</p>
1089 <pre><code>... a [Q] ii
1090 ------------------
1091  ... Q a Q</code></pre>
1092 <h3 id="definition-41">Definition</h3>
1093 <blockquote>
1094 <p>[<a href="#dip">dip</a>] <a href="#dupdip">dupdip</a> <a href="#i">i</a></p>
1095 </blockquote>
1096 <h3 id="example-7">Example</h3>
1097 <p>It&#x2019;s a little tricky to understand how this works so here&#x2019;s an example trace:</p>
1098 <pre><code>      1 2 3 4 [++] &#x2022; [dip] dupdip i
1099 1 2 3 4 [++] [dip] &#x2022; dupdip i
1100       1 2 3 4 [++] &#x2022; dip [++] i
1101              1 2 3 &#x2022; ++ 4 [++] i
1102              1 2 4 &#x2022; 4 [++] i
1103            1 2 4 4 &#x2022; [++] i
1104       1 2 4 4 [++] &#x2022; i
1105            1 2 4 4 &#x2022; ++
1106            1 2 4 5 &#x2022;</code></pre>
1107 <h3 id="discussion-38">Discussion</h3>
1108 <p>In some cases (like the example above) this is the same effect as using <a href="#app2">app2</a> but most of the time it&#x2019;s not:</p>
1109 <pre><code>   1 2 3 4 [+] ii
1110 --------------------
1111         1 9
1112
1113    1 2 3 4 [+] app2
1114 ----------------------
1115        1 2 5 6</code></pre>
1116 <h3 id="crosslinks-49">Crosslinks</h3>
1117 <p><a href="#app2">app2</a> <a href="#b">b</a></p>
1118 <hr />
1119 <h2 id="i">i</h2>
1120 <p>Basis Combinator</p>
1121 <p>Append a quoted expression onto the pending expression.</p>
1122 <pre><code>   [Q] . i
1123 -------------
1124        . Q</code></pre>
1125 <h3 id="discussion-39">Discussion</h3>
1126 <p>This is a fundamental combinator. It is used in all kinds of places. For example, the <a href="#x">x</a> combinator can be defined as <code>dup i</code>.</p>
1127 <hr />
1128 <h2 id="infra">infra</h2>
1129 <p>Combinator</p>
1130 <p>Accept a quoted program and a list on the stack and run the program with the list as its stack. Does not affect the stack (below the list.)</p>
1131 <pre><code>   ... x y z [a b c] [Q] infra
1132 ---------------------------------
1133     c b a Q [z y x ...] swaack</code></pre>
1134 <h3 id="definition-42">Definition</h3>
1135 <blockquote>
1136 <p><a href="#swons">swons</a> <a href="#swaack">swaack</a> [<a href="#i">i</a>] <a href="#dip">dip</a> <a href="#swaack">swaack</a></p>
1137 </blockquote>
1138 <pre><code>... [a b c] [F] swons swaack [i] dip swaack
1139 ... [[F] a b c]       swaack [i] dip swaack
1140
1141 c b a [F]   [...] [i] dip swaack
1142 c b a [F] i [...]         swaack
1143 c b a  F    [...]         swaack
1144 d e         [...]         swaack
1145 ... [e d]</code></pre>
1146 <h3 id="discussion-40">Discussion</h3>
1147 <p>This is one of the more useful combinators. It allows a quoted expression to serve as a stack for a program, effectively running it in a kind of &#x201C;pocket universe&#x201D;. If the list represents a datastructure then <code>infra</code> lets you work on its internal structure.</p>
1148 <h3 id="crosslinks-50">Crosslinks</h3>
1149 <p><a href="#swaack">swaack</a></p>
1150 <hr />
1151 <h2 id="infrst">infrst</h2>
1152 <p>Combinator</p>
1153 <p>Does <a href="#infra">infra</a> and then extracts the <a href="#first">first</a> item from the resulting list.</p>
1154 <h3 id="definition-43">Definition</h3>
1155 <blockquote>
1156 <p><a href="#infra">infra</a> <a href="#first">first</a></p>
1157 </blockquote>
1158 <hr />
1159 <h2 id="inscribe">inscribe</h2>
1160 <p>Create a new Joy function definition in the Joy dictionary. A definition is given as a quote with a name followed by a Joy expression.</p>
1161 <h3 id="example-8">Example</h3>
1162 <pre><code>[sqr dup mul] inscribe</code></pre>
1163 <h3 id="discussion-41">Discussion</h3>
1164 <p>This is the only function that modifies the dictionary. It&#x2019;s provided as a convenience, for tinkering with new definitions before entering them into the <code>defs.txt</code> file. It can be abused, which you should avoid unless you know what you&#x2019;re doing.</p>
1165 <hr />
1166 <h2 id="le">le</h2>
1167 <p>Basis Function</p>
1168 <p>Less-Than-or-Equal-to comparison of the two items on the top of the stack, replacing them with a Boolean value.</p>
1169 <pre><code>   a b le
1170 -------------
1171    Boolean
1172    (a &lt;= b)</code></pre>
1173 <h3 id="crosslinks-51">Crosslinks</h3>
1174 <p><a href="#cmp">cmp</a> <a href="#eq">eq</a> <a href="#ge">ge</a> <a href="#gt">gt</a> <a href="#lt">lt</a> <a href="#ne">ne</a></p>
1175 <hr />
1176 <h2 id="section-13">&lt;=</h2>
1177 <p>See <a href="#le">le</a>.</p>
1178 <hr />
1179 <h2 id="section-14">&lt;&gt;</h2>
1180 <p>See <a href="#ne">ne</a>.</p>
1181 <hr />
1182 <h2 id="section-15">&lt;{}</h2>
1183 <p>Function</p>
1184 <pre><code>   ... a &lt;{}
1185 ----------------
1186    ... [] a</code></pre>
1187 <h3 id="definition-44">Definition</h3>
1188 <pre><code>[] swap</code></pre>
1189 <h3 id="discussion-42">Discussion</h3>
1190 <p>Tuck an empty list just under the first item on the stack.</p>
1191 <h3 id="crosslinks-52">Crosslinks</h3>
1192 <p><a href="#section-18">&lt;&lt;{}</a></p>
1193 <hr />
1194 <h2 id="section-16">&lt;&lt;{}</h2>
1195 <p>Function</p>
1196 <pre><code>   ... b a &lt;{}
1197 -----------------
1198    ... [] b a</code></pre>
1199 <h3 id="definition-45">Definition</h3>
1200 <pre><code>[] rollup</code></pre>
1201 <h3 id="discussion-43">Discussion</h3>
1202 <p>Tuck an empty list just under the first two items on the stack.</p>
1203 <h3 id="crosslinks-53">Crosslinks</h3>
1204 <p><a href="#section-16">&lt;{}</a></p>
1205 <hr />
1206 <h2 id="section-17">&lt;&lt;</h2>
1207 <p>See <a href="#lshift">lshift</a>.</p>
1208 <hr />
1209 <h2 id="section-18">&lt;</h2>
1210 <p>See <a href="#lt">lt</a>.</p>
1211 <hr />
1212 <h2 id="loop">loop</h2>
1213 <p>Basis Combinator</p>
1214 <p>Expect a quoted program <code>Q</code> and a Boolean value on the stack. If the value is false discard the quoted program, otherwise run a copy of <code>Q</code> and <code>loop</code> again.</p>
1215 <pre><code>   false [Q] loop
1216 --------------------
1217
1218
1219    true [Q] . loop
1220 --------------------------
1221             . Q [Q] loop</code></pre>
1222 <h3 id="discussion-44">Discussion</h3>
1223 <p>This, along with <a href="#branch">branch</a> and <a href="#fork">fork</a>, is one of the four main combinators of all programming. The fourth, sequence, is implied by juxtaposition. That is to say, in Joy <code>F G</code> is like <code>G(F(...))</code> in a language bassed on function application. Or again, to quote the <a href="https://en.wikipedia.org/wiki/Joy_(programming_language)#Mathematical_purity">Joy Wikipedia entry</a>,</p>
1224 <blockquote>
1225 <p>In Joy, the meaning function is a homomorphism from the syntactic monoid onto the semantic monoid. That is, the syntactic relation of concatenation of symbols maps directly onto the semantic relation of composition of functions.</p>
1226 </blockquote>
1227 <p>Anyway, <a href="#branch">branch</a>, <a href="#fork">fork</a>, amd <a href="#loop">loop</a> are the fundamental combinators in Joy. Just as <a href="#branch">branch</a> has it&#x2019;s more common and convenient form <a href="#ifte">ifte</a>, <a href="#loop">loop</a> has <a href="#while">while</a>.</p>
1228 <h3 id="crosslinks-54">Crosslinks</h3>
1229 <p><a href="#branch">branch</a> <a href="#fork">fork</a> <a href="#while">while</a></p>
1230 <hr />
1231 <h2 id="lshift">lshift</h2>
1232 <p>Basis Function</p>
1233 <p><a href="https://en.wikipedia.org/wiki/Logical_shift">Logical Left-Shift</a></p>
1234 <pre><code>   a n lshift
1235 ----------------
1236      (a&#xD7;2&#x207F;)</code></pre>
1237 <h3 id="crosslinks-55">Crosslinks</h3>
1238 <p><a href="#rshift">rshift</a></p>
1239 <hr />
1240 <h2 id="lt">lt</h2>
1241 <p>Basis Function</p>
1242 <p>Less-Than comparison of the two items on the top of the stack, replacing them with a Boolean value.</p>
1243 <pre><code>   a b lt
1244 -------------
1245    Boolean
1246    (a &lt; b)</code></pre>
1247 <h3 id="crosslinks-56">Crosslinks</h3>
1248 <p><a href="#cmp">cmp</a> <a href="#eq">eq</a> <a href="#ge">ge</a> <a href="#gt">gt</a> <a href="#le">le</a> <a href="#ne">ne</a></p>
1249 <hr />
1250 <h2 id="make_generator">make_generator</h2>
1251 <p>Function</p>
1252 <p>Given an initial state value and a quoted generator function build a generator quote.</p>
1253 <pre><code>   state [generator function] make_generator
1254 -----------------------------------------------
1255      [state [generator function] codireco]</code></pre>
1256 <h3 id="example-9">Example</h3>
1257 <pre><code>   230 [dup ++] make_generator
1258 ---------------------------------
1259      [230 [dup ++] codireco]</code></pre>
1260 <p>And then:</p>
1261 <pre><code>   [230 [dup ++] codireco] 5 [x] times pop
1262 ---------------------------------------------
1263              230 231 232 233 234</code></pre>
1264 <h3 id="definition-46">Definition</h3>
1265 <blockquote>
1266 <p>[<a href="#codireco">codireco</a>] <a href="#ccons">ccons</a></p>
1267 </blockquote>
1268 <h3 id="discussion-45">Discussion</h3>
1269 <p>See the <a href="https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation">&#x201C;Using <code>x</code> to Generate Values&#x201D; notebook</a>.</p>
1270 <h3 id="crosslinks-57">Crosslinks</h3>
1271 <p><a href="#codireco">codireco</a></p>
1272 <hr />
1273 <h2 id="map">map</h2>
1274 <p>Combinator</p>
1275 <p>Given a list of items and a quoted program run the program for each item in the list (with the rest of the stack) and replace the old list and the program with a list of the results.</p>
1276 <h3 id="example-10">Example</h3>
1277 <pre><code>   5 [1 2 3] [++ *] map
1278 --------------------------
1279        5 [10 15 20]</code></pre>
1280 <h3 id="discussion-46">Discussion</h3>
1281 <p>This is a common operation in many languages. In Joy it can be a parallelism combinator due to the &#x201C;pure&#x201D; nature of the language.</p>
1282 <h3 id="crosslinks-58">Crosslinks</h3>
1283 <p><a href="#app1">app1</a> <a href="#app2">app2</a> <a href="#app3">app3</a> <a href="#appn">appN</a> <a href="#fork">fork</a></p>
1284 <hr />
1285 <h2 id="max">max</h2>
1286 <p>Basis Function</p>
1287 <p>Given a list find the maximum.</p>
1288 <h3 id="example-11">Example</h3>
1289 <pre><code>   [1 2 3 4] max
1290 -------------------
1291          4</code></pre>
1292 <h3 id="crosslinks-59">Crosslinks</h3>
1293 <p><a href="#min">min</a> <a href="#size">size</a> <a href="#sum">sum</a></p>
1294 <hr />
1295 <h2 id="min">min</h2>
1296 <p>Basis Function</p>
1297 <p>Given a list find the minimum.</p>
1298 <h3 id="example-12">Example</h3>
1299 <pre><code>   [1 2 3 4] min
1300 -------------------
1301          1 </code></pre>
1302 <h3 id="crosslinks-60">Crosslinks</h3>
1303 <p><a href="#max">max</a> <a href="#size">size</a> <a href="#sum">sum</a></p>
1304 <hr />
1305 <h2 id="mod">mod</h2>
1306 <p>Basis Function</p>
1307 <p>Return the remainder of <code>a</code> divided by <code>b</code>.</p>
1308 <pre><code>   a b mod
1309 -------------
1310     (a%b)</code></pre>
1311 <h3 id="crosslinks-61">Crosslinks</h3>
1312 <p><a href="#divmod">divmod</a> <a href="#mul">mul</a></p>
1313 <hr />
1314 <h2 id="modulus">modulus</h2>
1315 <p>See <a href="#mod">mod</a>.</p>
1316 <hr />
1317 <h2 id="mul">mul</h2>
1318 <p>Basis Function</p>
1319 <p>Multiply two numbers.</p>
1320 <pre><code>   a b mul
1321 -------------
1322     (a&#xD7;b)</code></pre>
1323 <h3 id="crosslinks-62">Crosslinks</h3>
1324 <p><a href="#div">div</a> <a href="#product">product</a></p>
1325 <hr />
1326 <h2 id="neg">neg</h2>
1327 <p>Function</p>
1328 <p>Invert the sign of a number.</p>
1329 <pre><code>   a neg
1330 -----------
1331     -a</code></pre>
1332 <h3 id="definition-47">Definition</h3>
1333 <blockquote>
1334 <p>0 <a href="#swap">swap</a> <a href="#section-12">-</a></p>
1335 </blockquote>
1336 <hr />
1337 <h2 id="ne">ne</h2>
1338 <p>Basis Function</p>
1339 <p>Not-Equal comparison of the two items on the top of the stack, replacing them with a Boolean value.</p>
1340 <pre><code>   a b ne
1341 -------------
1342    Boolean
1343    (a = b)</code></pre>
1344 <h3 id="crosslinks-63">Crosslinks</h3>
1345 <p><a href="#cmp">cmp</a> <a href="#eq">eq</a> <a href="#ge">ge</a> <a href="#gt">gt</a> <a href="#le">le</a> <a href="#lt">lt</a></p>
1346 <hr />
1347 <h2 id="not">not</h2>
1348 <p>Function</p>
1349 <p>Like <a href="#bool">bool</a> but convert the item on the top of the stack to the inverse Boolean value.</p>
1350 <pre><code>   true not
1351 --------------
1352     false
1353
1354    false not
1355 ---------------
1356      true</code></pre>
1357 <h3 id="definition-48">Definition</h3>
1358 <blockquote>
1359 <p><a href="#bool">bool</a> [true] [false] <a href="#branch">branch</a></p>
1360 </blockquote>
1361 <h3 id="crosslinks-64">Crosslinks</h3>
1362 <p><a href="#bool">bool</a></p>
1363 <hr />
1364 <h2 id="nulco">nulco</h2>
1365 <p>Function</p>
1366 <p>Take the item on the top of the stack and <a href="#cons">cons</a> it onto <code>[nullary]</code>.</p>
1367 <pre><code>     [F] nulco
1368 -------------------
1369    [[F] nullary]</code></pre>
1370 <h3 id="definition-49">Definition</h3>
1371 <blockquote>
1372 <p>[<a href="#nullary">nullary</a>] <a href="#cons">cons</a></p>
1373 </blockquote>
1374 <h3 id="discussion-47">Discussion</h3>
1375 <p>Helper function for <a href="#section-25">||</a> and <a href="#section">&amp;&amp;</a>.</p>
1376 <h3 id="crosslinks-65">Crosslinks</h3>
1377 <p><a href="#section">&amp;&amp;</a> <a href="#section-25">||</a></p>
1378 <hr />
1379 <h2 id="nullary">nullary</h2>
1380 <p>Combinator</p>
1381 <p>Run a quoted program without using any stack values and leave the first item of the result on the stack.</p>
1382 <pre><code>   ... [P] nullary
1383 ---------------------
1384         ... a</code></pre>
1385 <h3 id="definition-50">Definition</h3>
1386 <blockquote>
1387 <p>[<a href="#stack">stack</a>] <a href="#dip">dip</a> <a href="#infra">infra</a> <a href="#first">first</a></p>
1388 </blockquote>
1389 <h3 id="example-13">Example</h3>
1390 <pre><code>... [P] nullary
1391 ... [P] [stack] dip infra first
1392 ... stack [P] infra first
1393 ... [...] [P] infra first
1394 ... [a ...] first
1395 ...  a</code></pre>
1396 <h3 id="discussion-48">Discussion</h3>
1397 <p>A very useful function that runs any other quoted function and returns it&#x2019;s first result without disturbing the stack (under the quoted program.)</p>
1398 <h3 id="crosslinks-66">Crosslinks</h3>
1399 <p><a href="#unary">unary</a> <a href="#binary">binary</a> <a href="#ternary">ternary</a></p>
1400 <hr />
1401 <h2 id="of">of</h2>
1402 <p>Function</p>
1403 <p>Like <a href="#getitem">getitem</a> but <a href="#swap">swap</a>s the order of arguments.</p>
1404 <h3 id="example-14">Example</h3>
1405 <pre><code>   2 [a b c d] of
1406 --------------------
1407          c</code></pre>
1408 <h3 id="definition-51">Definition</h3>
1409 <blockquote>
1410 <p><a href="#swap">swap</a> <a href="#getitem">getitem</a></p>
1411 </blockquote>
1412 <h3 id="crosslinks-67">Crosslinks</h3>
1413 <p><a href="#getitem">getitem</a></p>
1414 <hr />
1415 <h2 id="or">or</h2>
1416 <p>Basis Function</p>
1417 <p>Logical bit-wise OR.</p>
1418 <h3 id="crosslinks-68">Crosslinks</h3>
1419 <p><a href="#and">and</a> <a href="#xor">xor</a></p>
1420 <hr />
1421 <h2 id="over">over</h2>
1422 <p>Function</p>
1423 <p><a href="#dup">dup</a> the second item on the stack <code>over</code> the first.</p>
1424 <pre><code>   a b over
1425 --------------
1426     a b a</code></pre>
1427 <h3 id="definition-52">Definition</h3>
1428 <p>There are many many ways to define this function.</p>
1429 <blockquote>
1430 <p><a href="#swap">swap</a> <a href="#tuck">tuck</a></p>
1431 </blockquote>
1432 <blockquote>
1433 <p>[<a href="#pop">pop</a>] <a href="#nullary">nullary</a></p>
1434 </blockquote>
1435 <blockquote>
1436 <p>[<a href="#dup">dup</a>] <a href="#dip">dip</a> <a href="#swap">swap</a></p>
1437 </blockquote>
1438 <blockquote>
1439 <p><a href="#unit">unit</a> <a href="#dupdip">dupdip</a></p>
1440 </blockquote>
1441 <blockquote>
1442 <p><a href="#unit">unit</a> <a href="#dupdipd">dupdipd</a> <a href="#first">first</a></p>
1443 </blockquote>
1444 <p>And so on&#x2026;</p>
1445 <h3 id="discussion-49">Discussion</h3>
1446 <p>A fine old word from Forth.</p>
1447 <h3 id="crosslinks-69">Crosslinks</h3>
1448 <p><a href="#tuck">tuck</a></p>
1449 <hr />
1450 <h2 id="pam">pam</h2>
1451 <p>Combinator</p>
1452 <p>Take a list of quoted functions from the stack and replace it with a list of the <a href="#first">first</a> results from running those functions (on copies of the rest of the stack.)</p>
1453 <h3 id="example-15">Example</h3>
1454 <pre><code>   5 7 [[+][-][*][/][%]] pam
1455 -------------------------------
1456       5 7 [12 -2 35 0 5]</code></pre>
1457 <h3 id="definition-53">Definition</h3>
1458 <blockquote>
1459 <p>[<a href="#i">i</a>] <a href="#map">map</a></p>
1460 </blockquote>
1461 <h3 id="discussion-50">Discussion</h3>
1462 <p>A specialization of <a href="#map">map</a> that runs a list of functions in parallel (if the underlying <a href="#map">map</a> function is so implemented, of course.)</p>
1463 <h3 id="crosslinks-70">Crosslinks</h3>
1464 <p><a href="#map">map</a></p>
1465 <hr />
1466 <h2 id="section-19">%</h2>
1467 <p>See <a href="#mod">mod</a>.</p>
1468 <hr />
1469 <h2 id="pick">pick</h2>
1470 <p>See <a href="#getitem">getitem</a>.</p>
1471 <hr />
1472 <h2 id="section-20">+</h2>
1473 <p>See <a href="#add">add</a>.</p>
1474 <hr />
1475 <h2 id="section-21">++</h2>
1476 <p>See <a href="#succ">succ</a>.</p>
1477 <hr />
1478 <h2 id="pm">pm</h2>
1479 <p>Function</p>
1480 <p>Plus or minus. Replace two numbers with their sum and difference.</p>
1481 <pre><code>      a b pm
1482 -----------------
1483    (a+b) (a-b)</code></pre>
1484 <h3 id="definition-54">Definition</h3>
1485 <blockquote>
1486 <p>[+] [-] <a href="#clop">clop</a></p>
1487 </blockquote>
1488 <hr />
1489 <h2 id="popdd">popdd</h2>
1490 <p>Function</p>
1491 <p><a href="#pop">pop</a> the third item on the stack.</p>
1492 <pre><code>   a b c popdd
1493 -----------------
1494        b c</code></pre>
1495 <h3 id="definition-55">Definition</h3>
1496 <blockquote>
1497 <p><a href="#rolldown">rolldown</a> <a href="#pop">pop</a></p>
1498 </blockquote>
1499 <h3 id="crosslinks-71">Crosslinks</h3>
1500 <p><a href="#pop">pop</a> <a href="#popd">popd</a> <a href="#popop">popop</a> <a href="#popopd">popopd</a> <a href="#popopdd">popopdd</a> <a href="#popopop">popopop</a></p>
1501 <hr />
1502 <h2 id="popd">popd</h2>
1503 <p>Function</p>
1504 <p><a href="#pop">pop</a> the second item down on the stack.</p>
1505 <pre><code>   a b popd
1506 --------------
1507       b</code></pre>
1508 <h3 id="definition-56">Definition</h3>
1509 <blockquote>
1510 <p><a href="#swap">swap</a> <a href="#pop">pop</a></p>
1511 </blockquote>
1512 <h3 id="crosslinks-72">Crosslinks</h3>
1513 <p><a href="#pop">pop</a> <a href="#popdd">popdd</a> <a href="#popop">popop</a> <a href="#popopd">popopd</a> <a href="#popopdd">popopdd</a> <a href="#popopop">popopop</a></p>
1514 <hr />
1515 <h2 id="pop">pop</h2>
1516 <p>Basis Function</p>
1517 <p>Pop the top item from the stack and discard it.</p>
1518 <pre><code>   a pop
1519 -----------</code></pre>
1520 <h3 id="crosslinks-73">Crosslinks</h3>
1521 <p><a href="#popd">popd</a> <a href="#popdd">popdd</a> <a href="#popop">popop</a> <a href="#popopd">popopd</a> <a href="#popopdd">popopdd</a> <a href="#popopop">popopop</a></p>
1522 <hr />
1523 <h2 id="popopdd">popopdd</h2>
1524 <p>Function</p>
1525 <pre><code>   a b c d popopdd
1526 ---------------------
1527         c d</code></pre>
1528 <h3 id="definition-57">Definition</h3>
1529 <blockquote>
1530 <p>[<a href="#popop">popop</a>] <a href="#dipd">dipd</a></p>
1531 </blockquote>
1532 <h3 id="crosslinks-74">Crosslinks</h3>
1533 <p><a href="#pop">pop</a> <a href="#popd">popd</a> <a href="#popdd">popdd</a> <a href="#popop">popop</a> <a href="#popopd">popopd</a> <a href="#popopop">popopop</a></p>
1534 <hr />
1535 <h2 id="popopd">popopd</h2>
1536 <p>Function</p>
1537 <p><a href="#pop">pop</a> the second and third items from the stack.</p>
1538 <pre><code>   a b c popopd
1539 ------------------
1540         c</code></pre>
1541 <h3 id="definition-58">Definition</h3>
1542 <blockquote>
1543 <p><a href="#rollup">rollup</a> <a href="#popop">popop</a></p>
1544 </blockquote>
1545 <h3 id="crosslinks-75">Crosslinks</h3>
1546 <p><a href="#pop">pop</a> <a href="#popd">popd</a> <a href="#popdd">popdd</a> <a href="#popop">popop</a> <a href="#popopdd">popopdd</a> <a href="#popopop">popopop</a></p>
1547 <hr />
1548 <h2 id="popop">popop</h2>
1549 <p>Function</p>
1550 <p><a href="#pop">pop</a> two items from the stack.</p>
1551 <pre><code>   a b popop
1552 ---------------</code></pre>
1553 <h3 id="definition-59">Definition</h3>
1554 <blockquote>
1555 <p><a href="#pop">pop</a> <a href="#pop">pop</a></p>
1556 </blockquote>
1557 <h3 id="crosslinks-76">Crosslinks</h3>
1558 <p><a href="#pop">pop</a> <a href="#popd">popd</a> <a href="#popdd">popdd</a> <a href="#popopd">popopd</a> <a href="#popopdd">popopdd</a> <a href="#popopop">popopop</a></p>
1559 <hr />
1560 <h2 id="popopop">popopop</h2>
1561 <p>Function</p>
1562 <p><a href="#pop">pop</a> three items from the stack.</p>
1563 <pre><code>   a b c popopop
1564 -------------------</code></pre>
1565 <h3 id="definition-60">Definition</h3>
1566 <blockquote>
1567 <p><a href="#pop">pop</a> <a href="#popop">popop</a></p>
1568 </blockquote>
1569 <h3 id="crosslinks-77">Crosslinks</h3>
1570 <p><a href="#pop">pop</a> <a href="#popd">popd</a> <a href="#popdd">popdd</a> <a href="#popop">popop</a> <a href="#popopd">popopd</a> <a href="#popopdd">popopdd</a></p>
1571 <hr />
1572 <h2 id="pow">pow</h2>
1573 <p>Basis Function</p>
1574 <p>Take two numbers <code>a</code> and <code>n</code> from the stack and raise <code>a</code> to the <code>n</code>th power. (<code>n</code> is on the top of the stack.)</p>
1575 <pre><code>   a n pow
1576 -------------
1577     (a&#x207F;)</code></pre>
1578 <h3 id="example-16">Example</h3>
1579 <pre><code>   2 [2 3 4 5 6 7 8 9] [pow] map
1580 -----------------------------------
1581     2 [4 8 16 32 64 128 256 512]</code></pre>
1582 <hr />
1583 <h2 id="pred">pred</h2>
1584 <p>Function</p>
1585 <p>Predecessor. Decrement TOS.</p>
1586 <h3 id="definition-61">Definition</h3>
1587 <blockquote>
1588 <p>1 -</p>
1589 </blockquote>
1590 <h3 id="crosslinks-78">Crosslinks</h3>
1591 <p><a href="#succ">succ</a></p>
1592 <hr />
1593 <h2 id="primrec">primrec</h2>
1594 <p>Combinator</p>
1595 <p>From the <a href="https://www.kevinalbrecht.com/code/joy-mirror/j00ovr.html">&#x201C;Overview of the language JOY&#x201D;</a></p>
1596 <blockquote>
1597 <p>The primrec combinator expects two quoted programs in addition to a data parameter. For an integer data parameter it works like this: If the data parameter is zero, then the first quotation has to produce the value to be returned. If the data parameter is positive then the second has to combine the data parameter with the result of applying the function to its predecessor.</p>
1598 </blockquote>
1599 <blockquote>
1600 <p>5 [1] [*] primrec</p>
1601 </blockquote>
1602 <blockquote>
1603 <p>Then primrec tests whether the top element on the stack (initially the 5) is equal to zero. If it is, it pops it off and executes one of the quotations, the [1] which leaves 1 on the stack as the result. Otherwise it pushes a decremented copy of the top element and recurses. On the way back from the recursion it uses the other quotation, [*], to multiply what is now a factorial on top of the stack by the second element on the stack.</p>
1604 </blockquote>
1605 <pre><code>   0 [Base] [Recur] primrec
1606 ------------------------------
1607       Base
1608
1609          n [Base] [Recur] primrec
1610 ------------------------------------------ n &gt; 0
1611    n (n-1) [Base] [Recur] primrec Recur</code></pre>
1612 <h3 id="discussion-51">Discussion</h3>
1613 <p>Simple and useful specialization of the <a href="#genrec">genrec</a> combinator from the <a href="https://www.kevinalbrecht.com/code/joy-mirror/index.html">original Joy system</a>.</p>
1614 <h3 id="crosslinks-79">Crosslinks</h3>
1615 <p><a href="#genrec">genrec</a> <a href="#tailrec">tailrec</a></p>
1616 <hr />
1617 <h2 id="product">product</h2>
1618 <p>Function</p>
1619 <p>Just as <a href="#sum">sum</a> sums a list of numbers, this function multiplies them together.</p>
1620 <h3 id="definition-62">Definition</h3>
1621 <blockquote>
1622 <p>1 <a href="#swap">swap</a> [<a href="#mul">mul</a>] <a href="#step">step</a></p>
1623 </blockquote>
1624 <p>Or,</p>
1625 <blockquote>
1626 <p>[1] [<a href="#mul">mul</a>] <a href="#primrec">primrec</a></p>
1627 </blockquote>
1628 <hr />
1629 <h2 id="section-22">?</h2>
1630 <p>Function</p>
1631 <p>Is the item on the top of the stack &#x201C;truthy&#x201D;?</p>
1632 <h3 id="definition-63">Definition</h3>
1633 <blockquote>
1634 <p><a href="#dup">dup</a> <a href="#bool">bool</a></p>
1635 </blockquote>
1636 <h3 id="discussion-52">Discussion</h3>
1637 <p>You often want to test the truth value of an item on the stack without consuming the item.</p>
1638 <h3 id="crosslinks-80">Crosslinks</h3>
1639 <p><a href="#bool">bool</a></p>
1640 <hr />
1641 <h2 id="quoted">quoted</h2>
1642 <p>Function</p>
1643 <p>&#x201C;Quote D&#x201D; Wrap the second item on the stack in a list.</p>
1644 <pre><code>   a b quoted
1645 ----------------
1646      [a] b</code></pre>
1647 <h3 id="definition-64">Definition</h3>
1648 <blockquote>
1649 <p>[<a href="#unit">unit</a>] <a href="#dip">dip</a></p>
1650 </blockquote>
1651 <h3 id="discussion-53">Discussion</h3>
1652 <p>This comes from the original Joy stuff.</p>
1653 <h3 id="crosslinks-81">Crosslinks</h3>
1654 <p><a href="#unit">unit</a></p>
1655 <hr />
1656 <h2 id="range">range</h2>
1657 <p>Function</p>
1658 <p>Expect a number <code>n</code> on the stack and replace it with a list: <code>[(n-1)...0]</code>.</p>
1659 <h3 id="example-17">Example</h3>
1660 <pre><code>     5 range
1661 -----------------
1662    [4 3 2 1 0]
1663
1664    -5 range
1665 --------------
1666       []</code></pre>
1667 <h3 id="definition-65">Definition</h3>
1668 <blockquote>
1669 <p>[0 &lt;=] [1 - <a href="#dup">dup</a>] <a href="#anamorphism">anamorphism</a></p>
1670 </blockquote>
1671 <h3 id="discussion-54">Discussion</h3>
1672 <p>If <code>n</code> is less than 1 the resulting list is empty.</p>
1673 <h3 id="crosslinks-82">Crosslinks</h3>
1674 <p><a href="#range_to_zero">range_to_zero</a></p>
1675 <hr />
1676 <h2 id="range_to_zero">range_to_zero</h2>
1677 <p>Function</p>
1678 <p>Take a number <code>n</code> from the stack and replace it with a list <code>[0...n]</code>.</p>
1679 <h3 id="example-18">Example</h3>
1680 <pre><code>   5 range_to_zero
1681 ---------------------
1682     [0 1 2 3 4 5]</code></pre>
1683 <h3 id="definition-66">Definition</h3>
1684 <blockquote>
1685 <p><a href="#unit">unit</a> [<a href="#down_to_zero">down_to_zero</a>] <a href="#infra">infra</a></p>
1686 </blockquote>
1687 <h3 id="discussion-55">Discussion</h3>
1688 <p>Note that the order is reversed compared to <a href="#range">range</a>.</p>
1689 <h3 id="crosslinks-83">Crosslinks</h3>
1690 <p><a href="#down_to_zero">down_to_zero</a> <a href="#range">range</a></p>
1691 <hr />
1692 <h2 id="reco">reco</h2>
1693 <p>Function</p>
1694 <p>Replace the first item in a list with the item under it.</p>
1695 <pre><code>   a [b ...] reco
1696 --------------------
1697      [a ...]</code></pre>
1698 <h3 id="definition-67">Definition</h3>
1699 <blockquote>
1700 <p><a href="#rest">rest</a> <a href="#cons">cons</a></p>
1701 </blockquote>
1702 <h3 id="crosslinks-84">Crosslinks</h3>
1703 <p><a href="#codireco">codireco</a> <a href="#make_generator">make_generator</a></p>
1704 <hr />
1705 <h2 id="remainder">remainder</h2>
1706 <p>See <a href="#mod">mod</a>.</p>
1707 <hr />
1708 <h2 id="rem">rem</h2>
1709 <p>See <a href="#mod">mod</a>.</p>
1710 <hr />
1711 <h2 id="remove">remove</h2>
1712 <p>Function</p>
1713 <p>Expects an item on the stack and a quote under it and removes that item from the the quote. The item is only removed once. If the list is empty or the item isn&#x2019;t in the list then the list is unchanged.</p>
1714 <pre><code>   [1 2 3 1] 1 remove
1715 ------------------------
1716         [2 3 1]</code></pre>
1717 <h3 id="definition-68">Definition</h3>
1718 <p>See the <a href="https://osdn.net/projects/joypy/scm/git/Thun/blobs/master/docs/notebooks/Remove-Function.ipynb">&#x201C;Remove Function&#x201D; notebook</a>.</p>
1719 <hr />
1720 <h2 id="rest">rest</h2>
1721 <p>Basis Function</p>
1722 <pre><code>   [a ...] rest
1723 ------------------
1724       [...]</code></pre>
1725 <h3 id="crosslinks-85">Crosslinks</h3>
1726 <p><a href="#first">first</a> <a href="#uncons">uncons</a></p>
1727 <hr />
1728 <h2 id="reverse">reverse</h2>
1729 <p>Function</p>
1730 <p>Reverse the list on the top of the stack.</p>
1731 <h3 id="example-19">Example</h3>
1732 <pre><code>   [1 2 3] reverse
1733 ---------------------
1734        [3 2 1]</code></pre>
1735 <h3 id="definition-69">Definition</h3>
1736 <blockquote>
1737 <p><a href="#section-15">&lt;{}</a> <a href="#shunt">shunt</a></p>
1738 </blockquote>
1739 <hr />
1740 <h2 id="rolldown">rolldown</h2>
1741 <p>Function</p>
1742 <pre><code>   a b c rolldown
1743 --------------------
1744        b c a</code></pre>
1745 <h3 id="definition-70">Definition</h3>
1746 <blockquote>
1747 <p><a href="#swapd">swapd</a> <a href="#swap">swap</a></p>
1748 </blockquote>
1749 <h3 id="crosslinks-86">Crosslinks</h3>
1750 <p><a href="#rollup">rollup</a></p>
1751 <hr />
1752 <h2 id="roll">roll&gt;</h2>
1753 <p>See <a href="#rollup">rollup</a>.</p>
1754 <hr />
1755 <h2 id="roll-1">roll&lt;</h2>
1756 <p>See <a href="#rolldown">rolldown</a>.</p>
1757 <hr />
1758 <h2 id="rollup">rollup</h2>
1759 <p>Function</p>
1760 <pre><code>   a b c rollup
1761 ------------------
1762       c a b</code></pre>
1763 <h3 id="definition-71">Definition</h3>
1764 <blockquote>
1765 <p><a href="#swap">swap</a> <a href="#swapd">swapd</a></p>
1766 </blockquote>
1767 <h3 id="crosslinks-87">Crosslinks</h3>
1768 <p><a href="#rolldown">rolldown</a></p>
1769 <hr />
1770 <h2 id="round">round</h2>
1771 <p>Function</p>
1772 <p>Round a number to a given precision in decimal digits.</p>
1773 <h3 id="discussion-56">Discussion</h3>
1774 <p>Another one that won&#x2019;t make sense until the &#x201C;numeric tower&#x201D; is nailed down.</p>
1775 <hr />
1776 <h2 id="rrest">rrest</h2>
1777 <p>Function</p>
1778 <pre><code>   [a b ...] rrest
1779 ---------------------
1780         [...]</code></pre>
1781 <h3 id="definition-72">Definition</h3>
1782 <blockquote>
1783 <p><a href="#rest">rest</a> <a href="#rest">rest</a></p>
1784 </blockquote>
1785 <h3 id="crosslinks-88">Crosslinks</h3>
1786 <p><a href="#rest">rest</a></p>
1787 <hr />
1788 <h2 id="rshift">rshift</h2>
1789 <p>Basis Function</p>
1790 <p><a href="https://en.wikipedia.org/wiki/Logical_shift">Logical Right-Shift</a></p>
1791 <pre><code>   a n rshift
1792 ----------------
1793      (a&#x2215;2&#x207F;)</code></pre>
1794 <h3 id="crosslinks-89">Crosslinks</h3>
1795 <p><a href="#lshift">lshift</a></p>
1796 <hr />
1797 <h2 id="run">run</h2>
1798 <p>Function</p>
1799 <p>Run a quoted program in a list.</p>
1800 <h3 id="example-20">Example</h3>
1801 <pre><code>   [1 2 +] run
1802 -----------------
1803        [3]</code></pre>
1804 <h3 id="definition-73">Definition</h3>
1805 <blockquote>
1806 <p><a href="#section-15">&lt;{}</a> <a href="#infra">infra</a></p>
1807 </blockquote>
1808 <hr />
1809 <h2 id="second">second</h2>
1810 <p>Function</p>
1811 <pre><code>   [a b ...] second
1812 ----------------------
1813           b</code></pre>
1814 <h3 id="definition-74">Definition</h3>
1815 <blockquote>
1816 <p><a href="#rest">rest</a> <a href="#first">first</a></p>
1817 </blockquote>
1818 <h3 id="crosslinks-90">Crosslinks</h3>
1819 <p><a href="#first">first</a> <a href="#third">third</a> <a href="#fourth">fourth</a></p>
1820 <hr />
1821 <h2 id="select">select</h2>
1822 <p>Basis Function</p>
1823 <p>Use a Boolean value to select one of two items from a sequence. :</p>
1824 <pre><code>   [a b] false select
1825 ------------------------
1826            a
1827
1828    [a b] true select
1829 -----------------------
1830            b</code></pre>
1831 <h3 id="discussion-57">Discussion</h3>
1832 <p>The sequence can contain more than two items but not fewer.</p>
1833 <h3 id="crosslinks-91">Crosslinks</h3>
1834 <p><a href="#choice">choice</a></p>
1835 <hr />
1836 <h2 id="sharing">sharing</h2>
1837 <p>Function</p>
1838 <p>Print redistribution information.</p>
1839 <h3 id="discussion-58">Discussion</h3>
1840 <p>Mathematically this is a form of <a href="#id">id</a>, but it has the side-effect of printing out the GPL notice.</p>
1841 <h3 id="crosslinks-92">Crosslinks</h3>
1842 <p><a href="#warranty">warranty</a></p>
1843 <hr />
1844 <h2 id="shift">shift</h2>
1845 <p>Function</p>
1846 <p>Move the top item from one list to another.</p>
1847 <h3 id="example-21">Example</h3>
1848 <pre><code>   [x y z] [a b c] shift
1849 ---------------------------
1850       [a x y z] [b c]</code></pre>
1851 <h3 id="definition-75">Definition</h3>
1852 <blockquote>
1853 <p><a href="#uncons">uncons</a> [<a href="#swons">swons</a>] <a href="#dip">dip</a></p>
1854 </blockquote>
1855 <h3 id="crosslinks-93">Crosslinks</h3>
1856 <p><a href="#shunt">shunt</a></p>
1857 <hr />
1858 <h2 id="shunt">shunt</h2>
1859 <p>Function</p>
1860 <p>Like <a href="#concat">concat</a> but <a href="#reverse">reverse</a> the top list into the second.</p>
1861 <h3 id="example-22">Example</h3>
1862 <pre><code>   [a b c] [d e f] shunt
1863 ---------------------------
1864        [f e d a b c] </code></pre>
1865 <h3 id="definition-76">Definition</h3>
1866 <blockquote>
1867 <p>[<a href="#swons">swons</a>] <a href="#step">step</a></p>
1868 </blockquote>
1869 <h3 id="discussion-59">Discussion</h3>
1870 <p>This is more efficient than <a href="#concat">concat</a> so prefer it if you don&#x2019;t need to preserve order.</p>
1871 <h3 id="crosslinks-94">Crosslinks</h3>
1872 <p><a href="#concat">concat</a> <a href="#reverse">reverse</a> <a href="#shift">shift</a></p>
1873 <hr />
1874 <h2 id="size">size</h2>
1875 <p>Function</p>
1876 <p>Replace a list with its size.</p>
1877 <h3 id="example-23">Example</h3>
1878 <pre><code>   [23 [cats] 4] size
1879 ------------------------
1880            3</code></pre>
1881 <h3 id="definition-77">Definition</h3>
1882 <blockquote>
1883 <p>[<a href="#pop">pop</a> <a href="#section-21">++</a>] <a href="#step_zero">step_zero</a></p>
1884 </blockquote>
1885 <hr />
1886 <h2 id="floor-1">/floor</h2>
1887 <p>See <a href="#floordiv">floordiv</a>.</p>
1888 <hr />
1889 <h2 id="section-23">/</h2>
1890 <p>See <a href="#floordiv">floordiv</a>.</p>
1891 <hr />
1892 <h2 id="section-24">//</h2>
1893 <p>See <a href="#floordiv">floordiv</a>.</p>
1894 <hr />
1895 <h2 id="sort">sort</h2>
1896 <p>Function</p>
1897 <p>Given a list return it sorted.</p>
1898 <h3 id="example-24">Example</h3>
1899 <pre><code>   [4 2 5 7 1] sort
1900 ----------------------
1901       [1 2 4 5 7]</code></pre>
1902 <hr />
1903 <h2 id="spiral_next">spiral_next</h2>
1904 <p>Function</p>
1905 <p>Example code.</p>
1906 <h3 id="discussion-60">Discussion</h3>
1907 <p>See the <a href="https://joypy.osdn.io/notebooks/Square_Spiral.html">&#x201C;Square Spiral Example Joy Code&#x201D; notebook</a>.</p>
1908 <hr />
1909 <h2 id="split_at">split_at</h2>
1910 <p>Function</p>
1911 <p>Split a list (second on the stack) at the position given by the number on the top of the stack.</p>
1912 <h3 id="example-25">Example</h3>
1913 <pre><code>   [1 2 3 4 5 6 7] 4 split_at
1914 --------------------------------
1915        [5 6 7] [4 3 2 1]</code></pre>
1916 <h3 id="definition-78">Definition</h3>
1917 <blockquote>
1918 <p>[<a href="#drop">drop</a>] [<a href="#take">take</a>] <a href="#clop">clop</a></p>
1919 </blockquote>
1920 <h3 id="discussion-61">Discussion</h3>
1921 <p>Take a list and a number <code>n</code> from the stack, take <code>n</code> items from the top of the list and <a href="#shunt">shunt</a> them onto a new list that replaces the number <code>n</code> on the top of the stack.</p>
1922 <h3 id="crosslinks-95">Crosslinks</h3>
1923 <p><a href="#split_list">split_list</a></p>
1924 <hr />
1925 <h2 id="split_list">split_list</h2>
1926 <p>Function</p>
1927 <p>Split a list (second on the stack) at the position given by the number on the top of the stack such that <a href="#concat">concat</a> would reconstruct the original list.</p>
1928 <pre><code>   [1 2 3 4 5 6 7] 4 split_list
1929 ----------------------------------
1930         [1 2 3 4] [5 6 7]</code></pre>
1931 <h3 id="definition-79">Definition</h3>
1932 <blockquote>
1933 <p>[<a href="#take">take</a> <a href="#reverse">reverse</a>] [<a href="#drop">drop</a>] <a href="#clop">clop</a></p>
1934 </blockquote>
1935 <h3 id="discussion-62">Discussion</h3>
1936 <p>Compare with <a href="#split_at">split_at</a>. This function does extra work to ensure that <a href="#concat">concat</a> would reconstruct the original list.</p>
1937 <h3 id="crosslinks-96">Crosslinks</h3>
1938 <p><a href="#split_at">split_at</a></p>
1939 <hr />
1940 <h2 id="sqr">sqr</h2>
1941 <p>Function</p>
1942 <p>Square the number on the top of the stack.</p>
1943 <pre><code>   n  sqr
1944 ------------
1945      n&#xB2;</code></pre>
1946 <h3 id="definition-80">Definition</h3>
1947 <blockquote>
1948 <p><a href="#dup">dup</a> <a href="#mul">mul</a></p>
1949 </blockquote>
1950 <hr />
1951 <h2 id="sqrt">sqrt</h2>
1952 <p>Basis Function Combinator</p>
1953 <p>Return the square root of the number a. Negative numbers return complex roots.</p>
1954 <h3 id="discussion-63">Discussion</h3>
1955 <p>Another &#x201C;numeric tower&#x201D; hatch&#x2026;</p>
1956 <hr />
1957 <h2 id="stackd">stackd</h2>
1958 <p>Function</p>
1959 <p>Grab the stack under the top item and put it onto the stack.</p>
1960 <h3 id="example-26">Example</h3>
1961 <pre><code>   ... 1 2 3 stackd
1962 ------------------------
1963   ... 1 2 [2 1 ...] 3</code></pre>
1964 <h3 id="definition-81">Definition</h3>
1965 <blockquote>
1966 <p>[<a href="#stack">stack</a>] <a href="#dip">dip</a></p>
1967 </blockquote>
1968 <hr />
1969 <h2 id="stack">stack</h2>
1970 <p>Function</p>
1971 <p>Put the stack onto the stack.</p>
1972 <pre><code>      ... c b a stack
1973 ---------------------------
1974    ... c b a [a b c ...]</code></pre>
1975 <h3 id="definition-82">Definition</h3>
1976 <blockquote>
1977 <p>[] <a href="#swaack">swaack</a> <a href="#dup">dup</a> <a href="#swaack">swaack</a> <a href="#first">first</a></p>
1978 </blockquote>
1979 <h3 id="discussion-64">Discussion</h3>
1980 <p>This function forms a pair with [unstack], and together they form the complement to the &#x201C;destructive&#x201D; pair <a href="#enstacken">enstacken</a> and <a href="#disenstacken">disenstacken</a>.</p>
1981 <h3 id="crosslinks-97">Crosslinks</h3>
1982 <p>[unstack] <a href="#enstacken">enstacken</a> <a href="#disenstacken">disenstacken</a></p>
1983 <hr />
1984 <h2 id="step">step</h2>
1985 <p>Combinator</p>
1986 <p>Run a quoted program on each item in a sequence.</p>
1987 <pre><code>   ... [] [Q] step
1988 ---------------------
1989          ...
1990
1991
1992    ... [a] [Q] step
1993 ----------------------
1994       ... a Q
1995
1996
1997    ... [a b c] [Q] . step
1998 ----------------------------------------
1999              ... a . Q [b c] [Q] step</code></pre>
2000 <h3 id="discussion-65">Discussion</h3>
2001 <p>See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.</p>
2002 <h3 id="crosslinks-98">Crosslinks</h3>
2003 <p><a href="#step_zero">step_zero</a></p>
2004 <hr />
2005 <h2 id="step_zero">step_zero</h2>
2006 <p>Combinator</p>
2007 <p>Like <a href="#step">step</a> but with 0 as the initial value.</p>
2008 <pre><code>   [...] [F] step_zero
2009 -------------------------
2010      0 [...] [F] step</code></pre>
2011 <h3 id="definition-83">Definition</h3>
2012 <blockquote>
2013 <p>0 <a href="#roll">roll&gt;</a> <a href="#step">step</a></p>
2014 </blockquote>
2015 <h3 id="discussion-66">Discussion</h3>
2016 <p><a href="#size">size</a> and <a href="#sum">sum</a> can both be defined in terms of this specialization of <a href="#step">step</a>.</p>
2017 <h3 id="crosslinks-99">Crosslinks</h3>
2018 <p><a href="#step">step</a></p>
2019 <hr />
2020 <h2 id="stuncons">stuncons</h2>
2021 <p>Function</p>
2022 <p>Take the <a href="#stack">stack</a> and <a href="#uncons">uncons</a> the top item.</p>
2023 <h3 id="example-27">Example</h3>
2024 <pre><code>   1 2 3 stuncons
2025 --------------------
2026    1 2 3 3 [2 1]</code></pre>
2027 <h3 id="definition-84">Definition</h3>
2028 <blockquote>
2029 <p><a href="#stack">stack</a> <a href="#uncons">uncons</a></p>
2030 </blockquote>
2031 <hr />
2032 <h2 id="stununcons">stununcons</h2>
2033 <p>Function</p>
2034 <p>Take the <a href="#stack">stack</a> and <a href="#uncons">uncons</a> the top two items.</p>
2035 <h3 id="example-28">Example</h3>
2036 <pre><code>   1 2 3 stununcons
2037 ----------------------
2038     1 2 3 3 2 [1]</code></pre>
2039 <h3 id="definition-85">Definition</h3>
2040 <blockquote>
2041 <p><a href="#stack">stack</a> <a href="#uncons">uncons</a> <a href="#uncons">uncons</a></p>
2042 </blockquote>
2043 <h3 id="crosslinks-100">Crosslinks</h3>
2044 <p><a href="#stuncons">stuncons</a></p>
2045 <hr />
2046 <h2 id="sub">sub</h2>
2047 <p>Basis Function</p>
2048 <p>Subtract the number on the top of the stack from the number below it.</p>
2049 <pre><code>   a b sub
2050 -------------
2051     (a-b)</code></pre>
2052 <h3 id="crosslinks-101">Crosslinks</h3>
2053 <p><a href="#add">add</a></p>
2054 <hr />
2055 <h2 id="succ">succ</h2>
2056 <p>Function</p>
2057 <p>Successor. Increment TOS.</p>
2058 <h3 id="definition-86">Definition</h3>
2059 <blockquote>
2060 <p>1 +</p>
2061 </blockquote>
2062 <h3 id="crosslinks-102">Crosslinks</h3>
2063 <p><a href="#pred">pred</a></p>
2064 <hr />
2065 <h2 id="sum">sum</h2>
2066 <p>Combinator</p>
2067 <p>Given a quoted sequence of numbers return the sum.</p>
2068 <h3 id="example-29">Example</h3>
2069 <pre><code>   [1 2 3 4 5] sum
2070 ---------------------
2071          15</code></pre>
2072 <h3 id="definition-87">Definition</h3>
2073 <blockquote>
2074 <p>[+] <a href="#step_zero">step_zero</a></p>
2075 </blockquote>
2076 <h3 id="crosslinks-103">Crosslinks</h3>
2077 <p><a href="#size">size</a></p>
2078 <hr />
2079 <h2 id="swaack">swaack</h2>
2080 <p>Basis Function</p>
2081 <p>Swap stack. Take a list from the top of the stack, replace the stack with the list, and put the old stack onto it.</p>
2082 <h3 id="example-30">Example</h3>
2083 <pre><code>   1 2 3 [4 5 6] swaack
2084 --------------------------
2085    6 5 4 [3 2 1]</code></pre>
2086 <h3 id="discussion-67">Discussion</h3>
2087 <p>This function works as a kind of &#x201C;context switch&#x201D;. It&#x2019;s used in the definition of <a href="#infra">infra</a>.</p>
2088 <h3 id="crosslinks-104">Crosslinks</h3>
2089 <p><a href="#infra">infra</a></p>
2090 <hr />
2091 <h2 id="swapd">swapd</h2>
2092 <p>Function</p>
2093 <p>Swap the second and third items on the stack.</p>
2094 <pre><code>   a b c swapd
2095 -----------------
2096       b a c</code></pre>
2097 <h3 id="definition-88">Definition</h3>
2098 <blockquote>
2099 <p>[<a href="#swap">swap</a>] <a href="#dip">dip</a></p>
2100 </blockquote>
2101 <h3 id="crosslinks-105">Crosslinks</h3>
2102 <p><a href="#over">over</a> <a href="#tuck">tuck</a></p>
2103 <hr />
2104 <h2 id="swap">swap</h2>
2105 <p>Basis Function</p>
2106 <p>Swap the top two items on the stack.</p>
2107 <pre><code>   a b swap
2108 --------------
2109      b a</code></pre>
2110 <h3 id="crosslinks-106">Crosslinks</h3>
2111 <p><a href="#swapd">swapd</a></p>
2112 <hr />
2113 <h2 id="swoncat">swoncat</h2>
2114 <p>Function</p>
2115 <p><a href="#concat">concat</a> two lists, but <a href="#swap">swap</a> the lists first.</p>
2116 <h3 id="definition-89">Definition</h3>
2117 <blockquote>
2118 <p><a href="#swap">swap</a> <a href="#concat">concat</a></p>
2119 </blockquote>
2120 <h3 id="crosslinks-107">Crosslinks</h3>
2121 <p><a href="#concat">concat</a></p>
2122 <hr />
2123 <h2 id="swons">swons</h2>
2124 <p>Function</p>
2125 <p>Like <a href="#cons">cons</a> but <a href="#swap">swap</a> the item and list.</p>
2126 <pre><code>   [...] a swons
2127 -------------------
2128       [a ...]</code></pre>
2129 <h3 id="definition-90">Definition</h3>
2130 <blockquote>
2131 <p><a href="#swap">swap</a> <a href="#cons">cons</a></p>
2132 </blockquote>
2133 <hr />
2134 <h2 id="tailrec">tailrec</h2>
2135 <p>Combinator</p>
2136 <p>A specialization of the <a href="#genrec">genrec</a> combinator.</p>
2137 <h3 id="definition-91">Definition</h3>
2138 <blockquote>
2139 <p>[<a href="#i">i</a>] <a href="#genrec">genrec</a></p>
2140 </blockquote>
2141 <h3 id="discussion-68">Discussion</h3>
2142 <p>Some recursive functions do not need to store additional data or pending actions per-call. These are called <a href="https://en.wikipedia.org/wiki/Tail_recursive">&#x201C;tail recursive&#x201D; functions</a>. In Joy, they appear as <a href="#genrec">genrec</a> definitions that have <a href="#i">i</a> for the second half of their recursive branch.</p>
2143 <p>See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.</p>
2144 <h3 id="crosslinks-108">Crosslinks</h3>
2145 <p><a href="#genrec">genrec</a></p>
2146 <hr />
2147 <h2 id="take">take</h2>
2148 <p>Function</p>
2149 <p>Expects an integer <code>n</code> and a list on the stack and replace them with a list with just the top <code>n</code> items in reverse order.</p>
2150 <pre><code>   [a b c d] 2 take
2151 ----------------------
2152         [b a]</code></pre>
2153 <h3 id="definition-92">Definition</h3>
2154 <blockquote>
2155 <p><a href="#section-16">&lt;&lt;{}</a> [<a href="#shift">shift</a>] <a href="#times">times</a> <a href="#pop">pop</a></p>
2156 </blockquote>
2157 <hr />
2158 <h2 id="ternary">ternary</h2>
2159 <p>Combinator</p>
2160 <p>Run a quoted program using exactly three stack values and leave the first item of the result on the stack.</p>
2161 <pre><code>   ... z y x [P] ternary
2162 -------------------------
2163          ... a</code></pre>
2164 <h3 id="definition-93">Definition</h3>
2165 <blockquote>
2166 <p><a href="#binary">binary</a> <a href="#popd">popd</a></p>
2167 </blockquote>
2168 <h3 id="discussion-69">Discussion</h3>
2169 <p>Runs any other quoted function and returns its first result while consuming exactly three items from the stack.</p>
2170 <h3 id="crosslinks-109">Crosslinks</h3>
2171 <p><a href="#binary">binary</a> <a href="#nullary">nullary</a> <a href="#unary">unary</a></p>
2172 <hr />
2173 <h2 id="third">third</h2>
2174 <p>Function</p>
2175 <pre><code>   [a b c ...] third
2176 -----------------------
2177            c</code></pre>
2178 <h3 id="definition-94">Definition</h3>
2179 <blockquote>
2180 <p><a href="#rest">rest</a> <a href="#second">second</a></p>
2181 </blockquote>
2182 <h3 id="crosslinks-110">Crosslinks</h3>
2183 <p><a href="#first">first</a> <a href="#second">second</a> <a href="#fourth">fourth</a> <a href="#rest">rest</a></p>
2184 <hr />
2185 <h2 id="times">times</h2>
2186 <p>Combinator</p>
2187 <p>Expect a quoted program and an integer <code>n</code> on the stack and do the program <code>n</code> times.</p>
2188 <pre><code>   ... n [Q] . times
2189 -----------------------  w/ n &lt;= 0
2190          ... .
2191
2192    ... 1 [Q] . times
2193 -----------------------
2194          ... . Q
2195
2196    ... n [Q] . times
2197 -------------------------------------  w/ n &gt; 1
2198          ... . Q (n-1) [Q] times</code></pre>
2199 <h3 id="definition-95">Definition</h3>
2200 <blockquote>
2201 <p>[-- dip] cons [swap] infra [0 &gt;] swap while pop :</p>
2202 </blockquote>
2203 <h3 id="discussion-70">Discussion</h3>
2204 <p>This works by building a little <a href="#while">while</a> program and running it:</p>
2205 <pre><code>                 1 3 [++] &#x2022; [-- dip] cons [swap] infra [0 &gt;] swap while pop                                                                                                                 
2206         1 3 [++] [-- dip] &#x2022; cons [swap] infra [0 &gt;] swap while pop                                                                                                                          
2207         1 3 [[++] -- dip] &#x2022; [swap] infra [0 &gt;] swap while pop                                                                                                                               
2208  1 3 [[++] -- dip] [swap] &#x2022; infra [0 &gt;] swap while pop                                                                                                                                      
2209               dip -- [++] &#x2022; swap [3 1] swaack [0 &gt;] swap while pop                                                                                                                          
2210               dip [++] -- &#x2022; [3 1] swaack [0 &gt;] swap while pop                                                                                                                               
2211         dip [++] -- [3 1] &#x2022; swaack [0 &gt;] swap while pop                                                                                                                                     
2212         1 3 [-- [++] dip] &#x2022; [0 &gt;] swap while pop                                                                                                                                            
2213   1 3 [-- [++] dip] [0 &gt;] &#x2022; swap while pop                                                                                                                                                  
2214   1 3 [0 &gt;] [-- [++] dip] &#x2022; while pop                                                                                                                                                       </code></pre>
2215 <p>This is a common pattern in Joy. You accept some parameters from the stack which typically include qouted programs and use them to build another program which does the actual work. This is kind of like macros in Lisp, or preprocessor directives in C.</p>
2216 <hr />
2217 <h2 id="truthy">truthy</h2>
2218 <p>See <a href="#bool">bool</a>.</p>
2219 <hr />
2220 <h2 id="tuck">tuck</h2>
2221 <p>Function</p>
2222 <p><a href="#dup">dup</a> the item on the top of the stack under the second item on the stack.</p>
2223 <pre><code>   a b tuck
2224 --------------
2225     b a b</code></pre>
2226 <h3 id="definition-96">Definition</h3>
2227 <blockquote>
2228 <p><a href="#dup">dup</a> [<a href="#swap">swap</a>] <a href="#dip">dip</a></p>
2229 </blockquote>
2230 <h3 id="crosslinks-111">Crosslinks</h3>
2231 <p><a href="#over">over</a></p>
2232 <hr />
2233 <h2 id="unary">unary</h2>
2234 <p>(Combinator)</p>
2235 <p>Run a quoted program using exactly one stack value and leave the first item of the result on the stack.</p>
2236 <pre><code>   ... x [P] unary
2237 ---------------------
2238        ... a</code></pre>
2239 <h3 id="definition-97">Definition</h3>
2240 <blockquote>
2241 <p><a href="#nullary">nullary</a> <a href="#popd">popd</a></p>
2242 </blockquote>
2243 <h3 id="discussion-71">Discussion</h3>
2244 <p>Runs any other quoted function and returns its first result while consuming exactly one item from the stack.</p>
2245 <h3 id="crosslinks-112">Crosslinks</h3>
2246 <p><a href="#binary">binary</a> <a href="#nullary">nullary</a> <a href="#ternary">ternary</a></p>
2247 <hr />
2248 <h2 id="uncons">uncons</h2>
2249 <p>Basis Function</p>
2250 <p>Removes an item from a list and leaves it on the stack under the rest of the list. You cannot <code>uncons</code> an item from an empty list.</p>
2251 <pre><code>   [a ...] uncons
2252 --------------------
2253       a [...]</code></pre>
2254 <h3 id="discussion-72">Discussion</h3>
2255 <p>This is the inverse of <a href="#cons">cons</a>.</p>
2256 <h3 id="crosslinks-113">Crosslinks</h3>
2257 <p><a href="#cons">cons</a></p>
2258 <hr />
2259 <h2 id="unique">unique</h2>
2260 <p>Function</p>
2261 <p>Given a list remove duplicate items.</p>
2262 <hr />
2263 <h2 id="unit">unit</h2>
2264 <p>Function</p>
2265 <pre><code>   a unit
2266 ------------
2267     [a]</code></pre>
2268 <h3 id="definition-98">Definition</h3>
2269 <blockquote>
2270 <p>[] <a href="#cons">cons</a></p>
2271 </blockquote>
2272 <hr />
2273 <h2 id="unquoted">unquoted</h2>
2274 <p>Combinator</p>
2275 <p>Unquote (using <a href="#i">i</a>) the list that is second on the stack.</p>
2276 <h3 id="example-31">Example</h3>
2277 <pre><code>   1 2 [3 4] 5 unquoted
2278 --------------------------
2279          1 2 3 4 5</code></pre>
2280 <h3 id="definition-99">Definition</h3>
2281 <blockquote>
2282 <p>[<a href="#i">i</a>] <a href="#dip">dip</a></p>
2283 </blockquote>
2284 <h3 id="crosslinks-114">Crosslinks</h3>
2285 <p><a href="#unit">unit</a></p>
2286 <hr />
2287 <h2 id="unswons">unswons</h2>
2288 <p>Function</p>
2289 <pre><code>   [a ...] unswons
2290 ---------------------
2291        [...] a</code></pre>
2292 <h3 id="definition-100">Definition</h3>
2293 <blockquote>
2294 <p><a href="#uncons">uncons</a> <a href="#swap">swap</a></p>
2295 </blockquote>
2296 <hr />
2297 <h2 id="section-25">||</h2>
2298 <p>Combinator</p>
2299 <p>Short-circuiting Boolean OR</p>
2300 <h3 id="definition-101">Definition</h3>
2301 <blockquote>
2302 <p><a href="#nulco">nulco</a> [<a href="#nullary">nullary</a>] <a href="#dip">dip</a> [true] <a href="#branch">branch</a></p>
2303 </blockquote>
2304 <h3 id="discussion-73">Discussion</h3>
2305 <p>Accept two quoted programs, run the first and expect a Boolean value, if it&#x2019;s <code>false</code> pop it and run the second program (which should also return a Boolean value) otherwise pop the second program (leaving <code>true</code> on the stack.)</p>
2306 <pre><code>   [A] [B] ||
2307 ---------------- A -&gt; false
2308         B
2309
2310
2311    [A] [B] ||
2312 ---------------- A -&gt; true
2313       true</code></pre>
2314 <h3 id="crosslinks-115">Crosslinks</h3>
2315 <p><a href="#section-1">&amp;&amp;</a></p>
2316 <hr />
2317 <h2 id="void">void</h2>
2318 <p>Basis Function</p>
2319 <p>True if the form on TOS is void otherwise False.</p>
2320 <h3 id="discussion-74">Discussion</h3>
2321 <p>A form is any Joy expression composed solely of lists. This represents a binary Boolean logical formula in the arithmetic of the &#x201C;Laws of Form&#x201D;, see <a href="http://www.markability.net/">The Markable Mark</a></p>
2322 <hr />
2323 <h2 id="warranty">warranty</h2>
2324 <p>Basis Function</p>
2325 <p>Print warranty information.</p>
2326 <hr />
2327 <h2 id="while">while</h2>
2328 <p>Combinator</p>
2329 <p>A specialization of <a href="#loop">loop</a> that accepts a quoted predicate program <code>P</code> and runs it <a href="#nullary">nullary</a>.</p>
2330 <pre><code>   [P] [F] while
2331 ------------------- P -&gt; false
2332
2333     [P] [F] while
2334 --------------------- P -&gt; true
2335    F [P] [F] while</code></pre>
2336 <h3 id="definition-102">Definition</h3>
2337 <blockquote>
2338 <p><a href="#swap">swap</a> <a href="#nulco">nulco</a> <a href="#dupdipd">dupdipd</a> <a href="#concat">concat</a> <a href="#loop">loop</a></p>
2339 </blockquote>
2340 <h3 id="crosslinks-116">Crosslinks</h3>
2341 <p><a href="#loop">loop</a></p>
2342 <hr />
2343 <h2 id="words">words</h2>
2344 <p>Basis Function</p>
2345 <p>Print all the words in alphabetical order.</p>
2346 <h3 id="discussion-75">Discussion</h3>
2347 <p>Mathematically this is a form of <a href="#id">id</a>.</p>
2348 <h3 id="crosslinks-117">Crosslinks</h3>
2349 <p><a href="#help">help</a></p>
2350 <hr />
2351 <h2 id="x">x</h2>
2352 <p>Combinator</p>
2353 <p>Take a quoted function <code>F</code> and run it with itself as the first item on the stack.</p>
2354 <pre><code>   [F] x
2355 -----------
2356    [F] F</code></pre>
2357 <h3 id="definition-103">Definition</h3>
2358 <pre><code>dup i</code></pre>
2359 <h3 id="discussion-76">Discussion</h3>
2360 <p>The simplest recursive pattern.</p>
2361 <p>See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>. as well as <a href="https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html">Recursion Theory and Joy</a> by Manfred von</p>
2362 <hr />
2363 <h2 id="xor">xor</h2>
2364 <p>Basis Function</p>
2365 <p>Logical bit-wise eXclusive OR.</p>
2366 <h3 id="crosslinks-118">Crosslinks</h3>
2367 <p><a href="#and">and</a> <a href="#or">or</a></p>
2368 <hr />
2369 <h2 id="zip">zip</h2>
2370 <p>Function</p>
2371 <p>Replace the two lists on the top of the stack with a list of the pairs from each list. The smallest list sets the length of the result list.</p>
2372 <h3 id="example-32">Example</h3>
2373 <pre><code>   [1 2 3] [4 5 6] zip
2374 -------------------------
2375    [[4 1] [5 2] [6 3]]</code></pre>
2376 </body>
2377 </html>