952 lines
149 KiB
HTML
952 lines
149 KiB
HTML
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Thun Function Reference</title><link rel="stylesheet" href="/css/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="#951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338">&</a></li> <li><a href="#73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef">&&</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="#a2c2339691fc48fbd14fb307292dff3e21222712d9240810742d7df0c6d74dfb">//</a></li> <li><a href="#25fec5b6fc916113006299298a2df014df5c407ebb11013f36163d3ec1cc1c53">/floor</a></li> <li><a href="#dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72"><</a></li> <li><a href="#4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e"><<</a></li> <li><a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108"><<{}</a></li> <li><a href="#b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866"><=</a></li> <li><a href="#24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64"><></a></li> <li><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7"><{}</a></li> <li><a href="#380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3">=</a></li> <li><a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">></a></li> <li><a href="#92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f">>=</a></li> <li><a href="#0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44">>></a></li> <li><a href="#8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1">?</a></li> <li><a href="#74cd9ef9c7e15f57bdad73c511462ca65cb674c46c49639c60f1b44650fa1dcb">^</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="#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="#floor">floor</a></li> <li><a href="#floordiv">floordiv</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="#ab323e8d4f8c5d1c7d333fbe3e08b223c11f7bcc5066ace0af17172f77aa31b3">gcd2</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="#hypot">hypot</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="#ne">ne</a></li> <li><a href="#neg">neg</a></li> <li><a href="#not">not</a></li> <li><a href="#nulco">nulco</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<</a></li> <li><a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll></a></li> <li><a href="#rolldown">rolldown</a></li> <li><a href="#rollup">rollup</a></li> <li><a href="#round">round</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="#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="#sqrt">sqrt</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="#truthy">truthy</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="#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="#xor">xor</a></li> <li><a href="#zip">zip</a></li> <li><a href="#565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866">||</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 < 0
|
||
false
|
||
|
||
|
||
n !-
|
||
---------- n >= 0
|
||
true
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote><a href="#">0</a> <a href="#92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f">>=</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Return a Boolean value indicating if a number is greater than or equal to
|
||
zero.</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></p><div class="notes"><p>See <a href="#ne">ne</a>.</p></div></div><hr><div><h2 id="bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec" class="func_name">% <a href="#bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec" class="self_link">¶</a></h2><p></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></div></div><hr><div><h2 id="951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338" class="func_name">& <a href="#951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#and">and</a>.</p></div></div><hr><div><h2 id="73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" class="func_name">&& <a href="#73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" 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.)</p>
|
||
<pre><code> [A] [B] &&
|
||
---------------- true
|
||
B
|
||
|
||
|
||
[A] [B] &&
|
||
---------------- false
|
||
false
|
||
</code></pre>
|
||
<h3>Definition</h3>
|
||
<pre><code>nulco [nullary [false]] dip branch
|
||
</code></pre>
|
||
<h3>Derivation</h3>
|
||
<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="discussion"><h3>Discussion</h3>This is seldom useful, I suspect, but this way you have it.</div><div class="crosslinks"><h3>See Also</h3><a href="#565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866" class="func_name">||</a></div></div><hr><div><h2 id="684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1" class="func_name">* <a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1" class="self_link">¶</a></h2><p></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></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="#hypot" class="func_name">hypot</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"><h3>Definition</h3><blockquote><a href="#">1</a> <a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a></blockquote></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></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"><h3>Definition</h3><blockquote><a href="#">1</a> <a href="#3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#range" class="func_name">range</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1" class="func_name">/ <a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#floordiv">floordiv</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="a2c2339691fc48fbd14fb307292dff3e21222712d9240810742d7df0c6d74dfb" class="func_name">// <a href="#a2c2339691fc48fbd14fb307292dff3e21222712d9240810742d7df0c6d74dfb" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#floordiv">floordiv</a>.</p></div></div><hr><div><h2 id="25fec5b6fc916113006299298a2df014df5c407ebb11013f36163d3ec1cc1c53" class="func_name">/floor <a href="#25fec5b6fc916113006299298a2df014df5c407ebb11013f36163d3ec1cc1c53" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#floordiv">floordiv</a>.</p></div></div><hr><div><h2 id="dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72" class="func_name">< <a href="#dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72" class="self_link">¶</a></h2><p></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></div></div><hr><div><h2 id="4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="func_name"><< <a href="#4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#lshift">lshift</a>.</p></div><div class="definition"><h3>Definition</h3><blockquote><a href="#lshift">lshift</a></blockquote></div></div><hr><div><h2 id="c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name"><<{} <a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="self_link">¶</a></h2><p></p><div class="notes"><pre><code> ... b a <{}
|
||
-----------------
|
||
... [] b a
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[] <a href="#rollup">rollup</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Tuck an empty list just under the first two items on the stack.</div><div class="crosslinks"><h3>See Also</h3><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="func_name"><{}</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"><= <a href="#b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866" class="self_link">¶</a></h2><p></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"><> <a href="#24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#ne">ne</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"><{} <a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="self_link">¶</a></h2><p></p><div class="notes"><pre><code> ... a <{}
|
||
----------------
|
||
... [] a
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[] <a href="#swap">swap</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Tuck an empty list just under the first item on the stack.</div><div class="crosslinks"><h3>See Also</h3><a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name"><<{}</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></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">> <a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221" class="self_link">¶</a></h2><p></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></div></div><hr><div><h2 id="92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f" class="func_name">>= <a href="#92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f" class="self_link">¶</a></h2><p></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">>> <a href="#0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#rshift">rshift</a>.</p></div><div class="definition"><h3>Definition</h3><blockquote><a href="#rshift">rshift</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#dup">dup</a> <a href="#bool">bool</a></blockquote></div><div class="discussion"><h3>Discussion</h3>You often want to test the truth value of an item on the stack without
|
||
consuming the item.</div><div class="crosslinks"><h3>See Also</h3><a href="#bool" class="func_name">bool</a></div></div><hr><div><h2 id="74cd9ef9c7e15f57bdad73c511462ca65cb674c46c49639c60f1b44650fa1dcb" class="func_name">^ <a href="#74cd9ef9c7e15f57bdad73c511462ca65cb674c46c49639c60f1b44650fa1dcb" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#xor">xor</a>.</p></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>Return the absolute value of the argument.</p></div><div class="definition"><h3>Definition</h3><blockquote><a href="#dup">dup</a> <a href="#">0</a> <a href="#dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72"><</a> [] [<a href="#neg">neg</a>] <a href="#branch">branch</a></blockquote></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></p><div class="notes"><p>Add two numbers together: a + b.</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>
|
||
<blockquote>
|
||
<p>[0 <=] [-- dup] anamorphism</p>
|
||
</blockquote></div><div class="definition"><h3>Definition</h3><blockquote>[<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></blockquote></div><div class="discussion"><h3>Discussion</h3>See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).</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></p><div class="notes"><p>Logical bit-wise AND.</p></div><div class="definition"><h3>Definition</h3><blockquote><a href="#nulco">nulco</a> [<a href="#nullary">nullary</a> [<a href="#">false</a>]] <a href="#dip">dip</a> <a href="#branch">branch</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#or" class="func_name">or</a> <a href="#xor" class="func_name">xor</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 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"><h3>Definition</h3><blockquote><a href="#grba">grba</a> <a href="#infrst">infrst</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Just a specialization of `nullary` really. Its parallelizable cousins
|
||
are more useful.</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"><h3>Definition</h3><blockquote>[<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></blockquote></div><div class="discussion"><h3>Discussion</h3>Unlike [app1](#app1), which is essentially an alias for [unary](#unary),
|
||
this function is not the same as [binary](#binary). Instead of running
|
||
one program using exactly two items from the stack and pushing one
|
||
result (as [binary](#binary) 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.</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"><h3>Definition</h3><blockquote><a href="#">3</a> <a href="#appN">appN</a></blockquote></div><div class="discussion"><h3>Discussion</h3>See [app2].</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"><h3>Definition</h3><blockquote>[<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></blockquote></div><div class="discussion"><h3>Discussion</h3>This function takes a quoted function `Q` and an integer and runs the
|
||
function that many times on that many stack items. See also [app2].</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"><h3>Definition</h3><blockquote><a href="#drop">drop</a> <a href="#first">first</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#sum">sum</a>] [<a href="#size">size</a>] <a href="#cleave">cleave</a> <a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a></blockquote></div><div class="discussion"><h3>Discussion</h3>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 [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).</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"><h3>Definition</h3><blockquote>[<a href="#i">i</a>] <a href="#dip">dip</a> <a href="#i">i</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This combinator may seem trivial but it comes in handy.</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"><h3>Definition</h3><blockquote><a href="#unary">unary</a> <a href="#popd">popd</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Runs any other quoted function and returns its first result while
|
||
consuming exactly two items from the stack.</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></p><div class="notes"><p>Convert the item on the top of the stack to a Boolean value.</p></div><div class="discussion"><h3>Discussion</h3>For integers 0 is `false` and any other number is `true`; for lists the
|
||
empty list is `false` and all other lists are `true`.</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="#" 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"><h3>Discussion</h3>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].</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="#" class="func_name">/\</a> <a href="#" class="func_name">\/</a> <a href="#abs" class="func_name">abs</a> <a href="#and" class="func_name">and</a> <a href="#ifte" class="func_name">ifte</a> <a href="#not" class="func_name">not</a> <a href="#or" class="func_name">or</a> <a href="#" class="func_name">small</a> <a href="#xor" class="func_name">xor</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"><h3>Definition</h3><blockquote><a href="#ccons">ccons</a> <a href="#ccons">ccons</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#cons">cons</a> <a href="#cons">cons</a></blockquote></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="discussion"><h3>Discussion</h3>It's a matter of taste whether you implement this in terms of [branch] or
|
||
the other way around.</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"><h3>Definition</h3><blockquote>[] <a href="#swaack">swaack</a> <a href="#pop">pop</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#fork">fork</a> <a href="#popdd">popdd</a></blockquote></div><div class="discussion"><h3>Discussion</h3>One of a handful of useful parallel combinators.</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"><h3>Definition</h3><blockquote><a href="#cleave">cleave</a> <a href="#popdd">popdd</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Like [cleave] but consumes an additional item from the stack.
|
||
1 2 3 4 [+] [-] clop
|
||
--------------------------
|
||
1 2 7 -1</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 > b
|
||
G
|
||
|
||
a b [G] [E] [L] cmp
|
||
------------------------- a = b
|
||
E
|
||
|
||
a b [G] [E] [L] cmp
|
||
------------------------- a < b
|
||
L
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[[<a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">></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></blockquote></div><div class="discussion"><h3>Discussion</h3>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 [<=] or [>=]
|
||
and not all three possibilities, e.g.:
|
||
[G] [EL] dup cmp
|
||
[GE] [L] dupd cmp
|
||
Or even:
|
||
[GL] [E] over cmp</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="#" 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"><h3>Definition</h3><blockquote><a href="#cons">cons</a> <a href="#dip">dip</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This is one of those weirdly specific functions that turns out to be
|
||
useful in a few places.</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"><h3>Definition</h3><blockquote><a href="#codi">codi</a> <a href="#reco">reco</a></blockquote></div><div class="discussion"><h3>Discussion</h3>See [make_generator] and the
|
||
["Using `x` to Generate Values" notebook](https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation)
|
||
as well as
|
||
[Recursion Theory and Joy](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html) by Manfred von Thun.</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></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="#" class="func_name">null</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"><h3>Discussion</h3>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</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"><h3>Discussion</h3>Cons is a [venerable old function from Lisp](https://en.wikipedia.org/wiki/Cons#Lists).
|
||
Its inverse operation is [uncons].</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="#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="#reco" class="func_name">reco</a> <a href="#swons" class="func_name">swons</a> <a href="#unit" class="func_name">unit</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"><h3>Definition</h3><blockquote><a href="#dip">dip</a> <a href="#infrst">infrst</a></blockquote></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"><h3>Discussion</h3>This along with [infra] are enough to update any datastructure.
|
||
See the ["Traversing Datastructures with Zippers" notebook](https://joypy.osdn.io/notebooks/Zipper.html).
|
||
Note that the item that was on the top of the stack (`x` 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 `dip` and `infra` to operate on compound
|
||
datastructures with atoms in them. This is a kind of side-effect of the
|
||
Continuation-Passing Style. The `dip` combinator could "set aside" the
|
||
item and replace it after running `Q` but that means that there is an
|
||
"extra space" where the item resides while `Q` 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.)</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="#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="#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="#" 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"><h3>Definition</h3><blockquote>[<a href="#dip">dip</a>] <a href="#codi">codi</a></blockquote></div><div class="discussion"><h3>Discussion</h3>See [dip].</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="#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="#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></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] . dip
|
||
-----------------------------
|
||
... . Q z y x
|
||
</code></pre></div><div class="discussion"><h3>Discussion</h3>See [dip].</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="#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"><h3>Definition</h3><blockquote><a href="#swaack">swaack</a> <a href="#pop">pop</a></blockquote></div><div class="discussion"><h3>Discussion</h3>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.</div><div class="crosslinks"><h3>See Also</h3><a href="#enstacken" class="func_name">enstacken</a> <a href="#stack" class="func_name">stack</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></p><div class="notes"><p>See <a href="#floordiv">floordiv</a>.</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"><h3>Definition</h3><blockquote>[<a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a>] [<a href="#bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a>] <a href="#clop">clop</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#">0</a> <a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">></a>] [<a href="#dup">dup</a> <a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a>] <a href="#while">while</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#rest">rest</a>] <a href="#times">times</a></blockquote></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="#gcd" class="func_name">gcd</a> <a href="#over" class="func_name">over</a> <a href="#range" class="func_name">range</a> <a href="#" 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"><h3>Definition</h3><blockquote>[<a href="#dup">dup</a>] <a href="#dip">dip</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#dup">dup</a>] <a href="#dipd">dipd</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#dupd">dupd</a> <a href="#dip">dip</a></blockquote></div><div class="discussion"><h3>Discussion</h3>A very common and useful combinator.</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"><h3>Definition</h3><blockquote><a href="#dup">dup</a> <a href="#dipd">dipd</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#stack">stack</a> [<a href="#clear">clear</a>] <a href="#dip">dip</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This is a destructive version of [stack]. See the note under
|
||
[disenstacken] about the apparent but illusory reversal of the stack.</div><div class="crosslinks"><h3>See Also</h3><a href="#stack" class="func_name">stack</a> <a href="#disenstacken" class="func_name">disenstacken</a></div></div><hr><div><h2 id="eq" class="func_name">eq <a href="#eq" class="self_link">¶</a></h2><p></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"><h3>Definition</h3><blockquote>[<a href="#">false</a>] [<a href="#">true</a>] [<a href="#">false</a>] <a href="#cmp">cmp</a></blockquote></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="#ne" class="func_name">ne</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"><h3>Definition</h3><blockquote><a href="#uncons">uncons</a> <a href="#pop">pop</a></blockquote></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="#infrst" class="func_name">infrst</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="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"><h3>Definition</h3><blockquote><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7"><{}</a> [<a href="#concat">concat</a>] <a href="#step">step</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Note that only one "level" of lists is flattened. In the example above
|
||
`[4]` is not unquoted.</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="floor" class="func_name">floor <a href="#floor" class="self_link">¶</a></h2><p></p><div class="notes"><p>Return the largest integer \<= x.</p></div><div class="discussion"><h3>Discussion</h3>This function doesn't make sense (yet) to have because there are (as yet)
|
||
only integers in the system.</div></div><hr><div><h2 id="floordiv" class="func_name">floordiv <a href="#floordiv" class="self_link">¶</a></h2><p></p><div class="notes"><p>I don't know why this is called "floor" div, I think it rounds its
|
||
result down (not towards zero or up.)</p>
|
||
<pre><code> a b floordiv
|
||
------------------
|
||
(a/b)
|
||
</code></pre></div><div class="discussion"><h3>Discussion</h3>All the division commands need to be revisited when the "numeric tower"
|
||
for Thun gets nailed down.</div><div class="crosslinks"><h3>See Also</h3><a href="#divmod" class="func_name">divmod</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"><h3>Definition</h3><blockquote>[<a href="#i">i</a>] <a href="#d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a">app2</a></blockquote></div><div class="discussion"><h3>Discussion</h3>The basic parallelism combinator, the two programs are run independently.</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"><h3>Definition</h3><blockquote><a href="#rest">rest</a> <a href="#third">third</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#">true</a> [<a href="#tuck">tuck</a> <a href="#mod">mod</a> <a href="#dup">dup</a> <a href="#">0</a> <a href="#62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">></a>] <a href="#loop">loop</a> <a href="#pop">pop</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Euclid's Algorithm</div></div><hr><div><h2 id="ab323e8d4f8c5d1c7d333fbe3e08b223c11f7bcc5066ace0af17172f77aa31b3" class="func_name">gcd2 <a href="#ab323e8d4f8c5d1c7d333fbe3e08b223c11f7bcc5066ace0af17172f77aa31b3" class="self_link">¶</a></h2><p></p><div class="notes"><p>Compiled GCD function.</p></div><div class="discussion"><h3>Discussion</h3>See [gcd].</div><div class="crosslinks"><h3>See Also</h3><a href="#gcd" class="func_name">gcd</a></div></div><hr><div><h2 id="ge" class="func_name">ge <a href="#ge" class="self_link">¶</a></h2><p></p><div class="notes"><p>Greater-than-or-equal-to comparison of two numbers.</p>
|
||
<pre><code> a b ge
|
||
--------------
|
||
Boolean
|
||
(a >= b)
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">true</a>] [<a href="#">true</a>] [<a href="#">false</a>] <a href="#cmp">cmp</a></blockquote></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="#ne" class="func_name">ne</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"><h3>Definition</h3><blockquote>[[<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></blockquote></div><div class="discussion"><h3>Discussion</h3>Note that this definition includes the `genrec` symbol itself, it is
|
||
self-referential. This is possible because the definition machinery does
|
||
not check that symbols in defs are in the dictionary. `genrec` is the
|
||
only self-referential definition.
|
||
See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
|
||
From ["Recursion Theory and Joy"](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html)
|
||
by Manfred von Thun:
|
||
> "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 `[then]` and the
|
||
test `[if]`, and then treat `rec1` and `rec2` as an else-part
|
||
"sandwiching" a quotation of the whole function.
|
||
For example, given a (general recursive) function `F`:
|
||
F == [I] [T] [R1] [R2] genrec
|
||
If the `[I]` if-part fails you must derive `R1` and `R2` from: :
|
||
... R1 [F] R2
|
||
Just set the stack arguments in front, and figure out what `R1` and `R2`
|
||
have to do to apply the quoted `[F]` in the proper way. In effect, the
|
||
`genrec` 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 `R2` is the `i` combinator:
|
||
P == [I] [T] [R] tailrec
|
||
== [I] [T] [R [P] i] ifte
|
||
== [I] [T] [R P] ifte</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></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="discussion"><h3>Discussion</h3>If the number isn't a valid index into the quote `getitem` will cause
|
||
some sort of problem (the exact nature of which is
|
||
implementation-dependant.)</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><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"><h3>Definition</h3><blockquote><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7"><{}</a> [<a href="#cons">cons</a>] <a href="#times">times</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#stack">stack</a> <a href="#popd">popd</a>] <a href="#dip">dip</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This function "grabs" an item from the stack along with a copy of the stack.
|
||
It's part of the [app2] definition.</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></p><div class="notes"><p>Greater-than comparison of two numbers.</p>
|
||
<pre><code> a b gt
|
||
--------------
|
||
Boolean
|
||
(a > b)
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">true</a>] [<a href="#">false</a>] [<a href="#">false</a>] <a href="#cmp">cmp</a></blockquote></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="#ne" class="func_name">ne</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"><h3>Discussion</h3>Technically this is equivalent to `pop`, but it will only work if the
|
||
item on the top of the stack is a quoted symbol.</div></div><hr><div><h2 id="hypot" class="func_name">hypot <a href="#hypot" class="self_link">¶</a></h2><p></p><div class="notes"><pre><code> x y hypot
|
||
---------------------------
|
||
sqrt(sqr(x) + sqr(y))
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[<a href="#sqr">sqr</a>] <a href="#ii">ii</a> <a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a> <a href="#sqrt">sqrt</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This is another function that has to wait on the numeric tower.</div><div class="crosslinks"><h3>See Also</h3><a href="#sqrt" class="func_name">sqrt</a></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"><h3>Discussion</h3>This is a fundamental combinator. It is used in all kinds of places. For
|
||
example, the [x] combinator can be defined as `dup i`.</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></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"><h3>Discussion</h3>Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy.</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"><h3>Definition</h3><blockquote>[<a href="#nullary">nullary</a>] <a href="#dipd">dipd</a> <a href="#swap">swap</a> <a href="#branch">branch</a></blockquote></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="#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"><h3>Definition</h3><blockquote>[<a href="#dip">dip</a>] <a href="#dupdip">dupdip</a> <a href="#i">i</a></blockquote></div><div class="discussion"><h3>Discussion</h3>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</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="#hypot" class="func_name">hypot</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</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"><h3>Definition</h3><blockquote><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></blockquote></div><div class="discussion"><h3>Discussion</h3>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
|
||
`infra` lets you work on its internal structure.</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"><h3>Definition</h3><blockquote><a href="#infra">infra</a> <a href="#first">first</a></blockquote></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></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"><h3>Discussion</h3>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 `defs.txt` file. It can be abused, which you should avoid unless you
|
||
know what you're doing.</div></div><hr><div><h2 id="le" class="func_name">le <a href="#le" class="self_link">¶</a></h2><p></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 <= b)
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">false</a>] [<a href="#">true</a>] [<a href="#">true</a>] <a href="#cmp">cmp</a></blockquote></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="#ne" class="func_name">ne</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"><h3>Discussion</h3>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 `F G` is like `G(F(...))` in a language bassed on
|
||
function application. Or again, to quote the [Joy Wikipedia
|
||
entry](https://en.wikipedia.org/wiki/Joy_(programming_language)#Mathematical_purity),
|
||
> 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].</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></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"><h3>Definition</h3><blockquote>[<a href="#">2</a> <a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#times">times</a></blockquote></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"><<</a></div></div><hr><div><h2 id="lt" class="func_name">lt <a href="#lt" class="self_link">¶</a></h2><p></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 < b)
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">false</a>] [<a href="#">false</a>] [<a href="#">true</a>] <a href="#cmp">cmp</a></blockquote></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="#ne" class="func_name">ne</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"><h3>Definition</h3><blockquote>[<a href="#codireco">codireco</a>] <a href="#ccons">ccons</a></blockquote></div><div class="discussion"><h3>Discussion</h3>See the ["Using `x` to Generate Values" notebook](https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation).</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"><h3>Definition</h3><blockquote>[<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></blockquote></div><div class="discussion"><h3>Discussion</h3>This is a common operation in many languages. In Joy it can be a
|
||
parallelism combinator due to the "pure" nature of the language.</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="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="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"><h3>Definition</h3><blockquote><a href="#bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a></blockquote></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><hr><div><h2 id="mul" class="func_name">mul <a href="#mul" class="self_link">¶</a></h2><p></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="ne" class="func_name">ne <a href="#ne" class="self_link">¶</a></h2><p></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 ne
|
||
-------------
|
||
Boolean
|
||
(a = b)
|
||
</code></pre></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="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"><h3>Definition</h3><blockquote><a href="#">0</a> <a href="#swap">swap</a> <a href="#3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#abs" class="func_name">abs</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>Like [bool] but convert the item on the top of the stack to the inverse
|
||
Boolean value.</p>
|
||
<pre><code> true not
|
||
--------------
|
||
false
|
||
|
||
false not
|
||
---------------
|
||
true
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">true</a>] [<a href="#">false</a>] <a href="#branch">branch</a></blockquote></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="#" class="func_name">null</a> <a href="#xor" class="func_name">xor</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"><h3>Definition</h3><blockquote>[<a href="#nullary">nullary</a>] <a href="#cons">cons</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Helper function for [\|\|] and [&&].</div><div class="crosslinks"><h3>See Also</h3><a href="#73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" class="func_name">&&</a> <a href="#565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866" class="func_name">||</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="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"><h3>Definition</h3><blockquote>[<a href="#stack">stack</a>] <a href="#dinfrirst">dinfrirst</a></blockquote></div><div class="discussion"><h3>Discussion</h3>A very useful function that runs any other quoted function and returns
|
||
it's first result without disturbing the stack (under the quoted
|
||
program.)</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"><h3>Definition</h3><blockquote><a href="#swap">swap</a> <a href="#at">at</a></blockquote></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></p><div class="notes"><p>Logical bit-wise OR.</p></div><div class="definition"><h3>Definition</h3><blockquote><a href="#nulco">nulco</a> [<a href="#nullary">nullary</a>] <a href="#dip">dip</a> [<a href="#">true</a>] <a href="#branch">branch</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#and" class="func_name">and</a> <a href="#xor" class="func_name">xor</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"><h3>Definition</h3><blockquote>[<a href="#dup">dup</a>] <a href="#dip">dip</a> <a href="#swap">swap</a></blockquote></div><div class="discussion"><h3>Discussion</h3>A fine old word from Forth.</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"><h3>Definition</h3><blockquote>[<a href="#i">i</a>] <a href="#map">map</a></blockquote></div><div class="discussion"><h3>Discussion</h3>A specialization of [map] that runs a list of functions in parallel (if
|
||
the underlying [map] function is so implemented, of course.)</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><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"><h3>Definition</h3><blockquote>[<a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a>] [<a href="#3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a>] <a href="#clop">clop</a></blockquote></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="#" class="func_name">/\</a> <a href="#" class="func_name">\/</a> <a href="#anamorphism" class="func_name">anamorphism</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="#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="#" class="func_name">small</a> <a href="#b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a> <a href="#take" class="func_name">take</a> <a href="#" class="func_name">unstack</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"><h3>Definition</h3><blockquote>[<a href="#pop">pop</a>] <a href="#dip">dip</a></blockquote></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="#grba" class="func_name">grba</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"><h3>Definition</h3><blockquote>[<a href="#pop">pop</a>] <a href="#dipd">dipd</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#pop">pop</a> <a href="#pop">pop</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#popop">popop</a>] <a href="#dip">dip</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#popop">popop</a>] <a href="#dipd">dipd</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#pop">pop</a> <a href="#popop">popop</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#">1</a> <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll></a> <a href="#swap">swap</a> [<a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#cons">cons</a> <a href="#times">times</a></blockquote></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="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 > 0
|
||
n (n-1) [Base] [Recur] primrec Recur
|
||
</code></pre></div><div class="discussion"><h3>Discussion</h3>Simple and useful specialization of the [genrec] combinator from the
|
||
[original Joy system](https://www.kevinalbrecht.com/code/joy-mirror/index.html).</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"><h3>Definition</h3><blockquote><a href="#">1</a> <a href="#swap">swap</a> [<a href="#684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#step">step</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#unit">unit</a>] <a href="#dip">dip</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This comes from the original Joy stuff.</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"><h3>Definition</h3><blockquote>[<a href="#">0</a> <a href="#b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866"><=</a>] [<a href="#d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a> <a href="#dup">dup</a>] <a href="#anamorphism">anamorphism</a></blockquote></div><div class="discussion"><h3>Discussion</h3>If `n` is less than 1 the resulting list is empty.</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"><h3>Definition</h3><blockquote><a href="#unit">unit</a> [<a href="#24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d">down_to_zero</a>] <a href="#infra">infra</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Note that the order is reversed compared to [range].</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"><h3>Definition</h3><blockquote><a href="#rest">rest</a> <a href="#cons">cons</a></blockquote></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></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></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"><h3>Definition</h3><blockquote><a href="#uncons">uncons</a> <a href="#popd">popd</a></blockquote></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="#reco" class="func_name">reco</a> <a href="#rrest" class="func_name">rrest</a> <a href="#second" class="func_name">second</a> <a href="#" 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"><h3>Definition</h3><blockquote><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7"><{}</a> <a href="#shunt">shunt</a></blockquote></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< <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"><h3>Definition</h3><blockquote><a href="#swapd">swapd</a> <a href="#swap">swap</a></blockquote></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> <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"><h3>Definition</h3><blockquote><a href="#swap">swap</a> <a href="#swapd">swapd</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd">roll<</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll></a></blockquote></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"><<{}</a></div></div><hr><div><h2 id="round" class="func_name">round <a href="#round" class="self_link">¶</a></h2><p></p><div class="notes"><p>Round a number to a given precision in decimal digits.</p></div><div class="discussion"><h3>Discussion</h3>Another one that won't make sense until the "numeric tower" is nailed
|
||
down.</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"><h3>Definition</h3><blockquote><a href="#rest">rest</a> <a href="#rest">rest</a></blockquote></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></p><div class="notes"><p><a href="https://en.wikipedia.org/wiki/Logical_shift">Logical Right-Shift</a></p>
|
||
<pre><code> a n rshift
|
||
----------------
|
||
(a∕2ⁿ)
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">2</a> <a href="#8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a>] <a href="#times">times</a></blockquote></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">>></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"><h3>Definition</h3><blockquote><a href="#7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7"><{}</a> <a href="#infra">infra</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#rest">rest</a> <a href="#first">first</a></blockquote></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"><h3>Discussion</h3>The sequence can contain more than two items but not fewer.</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"><h3>Discussion</h3>Mathematically this is a form of [id], but it has the side-effect of
|
||
printing out the GPL notice.</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"><h3>Definition</h3><blockquote><a href="#uncons">uncons</a> [<a href="#swons">swons</a>] <a href="#dip">dip</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#swons">swons</a>] <a href="#step">step</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This is more efficient than [concat] so prefer it if you don't need to
|
||
preserve order.</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"><h3>Definition</h3><blockquote>[<a href="#pop">pop</a> <a href="#cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a>] <a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482">step_zero</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#average" class="func_name">average</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"><h3>Definition</h3><blockquote>[[[<a href="#abs">abs</a>] <a href="#ii">ii</a> <a href="#b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866"><=</a>] [[<a href="#24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64"><></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></blockquote></div><div class="discussion"><h3>Discussion</h3>See the ["Square Spiral Example Joy Code" notebook](https://joypy.osdn.io/notebooks/Square_Spiral.html).</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"><h3>Definition</h3><blockquote>[<a href="#drop">drop</a>] [<a href="#take">take</a>] <a href="#clop">clop</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Take a list and a number `n` from the stack, take `n` items from the top
|
||
of the list and [shunt] them onto a new list that replaces the number `n`
|
||
on the top of the stack.</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"><h3>Definition</h3><blockquote>[<a href="#take">take</a> <a href="#reverse">reverse</a>] [<a href="#drop">drop</a>] <a href="#clop">clop</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Compare with [split_at]. This function does extra work to ensure that
|
||
[concat] would reconstruct the original list.</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
|
||
------------
|
||
n²
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote><a href="#dup">dup</a> <a href="#mul">mul</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#hypot" class="func_name">hypot</a></div></div><hr><div><h2 id="sqrt" class="func_name">sqrt <a href="#sqrt" class="self_link">¶</a></h2><p></p><div class="notes"><p>Function Combinator</p>
|
||
<p>Return the square root of the number a. Negative numbers return complex
|
||
roots.</p></div><div class="discussion"><h3>Discussion</h3>Another "numeric tower" hatch...</div><div class="backlinks"><h3>Used By</h3><a href="#hypot" class="func_name">hypot</a></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"><h3>Discussion</h3>This function forms a pair with [unstack], and together they form the
|
||
complement to the "destructive" pair [enstacken] and [disenstacken].</div><div class="crosslinks"><h3>See Also</h3><a href="#enstacken" class="func_name">enstacken</a> <a href="#disenstacken" class="func_name">disenstacken</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"><h3>Definition</h3><blockquote>[<a href="#stack">stack</a>] <a href="#dip">dip</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#">_step0</a>] <a href="#x">x</a></blockquote></div><div class="discussion"><h3>Discussion</h3>See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).</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="#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"><h3>Definition</h3><blockquote><a href="#">0</a> <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll></a> <a href="#step">step</a></blockquote></div><div class="discussion"><h3>Discussion</h3>[size] and [sum] can both be defined in terms of this specialization of
|
||
[step].</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"><h3>Definition</h3><blockquote><a href="#stack">stack</a> <a href="#uncons">uncons</a></blockquote></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></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="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"><h3>Definition</h3><blockquote>[<a href="#a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a>] <a href="#edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482">step_zero</a></blockquote></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"><h3>Discussion</h3>This function works as a kind of "context switch". It's used in the
|
||
definition of [infra].</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="#" 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"><{}</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="#" class="func_name">null</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<</a> <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll></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"><h3>Definition</h3><blockquote>[<a href="#swap">swap</a>] <a href="#dip">dip</a></blockquote></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<</a> <a href="#93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll></a> <a href="#tuck" class="func_name">tuck</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"><h3>Definition</h3><blockquote><a href="#swap">swap</a> <a href="#concat">concat</a></blockquote></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="#" 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"><h3>Definition</h3><blockquote><a href="#swap">swap</a> <a href="#cons">cons</a></blockquote></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"><h3>Definition</h3><blockquote>[<a href="#i">i</a>] <a href="#genrec">genrec</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Some recursive functions do not need to store additional data or pending
|
||
actions per-call. These are called ["tail recursive" functions](https://en.wikipedia.org/wiki/Tail_recursive). In Joy,
|
||
they appear as [genrec] definitions that have [i] for the second half of
|
||
their recursive branch.
|
||
See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).</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"><h3>Definition</h3><blockquote><a href="#c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108"><<{}</a> [<a href="#shift">shift</a>] <a href="#times">times</a> <a href="#pop">pop</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#binary">binary</a> <a href="#popd">popd</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Runs any other quoted function and returns its first result while
|
||
consuming exactly three items from the stack.</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"><h3>Definition</h3><blockquote><a href="#rest">rest</a> <a href="#second">second</a></blockquote></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 <= 0
|
||
... .
|
||
|
||
... 1 [Q] . times
|
||
-----------------------
|
||
... . Q
|
||
|
||
... n [Q] . times
|
||
------------------------------------- w/ n > 1
|
||
... . Q (n-1) [Q] times
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">_times0</a>] <a href="#x">x</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This works by building a little [while] program and running it:
|
||
1 3 [++] • [-- dip] cons [swap] infra [0 >] swap while pop
|
||
1 3 [++] [-- dip] • cons [swap] infra [0 >] swap while pop
|
||
1 3 [[++] -- dip] • [swap] infra [0 >] swap while pop
|
||
1 3 [[++] -- dip] [swap] • infra [0 >] swap while pop
|
||
dip -- [++] • swap [3 1] swaack [0 >] swap while pop
|
||
dip [++] -- • [3 1] swaack [0 >] swap while pop
|
||
dip [++] -- [3 1] • swaack [0 >] swap while pop
|
||
1 3 [-- [++] dip] • [0 >] swap while pop
|
||
1 3 [-- [++] dip] [0 >] • swap while pop
|
||
1 3 [0 >] [-- [++] 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="#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="truthy" class="func_name">truthy <a href="#truthy" class="self_link">¶</a></h2><p></p><div class="notes"><p>See <a href="#bool">bool</a>.</p></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"><h3>Definition</h3><blockquote><a href="#dup">dup</a> <a href="#swapd">swapd</a></blockquote></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"><h3>Definition</h3><blockquote><a href="#nullary">nullary</a> <a href="#popd">popd</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Runs any other quoted function and returns its first result while
|
||
consuming exactly one item from the stack.</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"><h3>Definition</h3><blockquote>[<a href="#first">first</a>] <a href="#dupdip">dupdip</a> <a href="#rest">rest</a></blockquote></div><div class="discussion"><h3>Discussion</h3>This is the inverse of [cons].</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="#rest" class="func_name">rest</a> <a href="#shift" class="func_name">shift</a> <a href="#stuncons" class="func_name">stuncons</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"><h3>Definition</h3><blockquote>[] <a href="#cons">cons</a></blockquote></div><div class="backlinks"><h3>Used By</h3><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"><h3>Definition</h3><blockquote>[<a href="#i">i</a>] <a href="#dip">dip</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#unit" class="func_name">unit</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"><h3>Definition</h3><blockquote><a href="#uncons">uncons</a> <a href="#swap">swap</a></blockquote></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"><h3>Discussion</h3>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 [The Markable Mark](http://www.markability.net/)</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 -> false
|
||
|
||
[P] [F] while
|
||
--------------------- P -> true
|
||
F [P] [F] while
|
||
</code></pre></div><div class="definition"><h3>Definition</h3><blockquote><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></blockquote></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"><h3>Discussion</h3>Mathematically this is a form of [id].</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"><h3>Definition</h3><blockquote><a href="#dup">dup</a> <a href="#i">i</a></blockquote></div><div class="discussion"><h3>Discussion</h3>The simplest recursive pattern.
|
||
See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
|
||
as well as
|
||
[Recursion Theory and Joy](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html) by Manfred von</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="xor" class="func_name">xor <a href="#xor" class="self_link">¶</a></h2><p></p><div class="notes"><p>Logical bit-wise eXclusive OR.</p></div><div class="definition"><h3>Definition</h3><blockquote>[] [<a href="#not">not</a>] <a href="#branch">branch</a></blockquote></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><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
|
||
-------------------------
|
||
[[4 1] [5 2] [6 3]]
|
||
</code></pre></div></div><hr><div><h2 id="565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866" class="func_name">|| <a href="#565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866" class="self_link">¶</a></h2><p><span class="kind">combinator</span> </p><div class="notes"><p>Short-circuiting Boolean OR</p></div><div class="discussion"><h3>Discussion</h3>Accept two quoted programs, run the first and expect a Boolean value, if
|
||
it’s `false` pop it and run the second program (which should also return a
|
||
Boolean value) otherwise pop the second program (leaving `true` on the
|
||
stack.)
|
||
[A] [B] ||
|
||
---------------- A -> false
|
||
B
|
||
[A] [B] ||
|
||
---------------- A -> true
|
||
true</div><div class="crosslinks"><h3>See Also</h3><a href="#73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" class="func_name">&&</a></div></div></body></html>
|