Thun/docs/html/FuncRef.html

967 lines
158 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html><head><meta charset="utf-8"><title>Thun Function Reference</title><link rel="stylesheet" href="/css/font/fonts.css"><link rel="stylesheet" href="/css/func_ref.css"></head><body><h1>Thun Function Reference</h1><a href="/">Home</a><p>Version -10.0.0</p><p>Each function, combinator, or definition should be documented here.</p><ul><li><a href="#e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a></li> <li><a href="#c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2">!=</a></li> <li><a href="#bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a></li> <li><a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a></li> <li><a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a></li> <li><a href="#cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a></li> <li><a href="#3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a></li> <li><a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a></li> <li><a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a></li> <li><a href="#c1773bc23efd62ebecd69d025d1561e8fc864159ba2fc48177060e4b376112b5">/\</a></li> <li><a href="#dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72">&lt;</a></li> <li><a href="#4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e">&lt;&lt;</a></li> <li><a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108">&lt;&lt;{}</a></li> <li><a href="#b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866">&lt;=</a></li> <li><a href="#24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64">&lt;&gt;</a></li> <li><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a></li> <li><a href="#380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3">=</a></li> <li><a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">&gt;</a></li> <li><a href="#92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f">&gt;=</a></li> <li><a href="#0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44">&gt;&gt;</a></li> <li><a href="#8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1">?</a></li> <li><a href="#7a063e4cb04c8b9d833cec4caea5b184720eba13daf25139c99a355a266d921f">\/</a></li> <li><a href="#abs">abs</a></li> <li><a href="#add">add</a></li> <li><a href="#anamorphism">anamorphism</a></li> <li><a href="#and">and</a></li> <li><a href="#172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094">app1</a></li> <li><a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a">app2</a></li> <li><a href="#697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868">app3</a></li> <li><a href="#appN">appN</a></li> <li><a href="#at">at</a></li> <li><a href="#average">average</a></li> <li><a href="#b">b</a></li> <li><a href="#binary">binary</a></li> <li><a href="#bool">bool</a></li> <li><a href="#branch">branch</a></li> <li><a href="#ccccons">ccccons</a></li> <li><a href="#ccons">ccons</a></li> <li><a href="#choice">choice</a></li> <li><a href="#clear">clear</a></li> <li><a href="#cleave">cleave</a></li> <li><a href="#clop">clop</a></li> <li><a href="#cmp">cmp</a></li> <li><a href="#codi">codi</a></li> <li><a href="#codireco">codireco</a></li> <li><a href="#concat">concat</a></li> <li><a href="#cond">cond</a></li> <li><a href="#cons">cons</a></li> <li><a href="#dinfrirst">dinfrirst</a></li> <li><a href="#dip">dip</a></li> <li><a href="#dipd">dipd</a></li> <li><a href="#dipdd">dipdd</a></li> <li><a href="#dipddd">dipddd</a></li> <li><a href="#disenstacken">disenstacken</a></li> <li><a href="#div">div</a></li> <li><a href="#divmod">divmod</a></li> <li><a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d">down_to_zero</a></li> <li><a href="#drop">drop</a></li> <li><a href="#dup">dup</a></li> <li><a href="#dupd">dupd</a></li> <li><a href="#dupdd">dupdd</a></li> <li><a href="#dupdip">dupdip</a></li> <li><a href="#dupdipd">dupdipd</a></li> <li><a href="#enstacken">enstacken</a></li> <li><a href="#eq">eq</a></li> <li><a href="#first">first</a></li> <li><a href="#07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236">first_two</a></li> <li><a href="#flatten">flatten</a></li> <li><a href="#fork">fork</a></li> <li><a href="#fourth">fourth</a></li> <li><a href="#gcd">gcd</a></li> <li><a href="#ge">ge</a></li> <li><a href="#genrec">genrec</a></li> <li><a href="#getitem">getitem</a></li> <li><a href="#grabN">grabN</a></li> <li><a href="#grba">grba</a></li> <li><a href="#gt">gt</a></li> <li><a href="#help">help</a></li> <li><a href="#i">i</a></li> <li><a href="#id">id</a></li> <li><a href="#ifte">ifte</a></li> <li><a href="#ii">ii</a></li> <li><a href="#infra">infra</a></li> <li><a href="#infrst">infrst</a></li> <li><a href="#inscribe">inscribe</a></li> <li><a href="#le">le</a></li> <li><a href="#loop">loop</a></li> <li><a href="#lshift">lshift</a></li> <li><a href="#lt">lt</a></li> <li><a href="#766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d">make_generator</a></li> <li><a href="#map">map</a></li> <li><a href="#max">max</a></li> <li><a href="#min">min</a></li> <li><a href="#mod">mod</a></li> <li><a href="#modulus">modulus</a></li> <li><a href="#mul">mul</a></li> <li><a href="#neg">neg</a></li> <li><a href="#neq">neq</a></li> <li><a href="#not">not</a></li> <li><a href="#nulco">nulco</a></li> <li><a href="#null">null</a></li> <li><a href="#nullary">nullary</a></li> <li><a href="#of">of</a></li> <li><a href="#or">or</a></li> <li><a href="#over">over</a></li> <li><a href="#pam">pam</a></li> <li><a href="#pick">pick</a></li> <li><a href="#pm">pm</a></li> <li><a href="#pop">pop</a></li> <li><a href="#popd">popd</a></li> <li><a href="#popdd">popdd</a></li> <li><a href="#popop">popop</a></li> <li><a href="#popopd">popopd</a></li> <li><a href="#popopdd">popopdd</a></li> <li><a href="#popopop">popopop</a></li> <li><a href="#pow">pow</a></li> <li><a href="#pred">pred</a></li> <li><a href="#primrec">primrec</a></li> <li><a href="#product">product</a></li> <li><a href="#quoted">quoted</a></li> <li><a href="#range">range</a></li> <li><a href="#ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774">range_to_zero</a></li> <li><a href="#reco">reco</a></li> <li><a href="#rem">rem</a></li> <li><a href="#remainder">remainder</a></li> <li><a href="#remove">remove</a></li> <li><a href="#rest">rest</a></li> <li><a href="#reverse">reverse</a></li> <li><a href="#2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd">roll&lt;</a></li> <li><a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll&gt;</a></li> <li><a href="#rolldown">rolldown</a></li> <li><a href="#rollup">rollup</a></li> <li><a href="#rrest">rrest</a></li> <li><a href="#rshift">rshift</a></li> <li><a href="#run">run</a></li> <li><a href="#second">second</a></li> <li><a href="#select">select</a></li> <li><a href="#sharing">sharing</a></li> <li><a href="#shift">shift</a></li> <li><a href="#shunt">shunt</a></li> <li><a href="#size">size</a></li> <li><a href="#small">small</a></li> <li><a href="#sort">sort</a></li> <li><a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7">spiral_next</a></li> <li><a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c">split_at</a></li> <li><a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415">split_list</a></li> <li><a href="#sqr">sqr</a></li> <li><a href="#stack">stack</a></li> <li><a href="#stackd">stackd</a></li> <li><a href="#step">step</a></li> <li><a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482">step_zero</a></li> <li><a href="#stuncons">stuncons</a></li> <li><a href="#stununcons">stununcons</a></li> <li><a href="#sub">sub</a></li> <li><a href="#succ">succ</a></li> <li><a href="#sum">sum</a></li> <li><a href="#swaack">swaack</a></li> <li><a href="#swap">swap</a></li> <li><a href="#swapd">swapd</a></li> <li><a href="#swoncat">swoncat</a></li> <li><a href="#swons">swons</a></li> <li><a href="#tailrec">tailrec</a></li> <li><a href="#take">take</a></li> <li><a href="#ternary">ternary</a></li> <li><a href="#third">third</a></li> <li><a href="#times">times</a></li> <li><a href="#tuck">tuck</a></li> <li><a href="#unary">unary</a></li> <li><a href="#uncons">uncons</a></li> <li><a href="#unique">unique</a></li> <li><a href="#unit">unit</a></li> <li><a href="#unquoted">unquoted</a></li> <li><a href="#unstack">unstack</a></li> <li><a href="#unswons">unswons</a></li> <li><a href="#void">void</a></li> <li><a href="#warranty">warranty</a></li> <li><a href="#while">while</a></li> <li><a href="#words">words</a></li> <li><a href="#x">x</a></li> <li><a href="#zip">zip</a></li> </ul><hr><div><h2 id="e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf" class="func_name">!- <a href="#e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf" class="self_link"></a></h2><p></p><div class="notes"><p>Not negative.</p>
<pre><code> n !-
----------- n &lt; 0
false
n !-
---------- n &gt;= 0
true
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">0 <a href="#92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f">&gt;=</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Return a Boolean value indicating if a number is greater than or equal to
zero.</p></div></div><div class="backlinks"><h3>Used By</h3><a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2" class="func_name">!= <a href="#c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#neq">neq</a>.</p></div></div><hr><div><h2 id="bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec" class="func_name">% <a href="#bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#mod">mod</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#divmod" class="func_name">divmod</a> <a href="#mod" class="func_name">mod</a> <a href="#modulus" class="func_name">modulus</a></div></div><hr><div><h2 id="684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1" class="func_name">* <a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#mul">mul</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#lshift" class="func_name">lshift</a> <a href="#pow" class="func_name">pow</a> <a href="#product" class="func_name">product</a></div></div><hr><div><h2 id="a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b" class="func_name">+ <a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#add">add</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e" class="func_name">++</a> <a href="#pm" class="func_name">pm</a> <a href="#sum" class="func_name">sum</a></div></div><hr><div><h2 id="cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e" class="func_name">++ <a href="#cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e" class="self_link"></a></h2><p></p><div class="notes"><p>See <a href="#succ">succ</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">1 <a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#size" class="func_name">size</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112" class="func_name">- <a href="#3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#sub">sub</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c" class="func_name">--</a> <a href="#neg" class="func_name">neg</a> <a href="#pm" class="func_name">pm</a></div></div><hr><div><h2 id="d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c" class="func_name">-- <a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c" class="self_link"></a></h2><p></p><div class="notes"><p>See <a href="#pred">pred</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">1 <a href="#3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#pred" class="func_name">pred</a> <a href="#range" class="func_name">range</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a> <a href="#succ" class="func_name">succ</a></div></div><hr><div><h2 id="8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1" class="func_name">/ <a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#div">div</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#average" class="func_name">average</a> <a href="#divmod" class="func_name">divmod</a> <a href="#rshift" class="func_name">rshift</a></div></div><hr><div><h2 id="c1773bc23efd62ebecd69d025d1561e8fc864159ba2fc48177060e4b376112b5" class="func_name">/\ <a href="#c1773bc23efd62ebecd69d025d1561e8fc864159ba2fc48177060e4b376112b5" class="self_link"></a></h2><p></p><div class="notes"><p>Binary Boolean <em>and</em>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#">_isnt_two_bools</a> [<a href="#pop">pop</a> false] [] <a href="#branch">branch</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#bool" class="func_name">bool</a> <a href="#not" class="func_name">not</a> <a href="#7a063e4cb04c8b9d833cec4caea5b184720eba13daf25139c99a355a266d921f" class="func_name">\/</a></div></div><hr><div><h2 id="dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72" class="func_name">&lt; <a href="#dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#lt">lt</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#abs" class="func_name">abs</a> <a href="#" class="func_name">min-of-two</a></div></div><hr><div><h2 id="4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="func_name">&lt;&lt; <a href="#4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#lshift">lshift</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#lshift">lshift</a></div></div></div><hr><div><h2 id="c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name">&lt;&lt;{} <a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="self_link"></a></h2><p></p><div class="notes"><pre><code> ... b a &lt;{}
-----------------
... [] b a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[] <a href="#rollup">rollup</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Tuck an empty list just under the first two items on the stack.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="func_name">&lt;{}</a></div><div class="backlinks"><h3>Used By</h3><a href="#take" class="func_name">take</a></div></div><hr><div><h2 id="b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866" class="func_name">&lt;= <a href="#b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#le">le</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#range" class="func_name">range</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64" class="func_name">&lt;&gt; <a href="#24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#neq">neq</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="func_name">&lt;{} <a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="self_link"></a></h2><p></p><div class="notes"><pre><code> ... a &lt;{}
----------------
... [] a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[] <a href="#swap">swap</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Tuck an empty list just under the first item on the stack.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name">&lt;&lt;{}</a></div><div class="backlinks"><h3>Used By</h3><a href="#flatten" class="func_name">flatten</a> <a href="#grabN" class="func_name">grabN</a> <a href="#reverse" class="func_name">reverse</a> <a href="#run" class="func_name">run</a></div></div><hr><div><h2 id="380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3" class="func_name">= <a href="#380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#eq">eq</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#cmp" class="func_name">cmp</a></div></div><hr><div><h2 id="62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221" class="func_name">&gt; <a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#gt">gt</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#cmp" class="func_name">cmp</a> <a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#gcd" class="func_name">gcd</a> <a href="#" class="func_name">max-of-two</a></div></div><hr><div><h2 id="92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f" class="func_name">&gt;= <a href="#92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#ge">ge</a>.</p></div><div class="backlinks"><h3>Used By</h3><a href="#e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf" class="func_name">!-</a></div></div><hr><div><h2 id="0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="func_name">&gt;&gt; <a href="#0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#rshift">rshift</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#rshift">rshift</a></div></div></div><hr><div><h2 id="8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="func_name">? <a href="#8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="self_link"></a></h2><p></p><div class="notes"><p>Is the item on the top of the stack "truthy"?</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dup">dup</a> <a href="#bool">bool</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>You often want to test the truth value of an item on the stack without
consuming the item.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#bool" class="func_name">bool</a></div></div><hr><div><h2 id="7a063e4cb04c8b9d833cec4caea5b184720eba13daf25139c99a355a266d921f" class="func_name">\/ <a href="#7a063e4cb04c8b9d833cec4caea5b184720eba13daf25139c99a355a266d921f" class="self_link"></a></h2><p></p><div class="notes"><p>Binary Boolean <em>or</em>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#">_isnt_two_bools</a> [] [<a href="#pop">pop</a> true] <a href="#branch">branch</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#bool" class="func_name">bool</a> <a href="#not" class="func_name">not</a> <a href="#c1773bc23efd62ebecd69d025d1561e8fc864159ba2fc48177060e4b376112b5" class="func_name">/\</a></div></div><hr><div><h2 id="abs" class="func_name">abs <a href="#abs" class="self_link"></a></h2><p></p><div class="notes"><p>Take an integer from the stack and replace it with its absolute value.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dup">dup</a> 0 <a href="#dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72">&lt;</a> [] [<a href="#neg">neg</a>] <a href="#branch">branch</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="add" class="func_name">add <a href="#add" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Take two integers from the stack and replace them with their sum.</p></div></div><hr><div><h2 id="anamorphism" class="func_name">anamorphism <a href="#anamorphism" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Build a list of values from a generator program <code>G</code> and a stopping
predicate <code>P</code>.</p>
<pre><code> [P] [G] anamorphism
-----------------------------------------
[P] [pop []] [G] [dip swons] genrec
</code></pre>
<h3>Example</h3>
<p>The <code>range</code> function generates a list of the integers from 0 to n - 1:</p>
<pre><code>[0 &lt;=] [-- dup] anamorphism
</code></pre>
<blockquote>
<p>joy? 5 </p>
<p>5</p>
<p>joy? [0 &lt;=] [-- dup]</p>
<p>5 [0 &lt;=] [-- dup]</p>
<p>joy? anamorphism</p>
<p>[4 3 2 1 0]</p>
</blockquote>
<p>Note that the last value generated (0) is at the bottom of the list.
See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<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></div></div><div class="backlinks"><h3>Used By</h3><a href="#range" class="func_name">range</a></div></div><hr><div><h2 id="and" class="func_name">and <a href="#and" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Short-circuiting Boolean AND</p>
<p>Accept two quoted programs, run the first and expect a Boolean value, if
it'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.) The quoted programs are run with [nullary].</p>
<pre><code> [A] [B] and
----------------- A -&gt; true
B
[A] [B] and
----------------- A -&gt; false
false
</code></pre>
<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></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#nulco">nulco</a> [<a href="#nullary">nullary</a> [false]] <a href="#dip">dip</a> <a href="#branch">branch</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#or" class="func_name">or</a></div><div class="backlinks"><h3>Used By</h3><a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1 <a href="#172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>"apply one"</p>
<p>Given a quoted program on TOS and anything as the second stack item run
the program without disturbing the rest of the stack and replace the two args with
the first result of the program.</p>
<pre><code> ... x [Q] app1
---------------------------------
... [x ...] [Q] infra first
</code></pre>
<p>This is the same effect as the <a href="#unary">unary</a> combinator.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#grba">grba</a> <a href="#infrst">infrst</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Just a specialization of <code>nullary</code> really. Its parallelizable cousins
are more useful.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a> <a href="#appN" class="func_name">appN</a> <a href="#unary" class="func_name">unary</a></div></div><hr><div><h2 id="d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2 <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Like <a href="#app1">app1</a> with two items.</p>
<pre><code> ... y x [Q] . app2
-----------------------------------
... [y ...] [Q] . infra first
[x ...] [Q] infra first
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<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></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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.
This is not currently implemented as parallel processes but it can (and
should) be done.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a> <a href="#appN" class="func_name">appN</a> <a href="#unary" class="func_name">unary</a></div><div class="backlinks"><h3>Used By</h3><a href="#fork" class="func_name">fork</a></div></div><hr><div><h2 id="697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3 <a href="#697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Like [app1] with three items.</p>
<pre><code> ... z y x [Q] . app3
-----------------------------------
... [z ...] [Q] . infra first
[y ...] [Q] infra first
[x ...] [Q] infra first
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">3 <a href="#appN">appN</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>See [app2].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#appN" class="func_name">appN</a> <a href="#unary" class="func_name">unary</a></div></div><hr><div><h2 id="appN" class="func_name">appN <a href="#appN" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Like [app1] with any number of items.</p>
<pre><code> ... xN ... x2 x1 x0 [Q] n . appN
--------------------------------------
... [xN ...] [Q] . infra first
...
[x2 ...] [Q] infra first
[x1 ...] [Q] infra first
[x0 ...] [Q] infra first
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#grabN">grabN</a>] <a href="#codi">codi</a> <a href="#map">map</a> <a href="#reverse">reverse</a> <a href="#disenstacken">disenstacken</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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 [app2].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a> <a href="#unary" class="func_name">unary</a></div><div class="backlinks"><h3>Used By</h3><a href="#697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a></div></div><hr><div><h2 id="at" class="func_name">at <a href="#at" class="self_link"></a></h2><p></p><div class="notes"><p>See <a href="#getitem">getitem</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#drop">drop</a> <a href="#first">first</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#of" class="func_name">of</a></div></div><hr><div><h2 id="average" class="func_name">average <a href="#average" class="self_link"></a></h2><p></p><div class="notes"><p>Compute the average of a list of numbers.
(Currently broken until I can figure out what to do about "numeric tower"
in Thun.)</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#sum">sum</a>] [<a href="#size">size</a>] <a href="#cleave">cleave</a> <a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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?
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></div></div></div><hr><div><h2 id="b" class="func_name">b <a href="#b" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run two quoted programs</p>
<pre><code> [P] [Q] b
---------------
P Q
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#i">i</a>] <a href="#dip">dip</a> <a href="#i">i</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This combinator may seem trivial but it comes in handy.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dupdip" class="func_name">dupdip</a> <a href="#ii" class="func_name">ii</a></div></div><hr><div><h2 id="binary" class="func_name">binary <a href="#binary" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run a quoted program using exactly two stack values and leave the first
item of the result on the stack.</p>
<pre><code> ... y x [P] binary
-----------------------
... a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#unary">unary</a> <a href="#popd">popd</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Runs any other quoted function and returns its first result while
consuming exactly two items from the stack.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#nullary" class="func_name">nullary</a> <a href="#ternary" class="func_name">ternary</a> <a href="#unary" class="func_name">unary</a></div><div class="backlinks"><h3>Used By</h3><a href="#ternary" class="func_name">ternary</a></div></div><hr><div><h2 id="bool" class="func_name">bool <a href="#bool" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Convert the item on the top of the stack to a Boolean value.</p></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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></div></div><div class="crosslinks"><h3>See Also</h3><a href="#not" class="func_name">not</a></div><div class="backlinks"><h3>Used By</h3><a href="#8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="func_name">?</a> <a href="#null" class="func_name">null</a></div></div><hr><div><h2 id="branch" class="func_name">branch <a href="#branch" class="self_link"></a></h2><p><span class="kind">combinator</span> <span class="kind">built-in</span></p><div class="notes"><p>Use a Boolean value to select and run one of two quoted programs.</p>
<pre><code> false [F] [T] branch
--------------------------
F
true [F] [T] branch
-------------------------
T
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is one of the fundamental operations (although it can be defined in
terms of [choice] as above). The more common "if..then..else" construct
[ifte] adds a predicate function that is evaluated [nullary].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#choice" class="func_name">choice</a> <a href="#ifte" class="func_name">ifte</a> <a href="#select" class="func_name">select</a></div><div class="backlinks"><h3>Used By</h3><a href="#c1773bc23efd62ebecd69d025d1561e8fc864159ba2fc48177060e4b376112b5" class="func_name">/\</a> <a href="#7a063e4cb04c8b9d833cec4caea5b184720eba13daf25139c99a355a266d921f" class="func_name">\/</a> <a href="#abs" class="func_name">abs</a> <a href="#and" class="func_name">and</a> <a href="#choice" class="func_name">choice</a> <a href="#ifte" class="func_name">ifte</a> <a href="#not" class="func_name">not</a> <a href="#" class="func_name">on-non-empty-list</a> <a href="#or" class="func_name">or</a> <a href="#small" class="func_name">small</a></div></div><hr><div><h2 id="ccccons" class="func_name">ccccons <a href="#ccccons" class="self_link"></a></h2><p></p><div class="notes"><pre><code> a b c d [...] ccccons
---------------------------
[a b c d ...]
</code></pre>
<p>Do [cons] four times.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#ccons">ccons</a> <a href="#ccons">ccons</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#ccons" class="func_name">ccons</a> <a href="#cons" class="func_name">cons</a> <a href="#times" class="func_name">times</a></div><div class="backlinks"><h3>Used By</h3><a href="#genrec" class="func_name">genrec</a></div></div><hr><div><h2 id="ccons" class="func_name">ccons <a href="#ccons" class="self_link"></a></h2><p></p><div class="notes"><pre><code> a b [...] ccons
---------------------
[a b ...]
</code></pre>
<p>Do [cons] two times.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#cons">cons</a> <a href="#cons">cons</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cons" class="func_name">cons</a> <a href="#ccons" class="func_name">ccons</a></div><div class="backlinks"><h3>Used By</h3><a href="#ccccons" class="func_name">ccccons</a> <a href="#cmp" class="func_name">cmp</a> <a href="#766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator</a></div></div><hr><div><h2 id="choice" class="func_name">choice <a href="#choice" class="self_link"></a></h2><p></p><div class="notes"><p>Use a Boolean value to select one of two items.</p>
<pre><code> a b false choice
----------------------
a
a b true choice
---------------------
b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#pop">pop</a>] [<a href="#popd">popd</a>] <a href="#branch">branch</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>It's a matter of taste whether you implement this in terms of [branch] or
the other way around.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#branch" class="func_name">branch</a> <a href="#select" class="func_name">select</a></div></div><hr><div><h2 id="clear" class="func_name">clear <a href="#clear" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Clear everything from the stack.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[] <a href="#swaack">swaack</a> <a href="#pop">pop</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#stack" class="func_name">stack</a> <a href="#swaack" class="func_name">swaack</a></div><div class="backlinks"><h3>Used By</h3><a href="#enstacken" class="func_name">enstacken</a></div></div><hr><div><h2 id="cleave" class="func_name">cleave <a href="#cleave" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run two programs in parallel, consuming one additional item, and put their
results on the stack.</p>
<pre><code> ... x [A] [B] cleave
------------------------
... a b
</code></pre>
<h3>Derivation</h3>
<blockquote>
<p>[fork] [popdd]</p>
</blockquote>
<h3>Example</h3>
<pre><code> 1 2 3 [+] [-] cleave
--------------------------
1 2 5 -1
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#fork">fork</a> <a href="#popdd">popdd</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>One of a handful of useful parallel combinators.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#clop" class="func_name">clop</a> <a href="#fork" class="func_name">fork</a> <a href="#map" class="func_name">map</a></div><div class="backlinks"><h3>Used By</h3><a href="#average" class="func_name">average</a> <a href="#clop" class="func_name">clop</a></div></div><hr><div><h2 id="clop" class="func_name">clop <a href="#clop" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run two programs in parallel, consuming two additional items, and put their results on the stack.</p>
<pre><code> ... x y [A] [B] clop
--------------------------
... a b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#cleave">cleave</a> <a href="#popdd">popdd</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Like [cleave] but consumes an additional item from the stack.
1 2 3 4 [+] [-] clop
--------------------------
1 2 7 -1</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cleave" class="func_name">cleave</a> <a href="#fork" class="func_name">fork</a> <a href="#map" class="func_name">map</a></div><div class="backlinks"><h3>Used By</h3><a href="#divmod" class="func_name">divmod</a> <a href="#pm" class="func_name">pm</a> <a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="cmp" class="func_name">cmp <a href="#cmp" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><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>
<pre><code> a b [G] [E] [L] cmp
------------------------- a &gt; b
G
a b [G] [E] [L] cmp
------------------------- a = b
E
a b [G] [E] [L] cmp
------------------------- a &lt; b
L
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[[<a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">&gt;</a>] <a href="#swap">swap</a>] <a href="#dipd">dipd</a> [<a href="#ifte">ifte</a>] <a href="#ccons">ccons</a> [<a href="#380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3">=</a>] <a href="#swons">swons</a> <a href="#ifte">ifte</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is useful sometimes, and you can [dup] or [dupd] with two quoted
programs to handle the cases when you just want to deal with [&lt;=] or [&gt;=]
and not all three possibilities, e.g.:
[G] [EL] dup cmp
[GE] [L] dupd cmp
Or even:
[GL] [E] over cmp</p></div></div><div class="backlinks"><h3>Used By</h3><a href="#eq" class="func_name">eq</a> <a href="#ge" class="func_name">ge</a> <a href="#gt" class="func_name">gt</a> <a href="#le" class="func_name">le</a> <a href="#lt" class="func_name">lt</a> <a href="#neq" class="func_name">neq</a></div></div><hr><div><h2 id="codi" class="func_name">codi <a href="#codi" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Take a quoted program from the stack, [cons] the next item onto it, then
[dip] the whole thing under what was the third item on the stack.</p>
<pre><code> a b [F] . codi
--------------------
b . F a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#cons">cons</a> <a href="#dip">dip</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is one of those weirdly specific functions that turns out to be
useful in a few places.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#appN" class="func_name">appN</a> <a href="#codireco" class="func_name">codireco</a></div><div class="backlinks"><h3>Used By</h3><a href="#appN" class="func_name">appN</a> <a href="#codireco" class="func_name">codireco</a> <a href="#dipd" class="func_name">dipd</a></div></div><hr><div><h2 id="codireco" class="func_name">codireco <a href="#codireco" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>This is part of the [make_generator] function. You would not use this
combinator directly.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#codi">codi</a> <a href="#reco">reco</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>See [make_generator] and the
<a href="https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation">"Using <code>x</code> to Generate Values" 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></div></div><div class="crosslinks"><h3>See Also</h3><a href="#766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator</a></div><div class="backlinks"><h3>Used By</h3><a href="#766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator</a></div></div><hr><div><h2 id="concat" class="func_name">concat <a href="#concat" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Concatinate two lists.</p>
<pre><code> [a b c] [d e f] concat
----------------------------
[a b c d e f]
</code></pre></div><div class="crosslinks"><h3>See Also</h3><a href="#first" class="func_name">first</a> <a href="#07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two</a> <a href="#flatten" class="func_name">flatten</a> <a href="#fourth" class="func_name">fourth</a> <a href="#getitem" class="func_name">getitem</a> <a href="#remove" class="func_name">remove</a> <a href="#rest" class="func_name">rest</a> <a href="#reverse" class="func_name">reverse</a> <a href="#rrest" class="func_name">rrest</a> <a href="#second" class="func_name">second</a> <a href="#shift" class="func_name">shift</a> <a href="#shunt" class="func_name">shunt</a> <a href="#size" class="func_name">size</a> <a href="#sort" class="func_name">sort</a> <a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a> <a href="#swaack" class="func_name">swaack</a> <a href="#third" class="func_name">third</a> <a href="#zip" class="func_name">zip</a></div><div class="backlinks"><h3>Used By</h3><a href="#flatten" class="func_name">flatten</a> <a href="#genrec" class="func_name">genrec</a> <a href="#swoncat" class="func_name">swoncat</a> <a href="#while" class="func_name">while</a></div></div><hr><div><h2 id="cond" class="func_name">cond <a href="#cond" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><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>
<pre><code>[
[ [Predicate0] Function0 ]
[ [Predicate1] Function1 ]
...
[ [PredicateN] FunctionN ]
[Default]
]
cond
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>It works by rewriting into a chain of nested [ifte]{.title-ref}
expressions, e.g.:
[[[B0] T0] [[B1] T1] [D]] cond
-----------------------------------------
[B0] [T0] [[B1] [T1] [D] ifte] ifte</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#ifte" class="func_name">ifte</a></div></div><hr><div><h2 id="cons" class="func_name">cons <a href="#cons" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Given an item and a list, append the item to the list to make a new list.</p>
<pre><code> a [...] cons
------------------
[a ...]
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Cons is a <a href="https://en.wikipedia.org/wiki/Cons#Lists">venerable old function from Lisp</a>.
Its inverse operation is [uncons].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#uncons" class="func_name">uncons</a></div><div class="backlinks"><h3>Used By</h3><a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#ccons" class="func_name">ccons</a> <a href="#codi" class="func_name">codi</a> <a href="#dipdd" class="func_name">dipdd</a> <a href="#dipddd" class="func_name">dipddd</a> <a href="#grabN" class="func_name">grabN</a> <a href="#map" class="func_name">map</a> <a href="#nulco" class="func_name">nulco</a> <a href="#pow" class="func_name">pow</a> <a href="#" class="func_name">quote-two</a> <a href="#reco" class="func_name">reco</a> <a href="#swons" class="func_name">swons</a> <a href="#unit" class="func_name">unit</a> <a href="#zip" class="func_name">zip</a></div></div><hr><div><h2 id="dinfrirst" class="func_name">dinfrirst <a href="#dinfrirst" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Specialist function (that means I forgot what it does and why.)</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dip">dip</a> <a href="#infrst">infrst</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#nullary" class="func_name">nullary</a></div></div><hr><div><h2 id="dip" class="func_name">dip <a href="#dip" class="self_link"></a></h2><p><span class="kind">combinator</span> <span class="kind">built-in</span></p><div class="notes"><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>
<pre><code> ... x [Q] . dip
---------------------
... . Q x
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This along with [infra] are enough to update any datastructure.
See the <a href="https://joypy.osdn.io/notebooks/Zipper.html">"Traversing Datastructures with Zippers" notebook</a>.
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't use symbols as
"atoms" 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 "set aside" the
item and replace it after running <code>Q</code> but that means that there is an
"extra space" 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></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dipd" class="func_name">dipd</a> <a href="#dipdd" class="func_name">dipdd</a> <a href="#dupdip" class="func_name">dupdip</a> <a href="#dupdipd" class="func_name">dupdipd</a> <a href="#infra" class="func_name">infra</a></div><div class="backlinks"><h3>Used By</h3><a href="#anamorphism" class="func_name">anamorphism</a> <a href="#and" class="func_name">and</a> <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#b" class="func_name">b</a> <a href="#codi" class="func_name">codi</a> <a href="#dinfrirst" class="func_name">dinfrirst</a> <a href="#dipd" class="func_name">dipd</a> <a href="#dipdd" class="func_name">dipdd</a> <a href="#dupd" class="func_name">dupd</a> <a href="#dupdip" class="func_name">dupdip</a> <a href="#enstacken" class="func_name">enstacken</a> <a href="#grba" class="func_name">grba</a> <a href="#ii" class="func_name">ii</a> <a href="#infra" class="func_name">infra</a> <a href="#map" class="func_name">map</a> <a href="#" class="func_name">on-non-empty-list</a> <a href="#or" class="func_name">or</a> <a href="#over" class="func_name">over</a> <a href="#popd" class="func_name">popd</a> <a href="#popopd" class="func_name">popopd</a> <a href="#quoted" class="func_name">quoted</a> <a href="#shift" class="func_name">shift</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a> <a href="#stackd" class="func_name">stackd</a> <a href="#swapd" class="func_name">swapd</a> <a href="#unquoted" class="func_name">unquoted</a> <a href="#unstack" class="func_name">unstack</a></div></div><hr><div><h2 id="dipd" class="func_name">dipd <a href="#dipd" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Like [dip] but expects two items.</p>
<pre><code> ... y x [Q] . dipd
-------------------------
... . Q y x
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#dip">dip</a>] <a href="#codi">codi</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>See [dip].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dip" class="func_name">dip</a> <a href="#dipdd" class="func_name">dipdd</a> <a href="#dipddd" class="func_name">dipddd</a> <a href="#dupdip" class="func_name">dupdip</a> <a href="#dupdipd" class="func_name">dupdipd</a> <a href="#infra" class="func_name">infra</a></div><div class="backlinks"><h3>Used By</h3><a href="#cmp" class="func_name">cmp</a> <a href="#dipdd" class="func_name">dipdd</a> <a href="#dipddd" class="func_name">dipddd</a> <a href="#dupdd" class="func_name">dupdd</a> <a href="#dupdipd" class="func_name">dupdipd</a> <a href="#ifte" class="func_name">ifte</a> <a href="#popdd" class="func_name">popdd</a> <a href="#popopdd" class="func_name">popopdd</a> <a href="#" class="func_name">uncons-pair</a></div></div><hr><div><h2 id="dipdd" class="func_name">dipdd <a href="#dipdd" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Like [dip] but expects three items. :</p>
<pre><code> ... z y x [Q] . dipdd
-----------------------------
... . Q z y x
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#dip">dip</a>] <a href="#cons">cons</a> <a href="#dipd">dipd</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>See [dip].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dip" class="func_name">dip</a> <a href="#dipd" class="func_name">dipd</a> <a href="#dipddd" class="func_name">dipddd</a> <a href="#dupdip" class="func_name">dupdip</a> <a href="#dupdipd" class="func_name">dupdipd</a> <a href="#infra" class="func_name">infra</a></div></div><hr><div><h2 id="dipddd" class="func_name">dipddd <a href="#dipddd" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Like [dip] but expects four items. :</p>
<pre><code> ... z y x w [Q] . dipddd
-------------------------------
... . Q z y x w
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#dipd">dipd</a>] <a href="#cons">cons</a> <a href="#dipd">dipd</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>See [dip].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dip" class="func_name">dip</a> <a href="#dipd" class="func_name">dipd</a> <a href="#dipdd" class="func_name">dipdd</a> <a href="#dupdip" class="func_name">dupdip</a> <a href="#dupdipd" class="func_name">dupdipd</a> <a href="#infra" class="func_name">infra</a></div></div><hr><div><h2 id="disenstacken" class="func_name">disenstacken <a href="#disenstacken" class="self_link"></a></h2><p></p><div class="notes"><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>
<pre><code> 1 2 3 [4 5 6] disenstacken
--------------------------------
6 5 4
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#swaack">swaack</a> <a href="#pop">pop</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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></div></div><div class="crosslinks"><h3>See Also</h3><a href="#enstacken" class="func_name">enstacken</a> <a href="#stack" class="func_name">stack</a> <a href="#unstack" class="func_name">unstack</a></div><div class="backlinks"><h3>Used By</h3><a href="#appN" class="func_name">appN</a></div></div><hr><div><h2 id="div" class="func_name">div <a href="#div" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Divide.</p></div></div><hr><div><h2 id="divmod" class="func_name">divmod <a href="#divmod" class="self_link"></a></h2><p></p><div class="notes"><pre><code> x y divmod
------------------
q r
(x/y) (x%y)
</code></pre>
<p>Invariant: <code>qy + r = x</code>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a>] [<a href="#bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a>] <a href="#clop">clop</a></div></div></div><hr><div><h2 id="24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero <a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="self_link"></a></h2><p></p><div class="notes"><p>Given a number greater than zero put all the Natural numbers (including
zero) less than that onto the stack.</p>
<h3>Example</h3>
<pre><code> 3 down_to_zero
--------------------
3 2 1 0
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[0 <a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">&gt;</a>] [<a href="#dup">dup</a> <a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a>] <a href="#while">while</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#range" class="func_name">range</a></div><div class="backlinks"><h3>Used By</h3><a href="#ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero</a></div></div><hr><div><h2 id="drop" class="func_name">drop <a href="#drop" class="self_link"></a></h2><p></p><div class="notes"><p>Expects an integer and a quote on the stack and returns the quote with n
items removed off the top.</p>
<h3>Example</h3>
<pre><code> [a b c d] 2 drop
----------------------
[c d]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#rest">rest</a>] <a href="#times">times</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#take" class="func_name">take</a></div><div class="backlinks"><h3>Used By</h3><a href="#at" class="func_name">at</a> <a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="dup" class="func_name">dup <a href="#dup" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>"Dup"licate the top item on the stack.</p>
<pre><code> a dup
-----------
a a
</code></pre></div><div class="crosslinks"><h3>See Also</h3><a href="#dupd" class="func_name">dupd</a> <a href="#dupdd" class="func_name">dupdd</a> <a href="#dupdip" class="func_name">dupdip</a> <a href="#dupdipd" class="func_name">dupdipd</a></div><div class="backlinks"><h3>Used By</h3><a href="#8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="func_name">?</a> <a href="#abs" class="func_name">abs</a> <a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#dupd" class="func_name">dupd</a> <a href="#dupdd" class="func_name">dupdd</a> <a href="#dupdipd" class="func_name">dupdipd</a> <a href="#" class="func_name">empty?</a> <a href="#gcd" class="func_name">gcd</a> <a href="#over" class="func_name">over</a> <a href="#range" class="func_name">range</a> <a href="#small" class="func_name">small</a> <a href="#sqr" class="func_name">sqr</a> <a href="#tuck" class="func_name">tuck</a> <a href="#x" class="func_name">x</a></div></div><hr><div><h2 id="dupd" class="func_name">dupd <a href="#dupd" class="self_link"></a></h2><p></p><div class="notes"><p>[dup] the second item down on the stack.</p>
<pre><code> a b dupd
--------------
a a b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#dup">dup</a>] <a href="#dip">dip</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dup" class="func_name">dup</a> <a href="#dupdd" class="func_name">dupdd</a> <a href="#dupdip" class="func_name">dupdip</a> <a href="#dupdipd" class="func_name">dupdipd</a></div><div class="backlinks"><h3>Used By</h3><a href="#dupdip" class="func_name">dupdip</a></div></div><hr><div><h2 id="dupdd" class="func_name">dupdd <a href="#dupdd" class="self_link"></a></h2><p></p><div class="notes"><p>[dup] the third item down on the stack.</p>
<pre><code> a b c dupdd
-----------------
a a b c
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#dup">dup</a>] <a href="#dipd">dipd</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dup" class="func_name">dup</a> <a href="#dupd" class="func_name">dupd</a> <a href="#dupdip" class="func_name">dupdip</a> <a href="#dupdipd" class="func_name">dupdipd</a></div></div><hr><div><h2 id="dupdip" class="func_name">dupdip <a href="#dupdip" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Apply a function <code>F</code> and [dup] the item under it on the stack.</p>
<pre><code> a [F] dupdip
------------------
a F a
</code></pre>
<h3>Derivation</h3>
<pre><code>a [F] dupdip
a [F] dupd dip
a [F] [dup] dip dip
a dup [F] dip
a a [F] dip
a F a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dupd">dupd</a> <a href="#dip">dip</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>A very common and useful combinator.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dupdipd" class="func_name">dupdipd</a></div><div class="backlinks"><h3>Used By</h3><a href="#ii" class="func_name">ii</a> <a href="#uncons" class="func_name">uncons</a></div></div><hr><div><h2 id="dupdipd" class="func_name">dupdipd <a href="#dupdipd" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run a copy of program <code>F</code> under the next item down on the stack.</p>
<pre><code> a [F] dupdipd
-------------------
F a [F]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dup">dup</a> <a href="#dipd">dipd</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#dupdip" class="func_name">dupdip</a></div><div class="backlinks"><h3>Used By</h3><a href="#while" class="func_name">while</a></div></div><hr><div><h2 id="enstacken" class="func_name">enstacken <a href="#enstacken" class="self_link"></a></h2><p></p><div class="notes"><p>Put the stack onto the stack replacing the contents of the stack.</p>
<pre><code> ... a b c enstacken
-------------------------
[c b a ...]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#stack">stack</a> [<a href="#clear">clear</a>] <a href="#dip">dip</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is a destructive version of [stack]. See the note under
[disenstacken] about the apparent but illusory reversal of the stack.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#stack" class="func_name">stack</a> <a href="#disenstacken" class="func_name">disenstacken</a> <a href="#unstack" class="func_name">unstack</a></div></div><hr><div><h2 id="eq" class="func_name">eq <a href="#eq" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Compare the two items on the top of the stack for equality and replace
them with a Boolean value.</p>
<pre><code> a b eq
-------------
Boolean
(a = b)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[false] [true] [false] <a href="#cmp">cmp</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cmp" class="func_name">cmp</a> <a href="#ge" class="func_name">ge</a> <a href="#gt" class="func_name">gt</a> <a href="#le" class="func_name">le</a> <a href="#lt" class="func_name">lt</a> <a href="#neq" class="func_name">neq</a></div></div><hr><div><h2 id="first" class="func_name">first <a href="#first" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Replace a list with its first item.</p>
<pre><code> [a ...]
--------------
a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#uncons">uncons</a> <a href="#pop">pop</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#second" class="func_name">second</a> <a href="#third" class="func_name">third</a> <a href="#fourth" class="func_name">fourth</a> <a href="#rest" class="func_name">rest</a></div><div class="backlinks"><h3>Used By</h3><a href="#at" class="func_name">at</a> <a href="#07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two</a> <a href="#getitem" class="func_name">getitem</a> <a href="#infrst" class="func_name">infrst</a> <a href="#" class="func_name">on-non-empty-list</a> <a href="#second" class="func_name">second</a> <a href="#uncons" class="func_name">uncons</a></div></div><hr><div><h2 id="07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two <a href="#07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="self_link"></a></h2><p></p><div class="notes"><p>Replace a list with its first two items.</p>
<pre><code> [a b ...] first_two
-------------------------
a b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#uncons">uncons</a> <a href="#first">first</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#first" class="func_name">first</a> <a href="#second" class="func_name">second</a> <a href="#third" class="func_name">third</a> <a href="#fourth" class="func_name">fourth</a> <a href="#rest" class="func_name">rest</a></div></div><hr><div><h2 id="flatten" class="func_name">flatten <a href="#flatten" class="self_link"></a></h2><p></p><div class="notes"><p>Given a list of lists, concatinate them.</p>
<h3>Example</h3>
<pre><code> [[1 2] [3 [4] 5] [6 7]] flatten
-------------------------------------
[1 2 3 [4] 5 6 7]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a> [<a href="#concat">concat</a>] <a href="#step">step</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Note that only one "level" of lists is flattened. In the example above
<code>[4]</code> is not unquoted.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#concat" class="func_name">concat</a> <a href="#first" class="func_name">first</a> <a href="#07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two</a> <a href="#fourth" class="func_name">fourth</a> <a href="#getitem" class="func_name">getitem</a> <a href="#remove" class="func_name">remove</a> <a href="#rest" class="func_name">rest</a> <a href="#reverse" class="func_name">reverse</a> <a href="#rrest" class="func_name">rrest</a> <a href="#second" class="func_name">second</a> <a href="#shift" class="func_name">shift</a> <a href="#shunt" class="func_name">shunt</a> <a href="#size" class="func_name">size</a> <a href="#sort" class="func_name">sort</a> <a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a> <a href="#swaack" class="func_name">swaack</a> <a href="#third" class="func_name">third</a> <a href="#zip" class="func_name">zip</a></div></div><hr><div><h2 id="fork" class="func_name">fork <a href="#fork" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run two quoted programs in parallel and replace them with their results.</p>
<pre><code> ... [F] [G] fork
----------------------
... f g
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#i">i</a>] <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a">app2</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>The basic parallelism combinator, the two programs are run independently.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cleave" class="func_name">cleave</a> <a href="#clop" class="func_name">clop</a> <a href="#map" class="func_name">map</a></div><div class="backlinks"><h3>Used By</h3><a href="#cleave" class="func_name">cleave</a></div></div><hr><div><h2 id="fourth" class="func_name">fourth <a href="#fourth" class="self_link"></a></h2><p></p><div class="notes"><p>Replace a list with its fourth item.</p>
<pre><code> [a b c d ...] fourth
--------------------------
d
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#rest">rest</a> <a href="#third">third</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#first" class="func_name">first</a> <a href="#second" class="func_name">second</a> <a href="#third" class="func_name">third</a> <a href="#rest" class="func_name">rest</a></div></div><hr><div><h2 id="gcd" class="func_name">gcd <a href="#gcd" class="self_link"></a></h2><p></p><div class="notes"><p>Take two integers from the stack and replace them with their Greatest
Common Denominator.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">true [<a href="#tuck">tuck</a> <a href="#mod">mod</a> <a href="#dup">dup</a> 0 <a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">&gt;</a>] <a href="#loop">loop</a> <a href="#pop">pop</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Euclid's Algorithm</p></div></div></div><hr><div><h2 id="ge" class="func_name">ge <a href="#ge" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Greater-than-or-equal-to comparison of two numbers.</p>
<pre><code> a b ge
--------------
Boolean
(a &gt;= b)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[true] [true] [false] <a href="#cmp">cmp</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cmp" class="func_name">cmp</a> <a href="#eq" class="func_name">eq</a> <a href="#gt" class="func_name">gt</a> <a href="#le" class="func_name">le</a> <a href="#lt" class="func_name">lt</a> <a href="#neq" class="func_name">neq</a></div></div><hr><div><h2 id="genrec" class="func_name">genrec <a href="#genrec" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p><strong>Gen</strong>eral <strong>Rec</strong>ursion Combinator. </p>
<pre><code> [if] [then] [rec1] [rec2] genrec
---------------------------------------------------------------------
[if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[[<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></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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.
See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.
From <a href="https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html">"Recursion Theory and Joy"</a>
by Manfred von Thun:</p>
<blockquote>
<p>"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."
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
"sandwiching" a quotation of the whole function.
For example, given a (general recursive) function <code>F</code>:
F == [I] [T] [R1] [R2] genrec
If the <code>[I]</code> if-part fails you must derive <code>R1</code> and <code>R2</code> from: :
... R1 [F] R2
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 [ifte] combinator with a quoted copy of
the original definition in the else-part:
F == [I] [T] [R1] [R2] genrec
== [I] [T] [R1 [F] R2] ifte
Tail recursive functions are those where <code>R2</code> is the <code>i</code> combinator:
P == [I] [T] [R] tailrec
== [I] [T] [R [P] i] ifte
== [I] [T] [R P] ifte</p>
</blockquote></div></div><div class="crosslinks"><h3>See Also</h3><a href="#anamorphism" class="func_name">anamorphism</a> <a href="#tailrec" class="func_name">tailrec</a> <a href="#x" class="func_name">x</a></div><div class="backlinks"><h3>Used By</h3><a href="#anamorphism" class="func_name">anamorphism</a> <a href="#genrec" class="func_name">genrec</a> <a href="#tailrec" class="func_name">tailrec</a> <a href="#zip" class="func_name">zip</a></div></div><hr><div><h2 id="getitem" class="func_name">getitem <a href="#getitem" class="self_link"></a></h2><p></p><div class="notes"><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>
<h3>Example</h3>
<pre><code> [a b c d] 2 getitem
-------------------------
c
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#rest">rest</a>] <a href="#times">times</a> <a href="#first">first</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>If the number isn'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></div></div><div class="crosslinks"><h3>See Also</h3><a href="#concat" class="func_name">concat</a> <a href="#first" class="func_name">first</a> <a href="#07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two</a> <a href="#flatten" class="func_name">flatten</a> <a href="#fourth" class="func_name">fourth</a> <a href="#remove" class="func_name">remove</a> <a href="#rest" class="func_name">rest</a> <a href="#reverse" class="func_name">reverse</a> <a href="#rrest" class="func_name">rrest</a> <a href="#second" class="func_name">second</a> <a href="#shift" class="func_name">shift</a> <a href="#shunt" class="func_name">shunt</a> <a href="#size" class="func_name">size</a> <a href="#sort" class="func_name">sort</a> <a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a> <a href="#swaack" class="func_name">swaack</a> <a href="#third" class="func_name">third</a> <a href="#zip" class="func_name">zip</a></div><div class="backlinks"><h3>Used By</h3><a href="#pick" class="func_name">pick</a></div></div><hr><div><h2 id="grabN" class="func_name">grabN <a href="#grabN" class="self_link"></a></h2><p></p><div class="notes"><p>Expect a number on the top of the stack and [cons] that many items from under it onto a new list.</p>
<h3>Example</h3>
<pre><code> a b c d e 3 grabN
-----------------------
a b [c d e]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a> [<a href="#cons">cons</a>] <a href="#times">times</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#appN" class="func_name">appN</a></div></div><hr><div><h2 id="grba" class="func_name">grba <a href="#grba" class="self_link"></a></h2><p></p><div class="notes"><p>A weird function used in [app2] that does this:</p>
<pre><code> ... 1 2 3 4 5 grba
-------------------------------
... 1 2 3 [4 3 2 1 ...] 5
</code></pre>
<p>It grabs the stack under the top item, and substitutes it for the second item down on the stack.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#stack">stack</a> <a href="#popd">popd</a>] <a href="#dip">dip</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This function "grabs" an item from the stack along with a copy of the stack.
It's part of the [app2] definition.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a></div><div class="backlinks"><h3>Used By</h3><a href="#172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a></div></div><hr><div><h2 id="gt" class="func_name">gt <a href="#gt" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Greater-than comparison of two numbers.</p>
<pre><code> a b gt
--------------
Boolean
(a &gt; b)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[true] [false] [false] <a href="#cmp">cmp</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cmp" class="func_name">cmp</a> <a href="#eq" class="func_name">eq</a> <a href="#ge" class="func_name">ge</a> <a href="#le" class="func_name">le</a> <a href="#lt" class="func_name">lt</a> <a href="#neq" class="func_name">neq</a></div></div><hr><div><h2 id="help" class="func_name">help <a href="#help" class="self_link"></a></h2><p></p><div class="notes"><p>Accepts a quoted symbol on the top of the stack and prints its
documentation.</p>
<pre><code> [foo] help
----------------
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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></div></div></div><hr><div><h2 id="i" class="func_name">i <a href="#i" class="self_link"></a></h2><p><span class="kind">combinator</span> <span class="kind">built-in</span></p><div class="notes"><p>Append a quoted expression onto the pending expression.</p>
<pre><code> [Q] . i
-------------
. Q
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is a fundamental combinator. It is used in all kinds of places. For
example, the [x] combinator can be defined as <code>dup i</code>.</p></div></div><div class="backlinks"><h3>Used By</h3><a href="#b" class="func_name">b</a> <a href="#fork" class="func_name">fork</a> <a href="#ii" class="func_name">ii</a> <a href="#infra" class="func_name">infra</a> <a href="#pam" class="func_name">pam</a> <a href="#tailrec" class="func_name">tailrec</a> <a href="#unquoted" class="func_name">unquoted</a> <a href="#x" class="func_name">x</a> <a href="#zip" class="func_name">zip</a></div></div><hr><div><h2 id="id" class="func_name">id <a href="#id" class="self_link"></a></h2><p></p><div class="notes"><p>The identity function.</p></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy.</p></div></div></div><hr><div><h2 id="ifte" class="func_name">ifte <a href="#ifte" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>If-Then-Else combinator, a common and convenient specialization of [branch].</p>
<pre><code> [if] [then] [else] ifte
---------------------------------------
[if] nullary [else] [then] branch
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#nullary">nullary</a>] <a href="#dipd">dipd</a> <a href="#swap">swap</a> <a href="#branch">branch</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#branch" class="func_name">branch</a> <a href="#loop" class="func_name">loop</a> <a href="#while" class="func_name">while</a></div><div class="backlinks"><h3>Used By</h3><a href="#cmp" class="func_name">cmp</a> <a href="#genrec" class="func_name">genrec</a> <a href="#" class="func_name">max-of-two</a> <a href="#" class="func_name">min-of-two</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="ii" class="func_name">ii <a href="#ii" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Take a quoted program from the stack and run it twice, first under the
top item, then again with the top item.</p>
<pre><code>... a [Q] ii
------------------
... Q a Q
</code></pre>
<h3>Example</h3>
<p>It's a little tricky to understand how this works so here's an example trace:</p>
<pre><code> 1 2 3 4 [++] • [dip] dupdip i
1 2 3 4 [++] [dip] • dupdip i
1 2 3 4 [++] • dip [++] i
1 2 3 • ++ 4 [++] i
1 2 4 • 4 [++] i
1 2 4 4 • [++] i
1 2 4 4 [++] • i
1 2 4 4 • ++
1 2 4 5 •
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#dip">dip</a>] <a href="#dupdip">dupdip</a> <a href="#i">i</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>In some cases (like the example above) this is the same effect as using [app2] but most of the time it's not:
1 2 3 4 [+] ii
--------------------
1 9
1 2 3 4 [+] app2
----------------------
1 2 5 6</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#b" class="func_name">b</a></div><div class="backlinks"><h3>Used By</h3><a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a> <a href="#" class="func_name">uncons-two</a></div></div><hr><div><h2 id="infra" class="func_name">infra <a href="#infra" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><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>
<pre><code> ... x y z [a b c] [Q] infra
---------------------------------
c b a Q [z y x ...] swaack
... [a b c] [F] swons swaack [i] dip swaack
... [[F] a b c] swaack [i] dip swaack
c b a [F] [...] [i] dip swaack
c b a [F] i [...] swaack
c b a F [...] swaack
d e [...] swaack
... [e d]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><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></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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 "pocket universe". If the list represents a datastructure then
<code>infra</code> lets you work on its internal structure.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#swaack" class="func_name">swaack</a></div><div class="backlinks"><h3>Used By</h3><a href="#infrst" class="func_name">infrst</a> <a href="#ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero</a> <a href="#run" class="func_name">run</a></div></div><hr><div><h2 id="infrst" class="func_name">infrst <a href="#infrst" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Does [infra] and then extracts the [first] item from the resulting list.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#infra">infra</a> <a href="#first">first</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#dinfrirst" class="func_name">dinfrirst</a></div></div><hr><div><h2 id="inscribe" class="func_name">inscribe <a href="#inscribe" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><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>
<h3>Example</h3>
<pre><code>[sqr dup mul] inscribe
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is the only function that modifies the dictionary. It'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're doing.</p></div></div></div><hr><div><h2 id="le" class="func_name">le <a href="#le" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Less-Than-or-Equal-to comparison of the two items on the top of the
stack, replacing them with a Boolean value.</p>
<pre><code> a b le
-------------
Boolean
(a &lt;= b)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[false] [true] [true] <a href="#cmp">cmp</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cmp" class="func_name">cmp</a> <a href="#eq" class="func_name">eq</a> <a href="#ge" class="func_name">ge</a> <a href="#gt" class="func_name">gt</a> <a href="#lt" class="func_name">lt</a> <a href="#neq" class="func_name">neq</a></div></div><hr><div><h2 id="loop" class="func_name">loop <a href="#loop" class="self_link"></a></h2><p><span class="kind">combinator</span> <span class="kind">built-in</span></p><div class="notes"><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>
<pre><code> false [Q] loop
--------------------
true [Q] . loop
--------------------------
. Q [Q] loop
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This, along with [branch] and [fork], 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>
<blockquote>
<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.
Anyway, [branch], [fork], amd [loop] are the fundamental combinators in Joy.
Just as [branch] has it's more common and convenient form [ifte],
[loop] has [while].</p>
</blockquote></div></div><div class="crosslinks"><h3>See Also</h3><a href="#branch" class="func_name">branch</a> <a href="#fork" class="func_name">fork</a> <a href="#while" class="func_name">while</a></div><div class="backlinks"><h3>Used By</h3><a href="#gcd" class="func_name">gcd</a> <a href="#while" class="func_name">while</a></div></div><hr><div><h2 id="lshift" class="func_name">lshift <a href="#lshift" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p><a href="https://en.wikipedia.org/wiki/Logical_shift">Logical Left-Shift</a></p>
<pre><code> a n lshift
----------------
(a×2ⁿ)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[2 <a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#times">times</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#rshift" class="func_name">rshift</a></div><div class="backlinks"><h3>Used By</h3><a href="#4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="func_name">&lt;&lt;</a></div></div><hr><div><h2 id="lt" class="func_name">lt <a href="#lt" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Less-Than comparison of the two items on the top of the
stack, replacing them with a Boolean value.</p>
<pre><code> a b lt
-------------
Boolean
(a &lt; b)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[false] [false] [true] <a href="#cmp">cmp</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cmp" class="func_name">cmp</a> <a href="#eq" class="func_name">eq</a> <a href="#ge" class="func_name">ge</a> <a href="#gt" class="func_name">gt</a> <a href="#le" class="func_name">le</a> <a href="#neq" class="func_name">neq</a></div></div><hr><div><h2 id="766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator <a href="#766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="self_link"></a></h2><p></p><div class="notes"><p>Given an initial state value and a quoted generator function build a
generator quote.</p>
<pre><code> state [generator function] make_generator
-----------------------------------------------
[state [generator function] codireco]
</code></pre>
<h3>Example</h3>
<pre><code> 230 [dup ++] make_generator
---------------------------------
[230 [dup ++] codireco]
</code></pre>
<p>And then:</p>
<pre><code> [230 [dup ++] codireco] 5 [x] times pop
---------------------------------------------
230 231 232 233 234
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#codireco">codireco</a>] <a href="#ccons">ccons</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>See the <a href="https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation">"Using <code>x</code> to Generate Values" notebook</a>.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#codireco" class="func_name">codireco</a></div></div><hr><div><h2 id="map" class="func_name">map <a href="#map" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><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>
<h3>Example</h3>
<pre><code> 5 [1 2 3] [++ *] map
--------------------------
5 [10 15 20]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#">_map0</a>] <a href="#cons">cons</a> [[] [<a href="#">_map?</a>] [<a href="#">_mape</a>]] <a href="#dip">dip</a> <a href="#tailrec">tailrec</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is a common operation in many languages. In Joy it can be a
parallelism combinator due to the "pure" nature of the language.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a> <a href="#appN" class="func_name">appN</a> <a href="#fork" class="func_name">fork</a></div><div class="backlinks"><h3>Used By</h3><a href="#appN" class="func_name">appN</a> <a href="#pam" class="func_name">pam</a></div></div><hr><div><h2 id="max" class="func_name">max <a href="#max" class="self_link"></a></h2><p></p><div class="notes"><p>Given a list find the maximum.</p>
<h3>Example</h3>
<pre><code> [1 2 3 4] max
-------------------
4
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#uncons">uncons</a> [<a href="#">max-of-two</a>] <a href="#step">step</a>] <a href="#">on-non-empty-list</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#min" class="func_name">min</a> <a href="#size" class="func_name">size</a> <a href="#sum" class="func_name">sum</a></div></div><hr><div><h2 id="min" class="func_name">min <a href="#min" class="self_link"></a></h2><p></p><div class="notes"><p>Given a list find the minimum.</p>
<h3>Example</h3>
<pre><code> [1 2 3 4] min
-------------------
1
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#uncons">uncons</a> [<a href="#">min-of-two</a>] <a href="#step">step</a>] <a href="#">on-non-empty-list</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#max" class="func_name">max</a> <a href="#size" class="func_name">size</a> <a href="#sum" class="func_name">sum</a></div></div><hr><div><h2 id="mod" class="func_name">mod <a href="#mod" class="self_link"></a></h2><p></p><div class="notes"><p>Return the remainder of <code>a</code> divided by <code>b</code>.</p>
<pre><code> a b mod
-------------
(a%b)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#divmod" class="func_name">divmod</a> <a href="#mul" class="func_name">mul</a></div><div class="backlinks"><h3>Used By</h3><a href="#gcd" class="func_name">gcd</a></div></div><hr><div><h2 id="modulus" class="func_name">modulus <a href="#modulus" class="self_link"></a></h2><p></p><div class="notes"><p>See <a href="#mod">mod</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a></div></div></div><hr><div><h2 id="mul" class="func_name">mul <a href="#mul" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Multiply two numbers.</p>
<pre><code> a b mul
-------------
(a×b)
</code></pre></div><div class="crosslinks"><h3>See Also</h3><a href="#div" class="func_name">div</a> <a href="#product" class="func_name">product</a></div><div class="backlinks"><h3>Used By</h3><a href="#sqr" class="func_name">sqr</a></div></div><hr><div><h2 id="neg" class="func_name">neg <a href="#neg" class="self_link"></a></h2><p></p><div class="notes"><p>Invert the sign of a number.</p>
<pre><code> a neg
-----------
-a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">0 <a href="#swap">swap</a> <a href="#3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#abs" class="func_name">abs</a></div></div><hr><div><h2 id="neq" class="func_name">neq <a href="#neq" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Not-Equal comparison of the two items on the top of the
stack, replacing them with a Boolean value.</p>
<pre><code> a b neq
-------------
Boolean
(a = b)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[true] [false] [true] <a href="#cmp">cmp</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cmp" class="func_name">cmp</a> <a href="#eq" class="func_name">eq</a> <a href="#ge" class="func_name">ge</a> <a href="#gt" class="func_name">gt</a> <a href="#le" class="func_name">le</a> <a href="#lt" class="func_name">lt</a></div></div><hr><div><h2 id="not" class="func_name">not <a href="#not" class="self_link"></a></h2><p></p><div class="notes"><p>Invert the Boolean value on the top of the stack.</p>
<pre><code> true not
--------------
false
false not
---------------
true
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[true] [false] <a href="#branch">branch</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#bool" class="func_name">bool</a></div><div class="backlinks"><h3>Used By</h3><a href="#null" class="func_name">null</a></div></div><hr><div><h2 id="nulco" class="func_name">nulco <a href="#nulco" class="self_link"></a></h2><p></p><div class="notes"><p>Take the item on the top of the stack and [cons] it onto <code>[nullary]</code>.</p>
<pre><code> [F] nulco
-------------------
[[F] nullary]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#nullary">nullary</a>] <a href="#cons">cons</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Helper function for [or] and [and].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#and" class="func_name">and</a> <a href="#or" class="func_name">or</a></div><div class="backlinks"><h3>Used By</h3><a href="#and" class="func_name">and</a> <a href="#or" class="func_name">or</a> <a href="#while" class="func_name">while</a></div></div><hr><div><h2 id="null" class="func_name">null <a href="#null" class="self_link"></a></h2><p></p><div class="notes"><p>True if the item on the top of the stack is an empty list,
false if it's a list but not empty,
and an error if it's not a list.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#">_isnt_list</a> <a href="#bool">bool</a> <a href="#not">not</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#" class="func_name">empty?</a> <a href="#small" class="func_name">small</a> <a href="#zip" class="func_name">zip</a></div></div><hr><div><h2 id="nullary" class="func_name">nullary <a href="#nullary" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run a quoted program without using any stack values and leave the first
item of the result on the stack.</p>
<pre><code> ... [P] nullary
---------------------
... a
</code></pre>
<h3>Example</h3>
<pre><code>... [P] nullary
... [P] [stack] dip infra first
... stack [P] infra first
... [...] [P] infra first
... [a ...] first
... a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#stack">stack</a>] <a href="#dinfrirst">dinfrirst</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>A very useful function that runs any other quoted function and returns
it's first result without disturbing the stack (under the quoted
program.)</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#unary" class="func_name">unary</a> <a href="#binary" class="func_name">binary</a> <a href="#ternary" class="func_name">ternary</a></div><div class="backlinks"><h3>Used By</h3><a href="#and" class="func_name">and</a> <a href="#genrec" class="func_name">genrec</a> <a href="#ifte" class="func_name">ifte</a> <a href="#nulco" class="func_name">nulco</a> <a href="#or" class="func_name">or</a> <a href="#unary" class="func_name">unary</a></div></div><hr><div><h2 id="of" class="func_name">of <a href="#of" class="self_link"></a></h2><p></p><div class="notes"><p>Like [getitem] but [swap]s the order of arguments.</p>
<h3>Example</h3>
<pre><code> 2 [a b c d] of
--------------------
c
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#swap">swap</a> <a href="#at">at</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#getitem" class="func_name">getitem</a></div></div><hr><div><h2 id="or" class="func_name">or <a href="#or" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Short-circuiting Boolean OR</p>
<p>Accept two quoted programs, run the first and expect a Boolean value, if
its <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.) The quoted programs are run with [nullary].</p>
<pre><code> [A] [B] or
---------------- A -&gt; false
B
[A] [B] or
---------------- A -&gt; true
true
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#nulco">nulco</a> [<a href="#nullary">nullary</a>] <a href="#dip">dip</a> [true] <a href="#branch">branch</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#and" class="func_name">and</a></div><div class="backlinks"><h3>Used By</h3><a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="over" class="func_name">over <a href="#over" class="self_link"></a></h2><p></p><div class="notes"><p>[dup] the second item on the stack <code>over</code> the first.</p>
<pre><code> a b over
--------------
a b a
</code></pre>
<h3>Definition</h3>
<p>There are many many ways to define this function.</p>
<blockquote>
<p>[swap] [tuck]</p>
<p>[[pop]] [nullary]</p>
<p>[[dup]] [dip] [swap]</p>
<p>[unit] [dupdip]</p>
<p>[unit] [dupdipd] [first]</p>
</blockquote>
<p>And so on...</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#dup">dup</a>] <a href="#dip">dip</a> <a href="#swap">swap</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>A fine old word from Forth.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#tuck" class="func_name">tuck</a></div></div><hr><div><h2 id="pam" class="func_name">pam <a href="#pam" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Take a list of quoted functions from the stack and replace it with a list
of the [first] results from running those functions (on copies of the
rest of the stack.)</p>
<h3>Example</h3>
<pre><code> 5 7 [[+][-][*][/][%]] pam
-------------------------------
5 7 [12 -2 35 0 5]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#i">i</a>] <a href="#map">map</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>A specialization of [map] that runs a list of functions in parallel (if
the underlying [map] function is so implemented, of course.)</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#map" class="func_name">map</a></div></div><hr><div><h2 id="pick" class="func_name">pick <a href="#pick" class="self_link"></a></h2><p></p><div class="notes"><p>See <a href="#getitem">getitem</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#getitem">getitem</a></div></div></div><hr><div><h2 id="pm" class="func_name">pm <a href="#pm" class="self_link"></a></h2><p></p><div class="notes"><p>Plus or minus. Replace two numbers with their sum and difference.</p>
<pre><code> a b pm
-----------------
(a+b) (a-b)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a>] [<a href="#3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a>] <a href="#clop">clop</a></div></div></div><hr><div><h2 id="pop" class="func_name">pop <a href="#pop" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Pop the top item from the stack and discard it.</p>
<pre><code> a pop
-----------
</code></pre></div><div class="crosslinks"><h3>See Also</h3><a href="#popd" class="func_name">popd</a> <a href="#popdd" class="func_name">popdd</a> <a href="#popop" class="func_name">popop</a> <a href="#popopd" class="func_name">popopd</a> <a href="#popopdd" class="func_name">popopdd</a> <a href="#popopop" class="func_name">popopop</a></div><div class="backlinks"><h3>Used By</h3><a href="#c1773bc23efd62ebecd69d025d1561e8fc864159ba2fc48177060e4b376112b5" class="func_name">/\</a> <a href="#7a063e4cb04c8b9d833cec4caea5b184720eba13daf25139c99a355a266d921f" class="func_name">\/</a> <a href="#anamorphism" class="func_name">anamorphism</a> <a href="#choice" class="func_name">choice</a> <a href="#clear" class="func_name">clear</a> <a href="#disenstacken" class="func_name">disenstacken</a> <a href="#first" class="func_name">first</a> <a href="#gcd" class="func_name">gcd</a> <a href="#" class="func_name">max-of-two</a> <a href="#" class="func_name">min-of-two</a> <a href="#popd" class="func_name">popd</a> <a href="#popdd" class="func_name">popdd</a> <a href="#popop" class="func_name">popop</a> <a href="#popopop" class="func_name">popopop</a> <a href="#size" class="func_name">size</a> <a href="#small" class="func_name">small</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a> <a href="#take" class="func_name">take</a> <a href="#unstack" class="func_name">unstack</a> <a href="#zip" class="func_name">zip</a></div></div><hr><div><h2 id="popd" class="func_name">popd <a href="#popd" class="self_link"></a></h2><p></p><div class="notes"><p>[pop] the second item down on the stack.</p>
<pre><code> a b popd
--------------
b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#pop">pop</a>] <a href="#dip">dip</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#pop" class="func_name">pop</a> <a href="#popdd" class="func_name">popdd</a> <a href="#popop" class="func_name">popop</a> <a href="#popopd" class="func_name">popopd</a> <a href="#popopdd" class="func_name">popopdd</a> <a href="#popopop" class="func_name">popopop</a></div><div class="backlinks"><h3>Used By</h3><a href="#binary" class="func_name">binary</a> <a href="#choice" class="func_name">choice</a> <a href="#grba" class="func_name">grba</a> <a href="#" class="func_name">max-of-two</a> <a href="#" class="func_name">min-of-two</a> <a href="#rest" class="func_name">rest</a> <a href="#ternary" class="func_name">ternary</a> <a href="#unary" class="func_name">unary</a></div></div><hr><div><h2 id="popdd" class="func_name">popdd <a href="#popdd" class="self_link"></a></h2><p></p><div class="notes"><p>[pop] the third item on the stack.</p>
<pre><code> a b c popdd
-----------------
b c
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#pop">pop</a>] <a href="#dipd">dipd</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#pop" class="func_name">pop</a> <a href="#popd" class="func_name">popd</a> <a href="#popop" class="func_name">popop</a> <a href="#popopd" class="func_name">popopd</a> <a href="#popopdd" class="func_name">popopdd</a> <a href="#popopop" class="func_name">popopop</a></div><div class="backlinks"><h3>Used By</h3><a href="#cleave" class="func_name">cleave</a> <a href="#clop" class="func_name">clop</a></div></div><hr><div><h2 id="popop" class="func_name">popop <a href="#popop" class="self_link"></a></h2><p></p><div class="notes"><p>[pop] two items from the stack.</p>
<pre><code> a b popop
---------------
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#pop">pop</a> <a href="#pop">pop</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#pop" class="func_name">pop</a> <a href="#popd" class="func_name">popd</a> <a href="#popdd" class="func_name">popdd</a> <a href="#popopd" class="func_name">popopd</a> <a href="#popopdd" class="func_name">popopdd</a> <a href="#popopop" class="func_name">popopop</a></div><div class="backlinks"><h3>Used By</h3><a href="#popopd" class="func_name">popopd</a> <a href="#popopdd" class="func_name">popopdd</a> <a href="#popopop" class="func_name">popopop</a></div></div><hr><div><h2 id="popopd" class="func_name">popopd <a href="#popopd" class="self_link"></a></h2><p></p><div class="notes"><p>[pop] the second and third items from the stack.</p>
<pre><code> a b c popopd
------------------
c
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#popop">popop</a>] <a href="#dip">dip</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#pop" class="func_name">pop</a> <a href="#popd" class="func_name">popd</a> <a href="#popdd" class="func_name">popdd</a> <a href="#popop" class="func_name">popop</a> <a href="#popopdd" class="func_name">popopdd</a> <a href="#popopop" class="func_name">popopop</a></div></div><hr><div><h2 id="popopdd" class="func_name">popopdd <a href="#popopdd" class="self_link"></a></h2><p></p><div class="notes"><pre><code> a b c d popopdd
---------------------
c d
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#popop">popop</a>] <a href="#dipd">dipd</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#pop" class="func_name">pop</a> <a href="#popd" class="func_name">popd</a> <a href="#popdd" class="func_name">popdd</a> <a href="#popop" class="func_name">popop</a> <a href="#popopd" class="func_name">popopd</a> <a href="#popopop" class="func_name">popopop</a></div></div><hr><div><h2 id="popopop" class="func_name">popopop <a href="#popopop" class="self_link"></a></h2><p></p><div class="notes"><p>[pop] three items from the stack.</p>
<pre><code> a b c popopop
-------------------
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#pop">pop</a> <a href="#popop">popop</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#pop" class="func_name">pop</a> <a href="#popd" class="func_name">popd</a> <a href="#popdd" class="func_name">popdd</a> <a href="#popop" class="func_name">popop</a> <a href="#popopd" class="func_name">popopd</a> <a href="#popopdd" class="func_name">popopdd</a></div></div><hr><div><h2 id="pow" class="func_name">pow <a href="#pow" class="self_link"></a></h2><p></p><div class="notes"><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>
<pre><code> a n pow
-------------
(aⁿ)
</code></pre>
<h3>Example</h3>
<pre><code> 2 [2 3 4 5 6 7 8 9] [pow] map
-----------------------------------
2 [4 8 16 32 64 128 256 512]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">1 <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll&gt;</a> <a href="#swap">swap</a> [<a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#cons">cons</a> <a href="#times">times</a></div></div></div><hr><div><h2 id="pred" class="func_name">pred <a href="#pred" class="self_link"></a></h2><p></p><div class="notes"><p>Predecessor. Decrement TOS.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#succ" class="func_name">succ</a></div></div><hr><div><h2 id="primrec" class="func_name">primrec <a href="#primrec" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>From the <a href="https://www.kevinalbrecht.com/code/joy-mirror/j00ovr.html">"Overview of the language JOY"</a></p>
<blockquote>
<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>
<p>5 [1] [*] primrec</p>
<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>
</blockquote>
<pre><code> 0 [Base] [Recur] primrec
------------------------------
Base
n [Base] [Recur] primrec
------------------------------------------ n &gt; 0
n (n-1) [Base] [Recur] primrec Recur
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Simple and useful specialization of the [genrec] combinator from the
<a href="https://www.kevinalbrecht.com/code/joy-mirror/index.html">original Joy system</a>.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#genrec" class="func_name">genrec</a> <a href="#tailrec" class="func_name">tailrec</a></div></div><hr><div><h2 id="product" class="func_name">product <a href="#product" class="self_link"></a></h2><p></p><div class="notes"><p>Just as [sum] sums a list of numbers, this function multiplies them
together.</p>
<h3>Definition</h3>
<blockquote>
<p>1 [swap] [[mul]] [step]</p>
</blockquote>
<p>Or,</p>
<blockquote>
<p>[1] [[mul]] [primrec]</p>
</blockquote></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">1 <a href="#swap">swap</a> [<a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#step">step</a></div></div></div><hr><div><h2 id="quoted" class="func_name">quoted <a href="#quoted" class="self_link"></a></h2><p></p><div class="notes"><p>"Quote D" Wrap the second item on the stack in a list.</p>
<pre><code> a b quoted
----------------
[a] b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#unit">unit</a>] <a href="#dip">dip</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This comes from the original Joy stuff.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#unit" class="func_name">unit</a></div></div><hr><div><h2 id="range" class="func_name">range <a href="#range" class="self_link"></a></h2><p></p><div class="notes"><p>Expect a number <code>n</code> on the stack and replace it with a list:
<code>[(n-1)...0]</code>.</p>
<h3>Example</h3>
<pre><code> 5 range
-----------------
[4 3 2 1 0]
-5 range
--------------
[]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[0 <a href="#b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866">&lt;=</a>] [<a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a> <a href="#dup">dup</a>] <a href="#anamorphism">anamorphism</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>If <code>n</code> is less than 1 the resulting list is empty.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero</a></div></div><hr><div><h2 id="ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero <a href="#ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="self_link"></a></h2><p></p><div class="notes"><p>Take a number <code>n</code> from the stack and replace it with a list
<code>[0...n]</code>.</p>
<h3>Example</h3>
<pre><code> 5 range_to_zero
---------------------
[0 1 2 3 4 5]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#unit">unit</a> [<a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d">down_to_zero</a>] <a href="#infra">infra</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Note that the order is reversed compared to [range].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#range" class="func_name">range</a></div></div><hr><div><h2 id="reco" class="func_name">reco <a href="#reco" class="self_link"></a></h2><p></p><div class="notes"><p>Replace the first item in a list with the item under it.</p>
<pre><code> a [b ...] reco
--------------------
[a ...]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#rest">rest</a> <a href="#cons">cons</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#codireco" class="func_name">codireco</a> <a href="#766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator</a></div><div class="backlinks"><h3>Used By</h3><a href="#codireco" class="func_name">codireco</a></div></div><hr><div><h2 id="rem" class="func_name">rem <a href="#rem" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#mod">mod</a>.</p></div></div><hr><div><h2 id="remainder" class="func_name">remainder <a href="#remainder" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>See <a href="#mod">mod</a>.</p></div></div><hr><div><h2 id="remove" class="func_name">remove <a href="#remove" class="self_link"></a></h2><p></p><div class="notes"><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't in the list then the list is unchanged.</p>
<pre><code> [1 2 3 1] 1 remove
------------------------
[2 3 1]
</code></pre>
<h3>Definition</h3>
<p>See the <a href="https://osdn.net/projects/joypy/scm/git/Thun/blobs/master/docs/notebooks/Remove-Function.ipynb">"Remove Function" notebook</a>.</p></div></div><hr><div><h2 id="rest" class="func_name">rest <a href="#rest" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><pre><code> [a ...] rest
------------------
[...]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#uncons">uncons</a> <a href="#popd">popd</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#first" class="func_name">first</a> <a href="#uncons" class="func_name">uncons</a></div><div class="backlinks"><h3>Used By</h3><a href="#drop" class="func_name">drop</a> <a href="#fourth" class="func_name">fourth</a> <a href="#getitem" class="func_name">getitem</a> <a href="#reco" class="func_name">reco</a> <a href="#rrest" class="func_name">rrest</a> <a href="#second" class="func_name">second</a> <a href="#small" class="func_name">small</a> <a href="#third" class="func_name">third</a> <a href="#uncons" class="func_name">uncons</a></div></div><hr><div><h2 id="reverse" class="func_name">reverse <a href="#reverse" class="self_link"></a></h2><p></p><div class="notes"><p>Reverse the list on the top of the stack.</p>
<h3>Example</h3>
<pre><code> [1 2 3] reverse
---------------------
[3 2 1]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a> <a href="#shunt">shunt</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#appN" class="func_name">appN</a> <a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="func_name">roll&lt; <a href="#2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="self_link"></a></h2><p></p><div class="notes"><p>See <a href="#rolldown">rolldown</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#swapd">swapd</a> <a href="#swap">swap</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#rolldown" class="func_name">rolldown</a></div></div><hr><div><h2 id="93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll&gt; <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="self_link"></a></h2><p></p><div class="notes"><p>See <a href="#rollup">rollup</a>.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#swap">swap</a> <a href="#swapd">swapd</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#pow" class="func_name">pow</a> <a href="#rollup" class="func_name">rollup</a> <a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="func_name">step_zero</a></div></div><hr><div><h2 id="rolldown" class="func_name">rolldown <a href="#rolldown" class="self_link"></a></h2><p></p><div class="notes"><pre><code> a b c rolldown
--------------------
b c a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd">roll&lt;</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#rollup" class="func_name">rollup</a></div></div><hr><div><h2 id="rollup" class="func_name">rollup <a href="#rollup" class="self_link"></a></h2><p></p><div class="notes"><pre><code> a b c rollup
------------------
c a b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll&gt;</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#rolldown" class="func_name">rolldown</a></div><div class="backlinks"><h3>Used By</h3><a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name">&lt;&lt;{}</a></div></div><hr><div><h2 id="rrest" class="func_name">rrest <a href="#rrest" class="self_link"></a></h2><p></p><div class="notes"><pre><code> [a b ...] rrest
---------------------
[...]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#rest">rest</a> <a href="#rest">rest</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#rest" class="func_name">rest</a></div></div><hr><div><h2 id="rshift" class="func_name">rshift <a href="#rshift" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p><a href="https://en.wikipedia.org/wiki/Logical_shift">Logical Right-Shift</a></p>
<pre><code> a n rshift
----------------
(a2ⁿ)
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[2 <a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a>] <a href="#times">times</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#lshift" class="func_name">lshift</a></div><div class="backlinks"><h3>Used By</h3><a href="#0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="func_name">&gt;&gt;</a></div></div><hr><div><h2 id="run" class="func_name">run <a href="#run" class="self_link"></a></h2><p></p><div class="notes"><p>Run a quoted program in a list.</p>
<h3>Example</h3>
<pre><code> [1 2 +] run
-----------------
[3]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a> <a href="#infra">infra</a></div></div></div><hr><div><h2 id="second" class="func_name">second <a href="#second" class="self_link"></a></h2><p></p><div class="notes"><pre><code> [a b ...] second
----------------------
b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#rest">rest</a> <a href="#first">first</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#first" class="func_name">first</a> <a href="#third" class="func_name">third</a> <a href="#fourth" class="func_name">fourth</a></div><div class="backlinks"><h3>Used By</h3><a href="#third" class="func_name">third</a></div></div><hr><div><h2 id="select" class="func_name">select <a href="#select" class="self_link"></a></h2><p></p><div class="notes"><p>Use a Boolean value to select one of two items from a sequence. :</p>
<pre><code> [a b] false select
------------------------
a
[a b] true select
-----------------------
b
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>The sequence can contain more than two items but not fewer.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#choice" class="func_name">choice</a></div></div><hr><div><h2 id="sharing" class="func_name">sharing <a href="#sharing" class="self_link"></a></h2><p></p><div class="notes"><p>Print redistribution information.</p></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Mathematically this is a form of [id], but it has the side-effect of
printing out the GPL notice.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#warranty" class="func_name">warranty</a></div></div><hr><div><h2 id="shift" class="func_name">shift <a href="#shift" class="self_link"></a></h2><p></p><div class="notes"><p>Move the top item from one list to another.</p>
<h3>Example</h3>
<pre><code> [x y z] [a b c] shift
---------------------------
[a x y z] [b c]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#uncons">uncons</a> [<a href="#swons">swons</a>] <a href="#dip">dip</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#shunt" class="func_name">shunt</a></div><div class="backlinks"><h3>Used By</h3><a href="#take" class="func_name">take</a></div></div><hr><div><h2 id="shunt" class="func_name">shunt <a href="#shunt" class="self_link"></a></h2><p></p><div class="notes"><p>Like [concat] but [reverse] the top list into the second.</p>
<h3>Example</h3>
<pre><code> [a b c] [d e f] shunt
---------------------------
[f e d a b c]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#swons">swons</a>] <a href="#step">step</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is more efficient than [concat] so prefer it if you don't need to
preserve order.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#concat" class="func_name">concat</a> <a href="#reverse" class="func_name">reverse</a> <a href="#shift" class="func_name">shift</a></div><div class="backlinks"><h3>Used By</h3><a href="#reverse" class="func_name">reverse</a></div></div><hr><div><h2 id="size" class="func_name">size <a href="#size" class="self_link"></a></h2><p></p><div class="notes"><p>Replace a list with its size.</p>
<h3>Example</h3>
<pre><code> [23 [cats] 4] size
------------------------
3
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#pop">pop</a> <a href="#cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a>] <a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482">step_zero</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#average" class="func_name">average</a></div></div><hr><div><h2 id="small" class="func_name">small <a href="#small" class="self_link"></a></h2><p></p><div class="notes"><p>Return <code>true</code> if the item on the top of the stack is a list with zero or one item in it,
<code>false</code> if it is a list with more than one item in it,
and an error if it is not a list.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dup">dup</a> <a href="#null">null</a> [<a href="#rest">rest</a> <a href="#null">null</a>] [<a href="#pop">pop</a> true] <a href="#branch">branch</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#null" class="func_name">null</a></div></div><hr><div><h2 id="sort" class="func_name">sort <a href="#sort" class="self_link"></a></h2><p></p><div class="notes"><p>Given a list return it sorted.</p>
<h3>Example</h3>
<pre><code> [4 2 5 7 1] sort
----------------------
[1 2 4 5 7]
</code></pre></div></div><hr><div><h2 id="b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="self_link"></a></h2><p></p><div class="notes"><p>Example code.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[[[<a href="#abs">abs</a>] <a href="#ii">ii</a> <a href="#b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866">&lt;=</a>] [[<a href="#24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64">&lt;&gt;</a>] [<a href="#pop">pop</a> <a href="#e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a>] <a href="#or">or</a>] <a href="#and">and</a>] [[<a href="#e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a>] [[<a href="#cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a>]] [[<a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a>]] <a href="#ifte">ifte</a> <a href="#dip">dip</a>] [[<a href="#pop">pop</a> <a href="#e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a>] [<a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a>] [<a href="#cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a>] <a href="#ifte">ifte</a>] <a href="#ifte">ifte</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>See the <a href="https://joypy.osdn.io/notebooks/Square_Spiral.html">"Square Spiral Example Joy Code" notebook</a>.</p></div></div></div><hr><div><h2 id="11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at <a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="self_link"></a></h2><p></p><div class="notes"><p>Split a list (second on the stack) at the position given by the number on
the top of the stack.</p>
<h3>Example</h3>
<pre><code> [1 2 3 4 5 6 7] 4 split_at
--------------------------------
[5 6 7] [4 3 2 1]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#drop">drop</a>] [<a href="#take">take</a>] <a href="#clop">clop</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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 [shunt] them onto a new list that replaces the number <code>n</code>
on the top of the stack.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list <a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="self_link"></a></h2><p></p><div class="notes"><p>Split a list (second on the stack) at the position given by the number on
the top of the stack such that [concat] would reconstruct the original
list.</p>
<pre><code> [1 2 3 4 5 6 7] 4 split_list
----------------------------------
[1 2 3 4] [5 6 7]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#take">take</a> <a href="#reverse">reverse</a>] [<a href="#drop">drop</a>] <a href="#clop">clop</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Compare with [split_at]. This function does extra work to ensure that
[concat] would reconstruct the original list.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a></div></div><hr><div><h2 id="sqr" class="func_name">sqr <a href="#sqr" class="self_link"></a></h2><p></p><div class="notes"><p>Square the number on the top of the stack.</p>
<pre><code> n sqr
------------
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dup">dup</a> <a href="#mul">mul</a></div></div></div><hr><div><h2 id="stack" class="func_name">stack <a href="#stack" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Put the stack onto the stack.</p>
<pre><code> ... c b a stack
---------------------------
... c b a [a b c ...]
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This function forms a pair with [unstack], and together they form the
complement to the "destructive" pair [enstacken] and [disenstacken].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#enstacken" class="func_name">enstacken</a> <a href="#disenstacken" class="func_name">disenstacken</a> <a href="#stackd" class="func_name">stackd</a> <a href="#unstack" class="func_name">unstack</a></div><div class="backlinks"><h3>Used By</h3><a href="#enstacken" class="func_name">enstacken</a> <a href="#grba" class="func_name">grba</a> <a href="#nullary" class="func_name">nullary</a> <a href="#stackd" class="func_name">stackd</a> <a href="#stuncons" class="func_name">stuncons</a></div></div><hr><div><h2 id="stackd" class="func_name">stackd <a href="#stackd" class="self_link"></a></h2><p></p><div class="notes"><p>Grab the stack under the top item and put it onto the stack.</p>
<h3>Example</h3>
<pre><code> ... 1 2 3 stackd
------------------------
... 1 2 [2 1 ...] 3
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#stack">stack</a>] <a href="#dip">dip</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#stack" class="func_name">stack</a></div></div><hr><div><h2 id="step" class="func_name">step <a href="#step" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run a quoted program on each item in a sequence.</p>
<pre><code> ... [] [Q] step
---------------------
...
... [a] [Q] step
----------------------
... a Q
... [a b c] [Q] . step
----------------------------------------
... a . Q [b c] [Q] step
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#">_step0</a>] <a href="#x">x</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="func_name">step_zero</a></div><div class="backlinks"><h3>Used By</h3><a href="#flatten" class="func_name">flatten</a> <a href="#max" class="func_name">max</a> <a href="#min" class="func_name">min</a> <a href="#product" class="func_name">product</a> <a href="#shunt" class="func_name">shunt</a> <a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="func_name">step_zero</a></div></div><hr><div><h2 id="edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="func_name">step_zero <a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Like [step] but with 0 as the initial value.</p>
<pre><code> [...] [F] step_zero
-------------------------
0 [...] [F] step
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">0 <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll&gt;</a> <a href="#step">step</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>[size] and [sum] can both be defined in terms of this specialization of
[step].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#step" class="func_name">step</a></div><div class="backlinks"><h3>Used By</h3><a href="#size" class="func_name">size</a> <a href="#sum" class="func_name">sum</a></div></div><hr><div><h2 id="stuncons" class="func_name">stuncons <a href="#stuncons" class="self_link"></a></h2><p></p><div class="notes"><p>Take the [stack] and [uncons] the top item.</p>
<h3>Example</h3>
<pre><code> 1 2 3 stuncons
--------------------
1 2 3 3 [2 1]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#stack">stack</a> <a href="#uncons">uncons</a></div></div></div><hr><div><h2 id="stununcons" class="func_name">stununcons <a href="#stununcons" class="self_link"></a></h2><p></p><div class="notes"><p>Take the [stack] and [uncons] the top two items.</p>
<h3>Example</h3>
<pre><code> 1 2 3 stununcons
----------------------
1 2 3 3 2 [1]
</code></pre></div><div class="crosslinks"><h3>See Also</h3><a href="#stuncons" class="func_name">stuncons</a></div></div><hr><div><h2 id="sub" class="func_name">sub <a href="#sub" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Subtract the number on the top of the stack from the number below it.</p>
<pre><code> a b sub
-------------
(a-b)
</code></pre></div><div class="crosslinks"><h3>See Also</h3><a href="#add" class="func_name">add</a></div></div><hr><div><h2 id="succ" class="func_name">succ <a href="#succ" class="self_link"></a></h2><p></p><div class="notes"><p>Successor. Increment TOS.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#pred" class="func_name">pred</a></div></div><hr><div><h2 id="sum" class="func_name">sum <a href="#sum" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Given a quoted sequence of numbers return the sum.</p>
<h3>Example</h3>
<pre><code> [1 2 3 4 5] sum
---------------------
15
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a>] <a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482">step_zero</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#size" class="func_name">size</a></div><div class="backlinks"><h3>Used By</h3><a href="#average" class="func_name">average</a></div></div><hr><div><h2 id="swaack" class="func_name">swaack <a href="#swaack" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><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>
<h3>Example</h3>
<pre><code> 1 2 3 [4 5 6] swaack
--------------------------
6 5 4 [3 2 1]
</code></pre></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This function works as a kind of "context switch". It's used in the
definition of [infra].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#infra" class="func_name">infra</a></div><div class="backlinks"><h3>Used By</h3><a href="#clear" class="func_name">clear</a> <a href="#disenstacken" class="func_name">disenstacken</a> <a href="#infra" class="func_name">infra</a> <a href="#unstack" class="func_name">unstack</a></div></div><hr><div><h2 id="swap" class="func_name">swap <a href="#swap" class="self_link"></a></h2><p><span class="kind">built-in</span></p><div class="notes"><p>Swap the top two items on the stack.</p>
<pre><code> a b swap
--------------
b a
</code></pre></div><div class="crosslinks"><h3>See Also</h3><a href="#swapd" class="func_name">swapd</a></div><div class="backlinks"><h3>Used By</h3><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="func_name">&lt;{}</a> <a href="#anamorphism" class="func_name">anamorphism</a> <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#cmp" class="func_name">cmp</a> <a href="#ifte" class="func_name">ifte</a> <a href="#neg" class="func_name">neg</a> <a href="#of" class="func_name">of</a> <a href="#over" class="func_name">over</a> <a href="#pow" class="func_name">pow</a> <a href="#product" class="func_name">product</a> <a href="#2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="func_name">roll&lt;</a> <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll&gt;</a> <a href="#swapd" class="func_name">swapd</a> <a href="#swoncat" class="func_name">swoncat</a> <a href="#swons" class="func_name">swons</a> <a href="#unswons" class="func_name">unswons</a> <a href="#while" class="func_name">while</a></div></div><hr><div><h2 id="swapd" class="func_name">swapd <a href="#swapd" class="self_link"></a></h2><p></p><div class="notes"><p>Swap the second and third items on the stack.</p>
<pre><code> a b c swapd
-----------------
b a c
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#swap">swap</a>] <a href="#dip">dip</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#over" class="func_name">over</a> <a href="#tuck" class="func_name">tuck</a></div><div class="backlinks"><h3>Used By</h3><a href="#2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="func_name">roll&lt;</a> <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll&gt;</a> <a href="#tuck" class="func_name">tuck</a> <a href="#" class="func_name">uncons-two</a></div></div><hr><div><h2 id="swoncat" class="func_name">swoncat <a href="#swoncat" class="self_link"></a></h2><p></p><div class="notes"><p>[concat] two lists, but [swap] the lists first.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#swap">swap</a> <a href="#concat">concat</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#concat" class="func_name">concat</a></div><div class="backlinks"><h3>Used By</h3><a href="#unstack" class="func_name">unstack</a></div></div><hr><div><h2 id="swons" class="func_name">swons <a href="#swons" class="self_link"></a></h2><p></p><div class="notes"><p>Like [cons] but [swap] the item and list.</p>
<pre><code> [...] a swons
-------------------
[a ...]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#swap">swap</a> <a href="#cons">cons</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#anamorphism" class="func_name">anamorphism</a> <a href="#cmp" class="func_name">cmp</a> <a href="#genrec" class="func_name">genrec</a> <a href="#infra" class="func_name">infra</a> <a href="#shift" class="func_name">shift</a> <a href="#shunt" class="func_name">shunt</a></div></div><hr><div><h2 id="tailrec" class="func_name">tailrec <a href="#tailrec" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>A specialization of the [genrec] combinator.</p></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#i">i</a>] <a href="#genrec">genrec</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><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">"tail recursive" functions</a>. In Joy,
they appear as [genrec] definitions that have [i] for the second half of
their recursive branch.
See the <a href="https://joypy.osdn.io/notebooks/Recursion_Combinators.html">Recursion Combinators notebook</a>.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#genrec" class="func_name">genrec</a></div><div class="backlinks"><h3>Used By</h3><a href="#map" class="func_name">map</a></div></div><hr><div><h2 id="take" class="func_name">take <a href="#take" class="self_link"></a></h2><p></p><div class="notes"><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>
<pre><code> [a b c d] 2 take
----------------------
[b a]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108">&lt;&lt;{}</a> [<a href="#shift">shift</a>] <a href="#times">times</a> <a href="#pop">pop</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="ternary" class="func_name">ternary <a href="#ternary" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Run a quoted program using exactly three stack values and leave the first
item of the result on the stack.</p>
<pre><code> ... z y x [P] ternary
-------------------------
... a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#binary">binary</a> <a href="#popd">popd</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Runs any other quoted function and returns its first result while
consuming exactly three items from the stack.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#binary" class="func_name">binary</a> <a href="#nullary" class="func_name">nullary</a> <a href="#unary" class="func_name">unary</a></div></div><hr><div><h2 id="third" class="func_name">third <a href="#third" class="self_link"></a></h2><p></p><div class="notes"><pre><code> [a b c ...] third
-----------------------
c
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#rest">rest</a> <a href="#second">second</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#first" class="func_name">first</a> <a href="#second" class="func_name">second</a> <a href="#fourth" class="func_name">fourth</a> <a href="#rest" class="func_name">rest</a></div><div class="backlinks"><h3>Used By</h3><a href="#fourth" class="func_name">fourth</a></div></div><hr><div><h2 id="times" class="func_name">times <a href="#times" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Expect a quoted program and an integer <code>n</code> on the stack and do the
program <code>n</code> times.</p>
<pre><code> ... n [Q] . times
----------------------- w/ n &lt;= 0
... .
... 1 [Q] . times
-----------------------
... . Q
... n [Q] . times
------------------------------------- w/ n &gt; 1
... . Q (n-1) [Q] times
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#">_times0</a>] <a href="#x">x</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3>This works by building a little [while] program and running it:
1 3 [++] • [-- dip] cons [swap] infra [0 &gt;] swap while pop
1 3 [++] [-- dip] • cons [swap] infra [0 &gt;] swap while pop
1 3 [[++] -- dip] • [swap] infra [0 &gt;] swap while pop
1 3 [[++] -- dip] [swap] • infra [0 &gt;] swap while pop
dip -- [++] • swap [3 1] swaack [0 &gt;] swap while pop
dip [++] -- • [3 1] swaack [0 &gt;] swap while pop
dip [++] -- [3 1] • swaack [0 &gt;] swap while pop
1 3 [-- [++] dip] • [0 &gt;] swap while pop
1 3 [-- [++] dip] [0 &gt;] • swap while pop
1 3 [0 &gt;] [-- [++] dip] • while pop
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.</div><div class="backlinks"><h3>Used By</h3><a href="#drop" class="func_name">drop</a> <a href="#getitem" class="func_name">getitem</a> <a href="#grabN" class="func_name">grabN</a> <a href="#lshift" class="func_name">lshift</a> <a href="#pow" class="func_name">pow</a> <a href="#rshift" class="func_name">rshift</a> <a href="#take" class="func_name">take</a></div></div><hr><div><h2 id="tuck" class="func_name">tuck <a href="#tuck" class="self_link"></a></h2><p></p><div class="notes"><p>[dup] the item on the top of the stack under the second item on the
stack.</p>
<pre><code> a b tuck
--------------
b a b
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dup">dup</a> <a href="#swapd">swapd</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#over" class="func_name">over</a></div><div class="backlinks"><h3>Used By</h3><a href="#gcd" class="func_name">gcd</a></div></div><hr><div><h2 id="unary" class="func_name">unary <a href="#unary" class="self_link"></a></h2><p></p><div class="notes"><p>(Combinator)</p>
<p>Run a quoted program using exactly one stack value and leave the first
item of the result on the stack.</p>
<pre><code> ... x [P] unary
---------------------
... a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#nullary">nullary</a> <a href="#popd">popd</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Runs any other quoted function and returns its first result while
consuming exactly one item from the stack.</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#binary" class="func_name">binary</a> <a href="#nullary" class="func_name">nullary</a> <a href="#ternary" class="func_name">ternary</a></div><div class="backlinks"><h3>Used By</h3><a href="#binary" class="func_name">binary</a></div></div><hr><div><h2 id="uncons" class="func_name">uncons <a href="#uncons" class="self_link"></a></h2><p></p><div class="notes"><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>
<pre><code> [a ...] uncons
--------------------
a [...]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#first">first</a>] <a href="#dupdip">dupdip</a> <a href="#rest">rest</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>This is the inverse of [cons].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#cons" class="func_name">cons</a></div><div class="backlinks"><h3>Used By</h3><a href="#first" class="func_name">first</a> <a href="#07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two</a> <a href="#max" class="func_name">max</a> <a href="#min" class="func_name">min</a> <a href="#rest" class="func_name">rest</a> <a href="#shift" class="func_name">shift</a> <a href="#stuncons" class="func_name">stuncons</a> <a href="#" class="func_name">uncons-two</a> <a href="#unswons" class="func_name">unswons</a></div></div><hr><div><h2 id="unique" class="func_name">unique <a href="#unique" class="self_link"></a></h2><p></p><div class="notes"><p>Given a list remove duplicate items.</p></div></div><hr><div><h2 id="unit" class="func_name">unit <a href="#unit" class="self_link"></a></h2><p></p><div class="notes"><pre><code> a unit
------------
[a]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[] <a href="#cons">cons</a></div></div><div class="backlinks"><h3>Used By</h3><a href="#" class="func_name">quote-two</a> <a href="#quoted" class="func_name">quoted</a> <a href="#ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero</a></div></div><hr><div><h2 id="unquoted" class="func_name">unquoted <a href="#unquoted" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Unquote (using [i]) the list that is second on the stack.</p>
<h3>Example</h3>
<pre><code> 1 2 [3 4] 5 unquoted
--------------------------
1 2 3 4 5
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#i">i</a>] <a href="#dip">dip</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#unit" class="func_name">unit</a></div></div><hr><div><h2 id="unstack" class="func_name">unstack <a href="#unstack" class="self_link"></a></h2><p></p><div class="notes"><p>Take a list from the top of the stack and <code>concat</code> it to the stack.</p>
<pre><code>joy? 1 2 3 [4 5 6]
1 2 3 [4 5 6]
joy? unstack
1 2 3 6 5 4
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[[] <a href="#swaack">swaack</a>] <a href="#dip">dip</a> <a href="#swoncat">swoncat</a> <a href="#swaack">swaack</a> <a href="#pop">pop</a></div></div><div class="crosslinks"><h3>See Also</h3><a href="#stack" class="func_name">stack</a> <a href="#disenstacken" class="func_name">disenstacken</a> <a href="#enstacken" class="func_name">enstacken</a></div></div><hr><div><h2 id="unswons" class="func_name">unswons <a href="#unswons" class="self_link"></a></h2><p></p><div class="notes"><pre><code> [a ...] unswons
---------------------
[...] a
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#uncons">uncons</a> <a href="#swap">swap</a></div></div></div><hr><div><h2 id="void" class="func_name">void <a href="#void" class="self_link"></a></h2><p></p><div class="notes"><p>True if the form on TOS is void otherwise False.</p></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>A form is any Joy expression composed solely of lists.
This represents a binary Boolean logical formula in the arithmetic of the
"Laws of Form", see <a href="http://www.markability.net/">The Markable Mark</a></p></div></div></div><hr><div><h2 id="warranty" class="func_name">warranty <a href="#warranty" class="self_link"></a></h2><p></p><div class="notes"><p>Print warranty information.</p></div></div><hr><div><h2 id="while" class="func_name">while <a href="#while" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>A specialization of [loop] that accepts a quoted predicate program <code>P</code>
and runs it [nullary].</p>
<pre><code> [P] [F] while
------------------- P -&gt; false
[P] [F] while
--------------------- P -&gt; true
F [P] [F] while
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><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></div></div><div class="crosslinks"><h3>See Also</h3><a href="#loop" class="func_name">loop</a></div><div class="backlinks"><h3>Used By</h3><a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a></div></div><hr><div><h2 id="words" class="func_name">words <a href="#words" class="self_link"></a></h2><p></p><div class="notes"><p>Print all the words in alphabetical order.</p></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>Mathematically this is a form of [id].</p></div></div><div class="crosslinks"><h3>See Also</h3><a href="#help" class="func_name">help</a></div></div><hr><div><h2 id="x" class="func_name">x <a href="#x" class="self_link"></a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Take a quoted function <code>F</code> and run it with itself as the first item on
the stack.</p>
<pre><code> [F] x
-----------
[F] F
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition"><a href="#dup">dup</a> <a href="#i">i</a></div></div><div class="discussion_wrapper"><h3>Discussion</h3><div class="discussion"><p>The simplest recursive pattern.
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></div></div><div class="backlinks"><h3>Used By</h3><a href="#step" class="func_name">step</a> <a href="#times" class="func_name">times</a></div></div><hr><div><h2 id="zip" class="func_name">zip <a href="#zip" class="self_link"></a></h2><p></p><div class="notes"><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>
<h3>Example</h3>
<pre><code> [1 2 3] [4 5 6] zip
-------------------------
[[1 4] [2 5] [3 6]]
</code></pre></div><div class="definition_wrapper"><h3>Definition</h3><div class="definition">[<a href="#null">null</a>] [<a href="#pop">pop</a>] [<a href="#">uncons-pair</a>] [<a href="#i">i</a> <a href="#cons">cons</a>] <a href="#genrec">genrec</a></div></div></div></body></html>