Thun/docs/html/FuncRef.html

1847 lines
156 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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

<!DOCTYPE html><html><head><meta charset="utf-8"><title>Thun Function Reference</title><link rel="stylesheet" href="/css/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="#function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a></li> <li><a href="#function_c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2">!=</a></li> <li><a href="#function_bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a></li> <li><a href="#function_951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338">&amp;</a></li> <li><a href="#function_73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef">&amp;&amp;</a></li> <li><a href="#function_684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a></li> <li><a href="#function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a></li> <li><a href="#function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a></li> <li><a href="#function_3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a></li> <li><a href="#function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a></li> <li><a href="#function_8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a></li> <li><a href="#function_a2c2339691fc48fbd14fb307292dff3e21222712d9240810742d7df0c6d74dfb">//</a></li> <li><a href="#function_25fec5b6fc916113006299298a2df014df5c407ebb11013f36163d3ec1cc1c53">/floor</a></li> <li><a href="#function_dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72">&lt;</a></li> <li><a href="#function_4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e">&lt;&lt;</a></li> <li><a href="#function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108">&lt;&lt;{}</a></li> <li><a href="#function_b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866">&lt;=</a></li> <li><a href="#function_24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64">&lt;&gt;</a></li> <li><a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a></li> <li><a href="#function_380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3">=</a></li> <li><a href="#function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">&gt;</a></li> <li><a href="#function_92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f">&gt;=</a></li> <li><a href="#function_0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44">&gt;&gt;</a></li> <li><a href="#function_8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1">?</a></li> <li><a href="#function_74cd9ef9c7e15f57bdad73c511462ca65cb674c46c49639c60f1b44650fa1dcb">^</a></li> <li><a href="#function_abs">abs</a></li> <li><a href="#function_add">add</a></li> <li><a href="#function_anamorphism">anamorphism</a></li> <li><a href="#function_and">and</a></li> <li><a href="#function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094">app1</a></li> <li><a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a">app2</a></li> <li><a href="#function_697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868">app3</a></li> <li><a href="#function_appN">appN</a></li> <li><a href="#function_at">at</a></li> <li><a href="#function_average">average</a></li> <li><a href="#function_b">b</a></li> <li><a href="#function_binary">binary</a></li> <li><a href="#function_bool">bool</a></li> <li><a href="#function_branch">branch</a></li> <li><a href="#function_ccccons">ccccons</a></li> <li><a href="#function_ccons">ccons</a></li> <li><a href="#function_choice">choice</a></li> <li><a href="#function_clear">clear</a></li> <li><a href="#function_cleave">cleave</a></li> <li><a href="#function_clop">clop</a></li> <li><a href="#function_cmp">cmp</a></li> <li><a href="#function_codi">codi</a></li> <li><a href="#function_codireco">codireco</a></li> <li><a href="#function_concat">concat</a></li> <li><a href="#function_cond">cond</a></li> <li><a href="#function_cons">cons</a></li> <li><a href="#function_dinfrirst">dinfrirst</a></li> <li><a href="#function_dip">dip</a></li> <li><a href="#function_dipd">dipd</a></li> <li><a href="#function_dipdd">dipdd</a></li> <li><a href="#function_disenstacken">disenstacken</a></li> <li><a href="#function_div">div</a></li> <li><a href="#function_divmod">divmod</a></li> <li><a href="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d">down_to_zero</a></li> <li><a href="#function_drop">drop</a></li> <li><a href="#function_dup">dup</a></li> <li><a href="#function_dupd">dupd</a></li> <li><a href="#function_dupdd">dupdd</a></li> <li><a href="#function_dupdip">dupdip</a></li> <li><a href="#function_dupdipd">dupdipd</a></li> <li><a href="#function_enstacken">enstacken</a></li> <li><a href="#function_eq">eq</a></li> <li><a href="#function_first">first</a></li> <li><a href="#function_07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236">first_two</a></li> <li><a href="#function_flatten">flatten</a></li> <li><a href="#function_floor">floor</a></li> <li><a href="#function_floordiv">floordiv</a></li> <li><a href="#function_fork">fork</a></li> <li><a href="#function_fourth">fourth</a></li> <li><a href="#function_gcd">gcd</a></li> <li><a href="#function_ab323e8d4f8c5d1c7d333fbe3e08b223c11f7bcc5066ace0af17172f77aa31b3">gcd2</a></li> <li><a href="#function_ge">ge</a></li> <li><a href="#function_genrec">genrec</a></li> <li><a href="#function_getitem">getitem</a></li> <li><a href="#function_grabN">grabN</a></li> <li><a href="#function_grba">grba</a></li> <li><a href="#function_gt">gt</a></li> <li><a href="#function_help">help</a></li> <li><a href="#function_hypot">hypot</a></li> <li><a href="#function_i">i</a></li> <li><a href="#function_id">id</a></li> <li><a href="#function_ifte">ifte</a></li> <li><a href="#function_ii">ii</a></li> <li><a href="#function_infra">infra</a></li> <li><a href="#function_infrst">infrst</a></li> <li><a href="#function_inscribe">inscribe</a></li> <li><a href="#function_le">le</a></li> <li><a href="#function_loop">loop</a></li> <li><a href="#function_lshift">lshift</a></li> <li><a href="#function_lt">lt</a></li> <li><a href="#function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d">make_generator</a></li> <li><a href="#function_map">map</a></li> <li><a href="#function_max">max</a></li> <li><a href="#function_min">min</a></li> <li><a href="#function_mod">mod</a></li> <li><a href="#function_modulus">modulus</a></li> <li><a href="#function_mul">mul</a></li> <li><a href="#function_ne">ne</a></li> <li><a href="#function_neg">neg</a></li> <li><a href="#function_not">not</a></li> <li><a href="#function_nulco">nulco</a></li> <li><a href="#function_nullary">nullary</a></li> <li><a href="#function_of">of</a></li> <li><a href="#function_or">or</a></li> <li><a href="#function_over">over</a></li> <li><a href="#function_pam">pam</a></li> <li><a href="#function_pick">pick</a></li> <li><a href="#function_pm">pm</a></li> <li><a href="#function_pop">pop</a></li> <li><a href="#function_popd">popd</a></li> <li><a href="#function_popdd">popdd</a></li> <li><a href="#function_popop">popop</a></li> <li><a href="#function_popopd">popopd</a></li> <li><a href="#function_popopdd">popopdd</a></li> <li><a href="#function_popopop">popopop</a></li> <li><a href="#function_pow">pow</a></li> <li><a href="#function_pred">pred</a></li> <li><a href="#function_primrec">primrec</a></li> <li><a href="#function_product">product</a></li> <li><a href="#function_quoted">quoted</a></li> <li><a href="#function_range">range</a></li> <li><a href="#function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774">range_to_zero</a></li> <li><a href="#function_reco">reco</a></li> <li><a href="#function_rem">rem</a></li> <li><a href="#function_remainder">remainder</a></li> <li><a href="#function_remove">remove</a></li> <li><a href="#function_rest">rest</a></li> <li><a href="#function_reverse">reverse</a></li> <li><a href="#function_2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd">roll&lt;</a></li> <li><a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll&gt;</a></li> <li><a href="#function_rolldown">rolldown</a></li> <li><a href="#function_rollup">rollup</a></li> <li><a href="#function_round">round</a></li> <li><a href="#function_rrest">rrest</a></li> <li><a href="#function_rshift">rshift</a></li> <li><a href="#function_run">run</a></li> <li><a href="#function_second">second</a></li> <li><a href="#function_select">select</a></li> <li><a href="#function_sharing">sharing</a></li> <li><a href="#function_shift">shift</a></li> <li><a href="#function_shunt">shunt</a></li> <li><a href="#function_size">size</a></li> <li><a href="#function_sort">sort</a></li> <li><a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7">spiral_next</a></li> <li><a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c">split_at</a></li> <li><a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415">split_list</a></li> <li><a href="#function_sqr">sqr</a></li> <li><a href="#function_sqrt">sqrt</a></li> <li><a href="#function_stack">stack</a></li> <li><a href="#function_stackd">stackd</a></li> <li><a href="#function_step">step</a></li> <li><a href="#function_edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482">step_zero</a></li> <li><a href="#function_stuncons">stuncons</a></li> <li><a href="#function_stununcons">stununcons</a></li> <li><a href="#function_sub">sub</a></li> <li><a href="#function_succ">succ</a></li> <li><a href="#function_sum">sum</a></li> <li><a href="#function_swaack">swaack</a></li> <li><a href="#function_swap">swap</a></li> <li><a href="#function_swapd">swapd</a></li> <li><a href="#function_swoncat">swoncat</a></li> <li><a href="#function_swons">swons</a></li> <li><a href="#function_tailrec">tailrec</a></li> <li><a href="#function_take">take</a></li> <li><a href="#function_ternary">ternary</a></li> <li><a href="#function_third">third</a></li> <li><a href="#function_times">times</a></li> <li><a href="#function_truthy">truthy</a></li> <li><a href="#function_tuck">tuck</a></li> <li><a href="#function_unary">unary</a></li> <li><a href="#function_uncons">uncons</a></li> <li><a href="#function_unique">unique</a></li> <li><a href="#function_unit">unit</a></li> <li><a href="#function_unquoted">unquoted</a></li> <li><a href="#function_unswons">unswons</a></li> <li><a href="#function_void">void</a></li> <li><a href="#function_warranty">warranty</a></li> <li><a href="#function_while">while</a></li> <li><a href="#function_words">words</a></li> <li><a href="#function_x">x</a></li> <li><a href="#function_xor">xor</a></li> <li><a href="#function_zip">zip</a></li> <li><a href="#function_565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866">||</a></li> </ul><hr><div><h2 id="function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf" class="func_name">!- <a href="#function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf" class="self_link"></a></h2><pre>
Not negative.
n !-
----------- n &lt; 0
false
n !-
---------- n &gt;= 0
true
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">0</a> <a href="#function_92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f">&gt;=</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="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2" class="func_name">!= <a href="#function_c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2" class="self_link"></a></h2><pre>
See [ne](#ne).
</pre></div><hr><div><h2 id="function_bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec" class="func_name">% <a href="#function_bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec" class="self_link"></a></h2><pre>
See [mod](#mod).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_divmod" class="func_name">divmod</a> <a href="#function_mod" class="func_name">mod</a></div></div><hr><div><h2 id="function_951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338" class="func_name">&amp; <a href="#function_951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338" class="self_link"></a></h2><pre>
See [and](#and).
</pre></div><hr><div><h2 id="function_73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" class="func_name">&amp;&amp; <a href="#function_73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Short-circuiting Boolean AND
Accept two quoted programs, run the first and expect a Boolean value, if
it's `true` pop it and run the second program (which should also return a
Boolean value) otherwise pop the second program (leaving `false` on the
stack.)
[A] [B] &amp;&amp;
---------------- true
B
[A] [B] &amp;&amp;
---------------- false
false
### Definition
nulco [nullary [false]] dip branch
### Derivation
TODO: this is derived in one of the notebooks I think, look it up and
link to it, or copy the content here.
</pre><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="#function_565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866" class="func_name">||</a></div></div><hr><div><h2 id="function_684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1" class="func_name">* <a href="#function_684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1" class="self_link"></a></h2><pre>
See [mul](#mul).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_lshift" class="func_name">lshift</a> <a href="#function_pow" class="func_name">pow</a> <a href="#function_product" class="func_name">product</a></div></div><hr><div><h2 id="function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b" class="func_name">+ <a href="#function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b" class="self_link"></a></h2><pre>
See [add](#add).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e" class="func_name">++</a> <a href="#function_hypot" class="func_name">hypot</a> <a href="#function_pm" class="func_name">pm</a> <a href="#function_sum" class="func_name">sum</a></div></div><hr><div><h2 id="function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e" class="func_name">++ <a href="#function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e" class="self_link"></a></h2><pre>
See [succ](#succ).
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">1</a> <a href="#function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_size" class="func_name">size</a> <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112" class="func_name">- <a href="#function_3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112" class="self_link"></a></h2><pre>
See [sub](#sub).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c" class="func_name">--</a> <a href="#function_neg" class="func_name">neg</a> <a href="#function_pm" class="func_name">pm</a></div></div><hr><div><h2 id="function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c" class="func_name">-- <a href="#function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c" class="self_link"></a></h2><pre>
See [pred](#pred).
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">1</a> <a href="#function_3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#function_range" class="func_name">range</a> <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1" class="func_name">/ <a href="#function_8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1" class="self_link"></a></h2><pre>
See [floordiv](#floordiv).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_average" class="func_name">average</a> <a href="#function_divmod" class="func_name">divmod</a> <a href="#function_rshift" class="func_name">rshift</a></div></div><hr><div><h2 id="function_a2c2339691fc48fbd14fb307292dff3e21222712d9240810742d7df0c6d74dfb" class="func_name">// <a href="#function_a2c2339691fc48fbd14fb307292dff3e21222712d9240810742d7df0c6d74dfb" class="self_link"></a></h2><pre>
See [floordiv](#floordiv).
</pre></div><hr><div><h2 id="function_25fec5b6fc916113006299298a2df014df5c407ebb11013f36163d3ec1cc1c53" class="func_name">/floor <a href="#function_25fec5b6fc916113006299298a2df014df5c407ebb11013f36163d3ec1cc1c53" class="self_link"></a></h2><pre>
See [floordiv](#floordiv).
</pre></div><hr><div><h2 id="function_dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72" class="func_name">&lt; <a href="#function_dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72" class="self_link"></a></h2><pre>
See [lt](#lt).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_abs" class="func_name">abs</a></div></div><hr><div><h2 id="function_4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="func_name">&lt;&lt; <a href="#function_4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="self_link"></a></h2><pre>
See [lshift](#lshift).
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_lshift">lshift</a></blockquote></div></div><hr><div><h2 id="function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name">&lt;&lt;{} <a href="#function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="self_link"></a></h2><pre>
... b a &lt;{}
-----------------
... [] b a
</pre><div class="definition"><h3>Definition</h3><blockquote>[] <a href="#function_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="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="func_name">&lt;{}</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_take" class="func_name">take</a></div></div><hr><div><h2 id="function_b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866" class="func_name">&lt;= <a href="#function_b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866" class="self_link"></a></h2><pre>
See [le](#le).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_range" class="func_name">range</a> <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64" class="func_name">&lt;&gt; <a href="#function_24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64" class="self_link"></a></h2><pre>
See [ne](#ne).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="func_name">&lt;{} <a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="self_link"></a></h2><pre>
... a &lt;{}
----------------
... [] a
</pre><div class="definition"><h3>Definition</h3><blockquote>[] <a href="#function_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="#function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name">&lt;&lt;{}</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_flatten" class="func_name">flatten</a> <a href="#function_grabN" class="func_name">grabN</a> <a href="#function_reverse" class="func_name">reverse</a> <a href="#function_run" class="func_name">run</a></div></div><hr><div><h2 id="function_380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3" class="func_name">= <a href="#function_380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3" class="self_link"></a></h2><pre>
See [eq](#eq).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_cmp" class="func_name">cmp</a></div></div><hr><div><h2 id="function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221" class="func_name">&gt; <a href="#function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221" class="self_link"></a></h2><pre>
See [gt](#gt).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#function_gcd" class="func_name">gcd</a></div></div><hr><div><h2 id="function_92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f" class="func_name">&gt;= <a href="#function_92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f" class="self_link"></a></h2><pre>
See [ge](#ge).
</pre><div class="backlinks"><h3>Used By</h3><a href="#function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf" class="func_name">!-</a></div></div><hr><div><h2 id="function_0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="func_name">&gt;&gt; <a href="#function_0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="self_link"></a></h2><pre>
See [rshift](#rshift).
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_rshift">rshift</a></blockquote></div></div><hr><div><h2 id="function_8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="func_name">? <a href="#function_8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="self_link"></a></h2><pre>
Is the item on the top of the stack "truthy"?
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_dup">dup</a> <a href="#function_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="#function_bool" class="func_name">bool</a></div></div><hr><div><h2 id="function_74cd9ef9c7e15f57bdad73c511462ca65cb674c46c49639c60f1b44650fa1dcb" class="func_name">^ <a href="#function_74cd9ef9c7e15f57bdad73c511462ca65cb674c46c49639c60f1b44650fa1dcb" class="self_link"></a></h2><pre>
See [xor](#xor).
</pre></div><hr><div><h2 id="function_abs" class="func_name">abs <a href="#function_abs" class="self_link"></a></h2><pre>
Return the absolute value of the argument.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_dup">dup</a> <a href="#">0</a> <a href="#function_dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72">&lt;</a> [] [<a href="#function_neg">neg</a>] <a href="#function_branch">branch</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_add" class="func_name">add <a href="#function_add" class="self_link"></a></h2><pre>
Add two numbers together: a + b.
</pre></div><hr><div><h2 id="function_anamorphism" class="func_name">anamorphism <a href="#function_anamorphism" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Build a list of values from a generator program `G` and a stopping
predicate `P`.
[P] [G] anamorphism
-----------------------------------------
[P] [pop []] [G] [dip swons] genrec
### Example
The `range` function generates a list of the integers from 0 to n - 1:
&gt; \[0 &lt;=\] \[\-\- dup\] anamorphism
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_pop">pop</a> []] <a href="#function_swap">swap</a> [<a href="#function_dip">dip</a> <a href="#function_swons">swons</a>] <a href="#function_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="#function_range" class="func_name">range</a></div></div><hr><div><h2 id="function_and" class="func_name">and <a href="#function_and" class="self_link"></a></h2><pre>
Logical bit-wise AND.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_nulco">nulco</a> [<a href="#function_nullary">nullary</a> [<a href="#">false</a>]] <a href="#function_dip">dip</a> <a href="#function_branch">branch</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_or" class="func_name">or</a> <a href="#function_xor" class="func_name">xor</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1 <a href="#function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
"apply one"
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.
... x [Q] app1
---------------------------------
... [x ...] [Q] infra first
This is the same effect as the [unary](#unary) combinator.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_grba">grba</a> <a href="#function_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="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a> <a href="#function_appN" class="func_name">appN</a> <a href="#function_unary" class="func_name">unary</a></div></div><hr><div><h2 id="function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2 <a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Like [app1](#app1) with two items.
... y x [Q] . app2
-----------------------------------
... [y ...] [Q] . infra first
[x ...] [Q] infra first
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_grba">grba</a> <a href="#function_swap">swap</a> <a href="#function_grba">grba</a> <a href="#function_swap">swap</a>] <a href="#function_dip">dip</a> [<a href="#function_infrst">infrst</a>] <a href="#function_cons">cons</a> <a href="#function_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="#function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#function_697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a> <a href="#function_appN" class="func_name">appN</a> <a href="#function_unary" class="func_name">unary</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_fork" class="func_name">fork</a></div></div><hr><div><h2 id="function_697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3 <a href="#function_697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Like [app1] with three items.
... z y x [Q] . app3
-----------------------------------
... [z ...] [Q] . infra first
[y ...] [Q] infra first
[x ...] [Q] infra first
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">3</a> <a href="#function_appN">appN</a></blockquote></div><div class="discussion"><h3>Discussion</h3>See [app2].</div><div class="crosslinks"><h3>See Also</h3><a href="#function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_appN" class="func_name">appN</a> <a href="#function_unary" class="func_name">unary</a></div></div><hr><div><h2 id="function_appN" class="func_name">appN <a href="#function_appN" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Like [app1] with any number of items.
... xN ... x2 x1 x0 [Q] n . appN
--------------------------------------
... [xN ...] [Q] . infra first
...
[x2 ...] [Q] infra first
[x1 ...] [Q] infra first
[x0 ...] [Q] infra first
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_grabN">grabN</a>] <a href="#function_codi">codi</a> <a href="#function_map">map</a> <a href="#function_reverse">reverse</a> <a href="#function_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="#function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a> <a href="#function_unary" class="func_name">unary</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a></div></div><hr><div><h2 id="function_at" class="func_name">at <a href="#function_at" class="self_link"></a></h2><pre>
See [getitem](#getitem).
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_drop">drop</a> <a href="#function_first">first</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_of" class="func_name">of</a></div></div><hr><div><h2 id="function_average" class="func_name">average <a href="#function_average" class="self_link"></a></h2><pre>
Compute the average of a list of numbers.
(Currently broken until I can figure out what to do about "numeric tower"
in Thun.)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_sum">sum</a>] [<a href="#function_size">size</a>] <a href="#function_cleave">cleave</a> <a href="#function_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="function_b" class="func_name">b <a href="#function_b" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run two quoted programs
[P] [Q] b
---------------
P Q
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_i">i</a>] <a href="#function_dip">dip</a> <a href="#function_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="#function_dupdip" class="func_name">dupdip</a> <a href="#function_ii" class="func_name">ii</a></div></div><hr><div><h2 id="function_binary" class="func_name">binary <a href="#function_binary" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run a quoted program using exactly two stack values and leave the first
item of the result on the stack.
... y x [P] binary
-----------------------
... a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_unary">unary</a> <a href="#function_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="#function_nullary" class="func_name">nullary</a> <a href="#function_ternary" class="func_name">ternary</a> <a href="#function_unary" class="func_name">unary</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_ternary" class="func_name">ternary</a></div></div><hr><div><h2 id="function_bool" class="func_name">bool <a href="#function_bool" class="self_link"></a></h2><pre>
Convert the item on the top of the stack to a Boolean value.
</pre><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="#function_not" class="func_name">not</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="func_name">?</a> <a href="#" class="func_name">null</a></div></div><hr><div><h2 id="function_branch" class="func_name">branch <a href="#function_branch" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Use a Boolean value to select and run one of two quoted programs.
false [F] [T] branch
--------------------------
F
true [F] [T] branch
-------------------------
T
</pre><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="#function_choice" class="func_name">choice</a> <a href="#function_ifte" class="func_name">ifte</a> <a href="#function_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="#function_abs" class="func_name">abs</a> <a href="#function_and" class="func_name">and</a> <a href="#function_ifte" class="func_name">ifte</a> <a href="#function_not" class="func_name">not</a> <a href="#function_or" class="func_name">or</a> <a href="#" class="func_name">small</a> <a href="#function_xor" class="func_name">xor</a></div></div><hr><div><h2 id="function_ccccons" class="func_name">ccccons <a href="#function_ccccons" class="self_link"></a></h2><pre>
a b c d [...] ccccons
---------------------------
[a b c d ...]
Do [cons] four times.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_ccons">ccons</a> <a href="#function_ccons">ccons</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_ccons" class="func_name">ccons</a> <a href="#function_cons" class="func_name">cons</a> <a href="#function_times" class="func_name">times</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_genrec" class="func_name">genrec</a></div></div><hr><div><h2 id="function_ccons" class="func_name">ccons <a href="#function_ccons" class="self_link"></a></h2><pre>
a b [...] ccons
---------------------
[a b ...]
Do [cons] two times.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_cons">cons</a> <a href="#function_cons">cons</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_cons" class="func_name">cons</a> <a href="#function_ccons" class="func_name">ccons</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_ccccons" class="func_name">ccccons</a> <a href="#function_cmp" class="func_name">cmp</a> <a href="#function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator</a></div></div><hr><div><h2 id="function_choice" class="func_name">choice <a href="#function_choice" class="self_link"></a></h2><pre>
Use a Boolean value to select one of two items.
a b false choice
----------------------
a
a b true choice
---------------------
b
</pre><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="#function_branch" class="func_name">branch</a> <a href="#function_select" class="func_name">select</a></div></div><hr><div><h2 id="function_clear" class="func_name">clear <a href="#function_clear" class="self_link"></a></h2><pre>
Clear everything from the stack.
</pre><div class="definition"><h3>Definition</h3><blockquote>[] <a href="#function_swaack">swaack</a> <a href="#function_pop">pop</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_stack" class="func_name">stack</a> <a href="#function_swaack" class="func_name">swaack</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_enstacken" class="func_name">enstacken</a></div></div><hr><div><h2 id="function_cleave" class="func_name">cleave <a href="#function_cleave" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run two programs in parallel, consuming one additional item, and put their
results on the stack.
... x [A] [B] cleave
------------------------
... a b
### Derivation
&gt; [fork] [popdd]
### Example
1 2 3 [+] [-] cleave
--------------------------
1 2 5 -1
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_fork">fork</a> <a href="#function_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="#function_clop" class="func_name">clop</a> <a href="#function_fork" class="func_name">fork</a> <a href="#function_map" class="func_name">map</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_average" class="func_name">average</a> <a href="#function_clop" class="func_name">clop</a></div></div><hr><div><h2 id="function_clop" class="func_name">clop <a href="#function_clop" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run two programs in parallel, consuming two additional items, and put their results on the stack.
... x y [A] [B] clop
--------------------------
... a b
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_cleave">cleave</a> <a href="#function_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="#function_cleave" class="func_name">cleave</a> <a href="#function_fork" class="func_name">fork</a> <a href="#function_map" class="func_name">map</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_divmod" class="func_name">divmod</a> <a href="#function_pm" class="func_name">pm</a> <a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="function_cmp" class="func_name">cmp <a href="#function_cmp" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
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.
a b [G] [E] [L] cmp
------------------------- a &gt; b
G
a b [G] [E] [L] cmp
------------------------- a = b
E
a b [G] [E] [L] cmp
------------------------- a &lt; b
L</pre><div class="definition"><h3>Definition</h3><blockquote>[[<a href="#function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">&gt;</a>] <a href="#function_swap">swap</a>] <a href="#function_dipd">dipd</a> [<a href="#function_ifte">ifte</a>] <a href="#function_ccons">ccons</a> [<a href="#function_380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3">=</a>] <a href="#function_swons">swons</a> <a href="#function_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 [&lt;=] or [&gt;=]
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="#function_eq" class="func_name">eq</a> <a href="#function_ge" class="func_name">ge</a> <a href="#function_gt" class="func_name">gt</a> <a href="#function_le" class="func_name">le</a> <a href="#function_lt" class="func_name">lt</a> <a href="#" class="func_name">neq</a></div></div><hr><div><h2 id="function_codi" class="func_name">codi <a href="#function_codi" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
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.
a b [F] . codi
--------------------
b . F a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_cons">cons</a> <a href="#function_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="#function_appN" class="func_name">appN</a> <a href="#function_codireco" class="func_name">codireco</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_appN" class="func_name">appN</a> <a href="#function_codireco" class="func_name">codireco</a> <a href="#function_dipd" class="func_name">dipd</a></div></div><hr><div><h2 id="function_codireco" class="func_name">codireco <a href="#function_codireco" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
This is part of the [make_generator] function. You would not use this
combinator directly.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_codi">codi</a> <a href="#function_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="#function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator</a></div></div><hr><div><h2 id="function_concat" class="func_name">concat <a href="#function_concat" class="self_link"></a></h2><pre>
Concatinate two lists.
[a b c] [d e f] concat
----------------------------
[a b c d e f]
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_first" class="func_name">first</a> <a href="#function_07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two</a> <a href="#function_flatten" class="func_name">flatten</a> <a href="#function_fourth" class="func_name">fourth</a> <a href="#function_getitem" class="func_name">getitem</a> <a href="#function_remove" class="func_name">remove</a> <a href="#function_rest" class="func_name">rest</a> <a href="#function_reverse" class="func_name">reverse</a> <a href="#function_rrest" class="func_name">rrest</a> <a href="#function_second" class="func_name">second</a> <a href="#function_shift" class="func_name">shift</a> <a href="#function_shunt" class="func_name">shunt</a> <a href="#function_size" class="func_name">size</a> <a href="#function_sort" class="func_name">sort</a> <a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a> <a href="#function_swaack" class="func_name">swaack</a> <a href="#function_third" class="func_name">third</a> <a href="#function_zip" class="func_name">zip</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_flatten" class="func_name">flatten</a> <a href="#function_genrec" class="func_name">genrec</a> <a href="#" class="func_name">null</a> <a href="#function_swoncat" class="func_name">swoncat</a> <a href="#function_while" class="func_name">while</a></div></div><hr><div><h2 id="function_cond" class="func_name">cond <a href="#function_cond" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
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
`true`. If no predicates return `true` the default function runs.
[
[ [Predicate0] Function0 ]
[ [Predicate1] Function1 ]
...
[ [PredicateN] FunctionN ]
[Default]
]
cond
</pre><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="#function_ifte" class="func_name">ifte</a></div></div><hr><div><h2 id="function_cons" class="func_name">cons <a href="#function_cons" class="self_link"></a></h2><pre>
Given an item and a list, append the item to the list to make a new list.
a [...] cons
------------------
[a ...]
</pre><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="#function_uncons" class="func_name">uncons</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_ccons" class="func_name">ccons</a> <a href="#function_codi" class="func_name">codi</a> <a href="#function_grabN" class="func_name">grabN</a> <a href="#function_map" class="func_name">map</a> <a href="#function_nulco" class="func_name">nulco</a> <a href="#function_pow" class="func_name">pow</a> <a href="#function_reco" class="func_name">reco</a> <a href="#function_swons" class="func_name">swons</a> <a href="#function_unit" class="func_name">unit</a></div></div><hr><div><h2 id="function_dinfrirst" class="func_name">dinfrirst <a href="#function_dinfrirst" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Specialist function (that means I forgot what it does and why.)
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_dip">dip</a> <a href="#function_infrst">infrst</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_nullary" class="func_name">nullary</a></div></div><hr><div><h2 id="function_dip" class="func_name">dip <a href="#function_dip" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
The `dip` 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.
... x [Q] . dip
---------------------
... . Q x
</pre><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="#function_dipd" class="func_name">dipd</a> <a href="#function_dipdd" class="func_name">dipdd</a> <a href="#function_dupdip" class="func_name">dupdip</a> <a href="#function_dupdipd" class="func_name">dupdipd</a> <a href="#function_infra" class="func_name">infra</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_anamorphism" class="func_name">anamorphism</a> <a href="#function_and" class="func_name">and</a> <a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_b" class="func_name">b</a> <a href="#function_codi" class="func_name">codi</a> <a href="#function_dinfrirst" class="func_name">dinfrirst</a> <a href="#function_dipd" class="func_name">dipd</a> <a href="#function_dupd" class="func_name">dupd</a> <a href="#function_dupdip" class="func_name">dupdip</a> <a href="#function_enstacken" class="func_name">enstacken</a> <a href="#function_grba" class="func_name">grba</a> <a href="#function_ii" class="func_name">ii</a> <a href="#function_infra" class="func_name">infra</a> <a href="#function_map" class="func_name">map</a> <a href="#function_or" class="func_name">or</a> <a href="#function_over" class="func_name">over</a> <a href="#function_popd" class="func_name">popd</a> <a href="#function_popopd" class="func_name">popopd</a> <a href="#function_quoted" class="func_name">quoted</a> <a href="#function_shift" class="func_name">shift</a> <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a> <a href="#function_stackd" class="func_name">stackd</a> <a href="#function_swapd" class="func_name">swapd</a> <a href="#function_unquoted" class="func_name">unquoted</a> <a href="#" class="func_name">unstack</a></div></div><hr><div><h2 id="function_dipd" class="func_name">dipd <a href="#function_dipd" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Like [dip] but expects two items.
... y x [Q] . dipd
-------------------------
... . Q y x
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_dip">dip</a>] <a href="#function_codi">codi</a></blockquote></div><div class="discussion"><h3>Discussion</h3>See [dip].</div><div class="crosslinks"><h3>See Also</h3><a href="#function_dip" class="func_name">dip</a> <a href="#function_dipdd" class="func_name">dipdd</a> <a href="#function_dupdip" class="func_name">dupdip</a> <a href="#function_dupdipd" class="func_name">dupdipd</a> <a href="#function_infra" class="func_name">infra</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_dupdd" class="func_name">dupdd</a> <a href="#function_dupdipd" class="func_name">dupdipd</a> <a href="#function_ifte" class="func_name">ifte</a> <a href="#function_popdd" class="func_name">popdd</a> <a href="#function_popopdd" class="func_name">popopdd</a></div></div><hr><div><h2 id="function_dipdd" class="func_name">dipdd <a href="#function_dipdd" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Like [dip] but expects three items. :
... z y x [Q] . dip
-----------------------------
... . Q z y x</pre><div class="discussion"><h3>Discussion</h3>See [dip].</div><div class="crosslinks"><h3>See Also</h3><a href="#function_dip" class="func_name">dip</a> <a href="#function_dipd" class="func_name">dipd</a> <a href="#function_dupdip" class="func_name">dupdip</a> <a href="#function_dupdipd" class="func_name">dupdipd</a> <a href="#function_infra" class="func_name">infra</a></div></div><hr><div><h2 id="function_disenstacken" class="func_name">disenstacken <a href="#function_disenstacken" class="self_link"></a></h2><pre>
The `disenstacken` function expects a list on top of the stack and makes
that the stack discarding the rest of the stack.
1 2 3 [4 5 6] disenstacken
--------------------------------
6 5 4
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_swaack">swaack</a> <a href="#function_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="#function_enstacken" class="func_name">enstacken</a> <a href="#function_stack" class="func_name">stack</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_appN" class="func_name">appN</a></div></div><hr><div><h2 id="function_div" class="func_name">div <a href="#function_div" class="self_link"></a></h2><pre>
See [floordiv](#floordiv).
</pre></div><hr><div><h2 id="function_divmod" class="func_name">divmod <a href="#function_divmod" class="self_link"></a></h2><pre>
x y divmod
------------------
q r
(x/y) (x%y)
Invariant: `qy + r = x`.
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a>] [<a href="#function_bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a>] <a href="#function_clop">clop</a></blockquote></div></div><hr><div><h2 id="function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero <a href="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="self_link"></a></h2><pre>
Given a number greater than zero put all the Natural numbers (including
zero) less than that onto the stack.
### Example
3 down_to_zero
--------------------
3 2 1 0
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">0</a> <a href="#function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">&gt;</a>] [<a href="#function_dup">dup</a> <a href="#function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a>] <a href="#function_while">while</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_range" class="func_name">range</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero</a></div></div><hr><div><h2 id="function_drop" class="func_name">drop <a href="#function_drop" class="self_link"></a></h2><pre>
Expects an integer and a quote on the stack and returns the quote with n
items removed off the top.
### Example
[a b c d] 2 drop
----------------------
[c d]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_rest">rest</a>] <a href="#function_times">times</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_take" class="func_name">take</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_at" class="func_name">at</a> <a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="function_dup" class="func_name">dup <a href="#function_dup" class="self_link"></a></h2><pre>
"Dup"licate the top item on the stack.
a dup
-----------
a a
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_dupd" class="func_name">dupd</a> <a href="#function_dupdd" class="func_name">dupdd</a> <a href="#function_dupdip" class="func_name">dupdip</a> <a href="#function_dupdipd" class="func_name">dupdipd</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="func_name">?</a> <a href="#function_abs" class="func_name">abs</a> <a href="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#function_dupd" class="func_name">dupd</a> <a href="#function_dupdd" class="func_name">dupdd</a> <a href="#function_dupdipd" class="func_name">dupdipd</a> <a href="#function_gcd" class="func_name">gcd</a> <a href="#function_over" class="func_name">over</a> <a href="#function_range" class="func_name">range</a> <a href="#" class="func_name">small</a> <a href="#function_sqr" class="func_name">sqr</a> <a href="#function_tuck" class="func_name">tuck</a> <a href="#function_x" class="func_name">x</a></div></div><hr><div><h2 id="function_dupd" class="func_name">dupd <a href="#function_dupd" class="self_link"></a></h2><pre>
[dup] the second item down on the stack.
a b dupd
--------------
a a b
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_dup">dup</a>] <a href="#function_dip">dip</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_dup" class="func_name">dup</a> <a href="#function_dupdd" class="func_name">dupdd</a> <a href="#function_dupdip" class="func_name">dupdip</a> <a href="#function_dupdipd" class="func_name">dupdipd</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_dupdip" class="func_name">dupdip</a></div></div><hr><div><h2 id="function_dupdd" class="func_name">dupdd <a href="#function_dupdd" class="self_link"></a></h2><pre>
[dup] the third item down on the stack.
a b c dupdd
-----------------
a a b c
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_dup">dup</a>] <a href="#function_dipd">dipd</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_dup" class="func_name">dup</a> <a href="#function_dupd" class="func_name">dupd</a> <a href="#function_dupdip" class="func_name">dupdip</a> <a href="#function_dupdipd" class="func_name">dupdipd</a></div></div><hr><div><h2 id="function_dupdip" class="func_name">dupdip <a href="#function_dupdip" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Apply a function `F` and [dup] the item under it on the stack.
a [F] dupdip
------------------
a F a
### Derivation
a [F] dupdip
a [F] dupd dip
a [F] [dup] dip dip
a dup [F] dip
a a [F] dip
a F a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_dupd">dupd</a> <a href="#function_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="#function_dupdipd" class="func_name">dupdipd</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_ii" class="func_name">ii</a> <a href="#function_uncons" class="func_name">uncons</a></div></div><hr><div><h2 id="function_dupdipd" class="func_name">dupdipd <a href="#function_dupdipd" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run a copy of program `F` under the next item down on the stack.
a [F] dupdipd
-------------------
F a [F]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_dup">dup</a> <a href="#function_dipd">dipd</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_dupdip" class="func_name">dupdip</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_while" class="func_name">while</a></div></div><hr><div><h2 id="function_enstacken" class="func_name">enstacken <a href="#function_enstacken" class="self_link"></a></h2><pre>
Put the stack onto the stack replacing the contents of the stack.
... a b c enstacken
-------------------------
[c b a ...]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_stack">stack</a> [<a href="#function_clear">clear</a>] <a href="#function_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="#function_stack" class="func_name">stack</a> <a href="#function_disenstacken" class="func_name">disenstacken</a></div></div><hr><div><h2 id="function_eq" class="func_name">eq <a href="#function_eq" class="self_link"></a></h2><pre>
Compare the two items on the top of the stack for equality and replace
them with a Boolean value.
a b eq
-------------
Boolean
(a = b)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">false</a>] [<a href="#">true</a>] [<a href="#">false</a>] <a href="#function_cmp">cmp</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_ge" class="func_name">ge</a> <a href="#function_gt" class="func_name">gt</a> <a href="#function_le" class="func_name">le</a> <a href="#function_lt" class="func_name">lt</a> <a href="#function_ne" class="func_name">ne</a></div></div><hr><div><h2 id="function_first" class="func_name">first <a href="#function_first" class="self_link"></a></h2><pre>
Replace a list with its first item.
[a ...]
--------------
a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_uncons">uncons</a> <a href="#function_pop">pop</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_second" class="func_name">second</a> <a href="#function_third" class="func_name">third</a> <a href="#function_fourth" class="func_name">fourth</a> <a href="#function_rest" class="func_name">rest</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_at" class="func_name">at</a> <a href="#function_infrst" class="func_name">infrst</a> <a href="#function_second" class="func_name">second</a> <a href="#function_uncons" class="func_name">uncons</a></div></div><hr><div><h2 id="function_07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two <a href="#function_07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="self_link"></a></h2><pre>
Replace a list with its first two items.
[a b ...] first_two
-------------------------
a b
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_first" class="func_name">first</a> <a href="#function_second" class="func_name">second</a> <a href="#function_third" class="func_name">third</a> <a href="#function_fourth" class="func_name">fourth</a> <a href="#function_rest" class="func_name">rest</a></div></div><hr><div><h2 id="function_flatten" class="func_name">flatten <a href="#function_flatten" class="self_link"></a></h2><pre>
Given a list of lists, concatinate them.
### Example
[[1 2] [3 [4] 5] [6 7]] flatten
-------------------------------------
[1 2 3 [4] 5 6 7]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a> [<a href="#function_concat">concat</a>] <a href="#function_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="#function_concat" class="func_name">concat</a> <a href="#function_first" class="func_name">first</a> <a href="#function_07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two</a> <a href="#function_fourth" class="func_name">fourth</a> <a href="#function_getitem" class="func_name">getitem</a> <a href="#function_remove" class="func_name">remove</a> <a href="#function_rest" class="func_name">rest</a> <a href="#function_reverse" class="func_name">reverse</a> <a href="#function_rrest" class="func_name">rrest</a> <a href="#function_second" class="func_name">second</a> <a href="#function_shift" class="func_name">shift</a> <a href="#function_shunt" class="func_name">shunt</a> <a href="#function_size" class="func_name">size</a> <a href="#function_sort" class="func_name">sort</a> <a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a> <a href="#function_swaack" class="func_name">swaack</a> <a href="#function_third" class="func_name">third</a> <a href="#function_zip" class="func_name">zip</a></div></div><hr><div><h2 id="function_floor" class="func_name">floor <a href="#function_floor" class="self_link"></a></h2><pre>
Return the largest integer \&lt;= x.
</pre><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="function_floordiv" class="func_name">floordiv <a href="#function_floordiv" class="self_link"></a></h2><pre>
I don't know why this is called "floor" div, I think it rounds its
result down (not towards zero or up.)
a b floordiv
------------------
(a/b)
</pre><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="#function_divmod" class="func_name">divmod</a></div></div><hr><div><h2 id="function_fork" class="func_name">fork <a href="#function_fork" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run two quoted programs in parallel and replace them with their results.
... [F] [G] fork
----------------------
... f g
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_i">i</a>] <a href="#function_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="#function_cleave" class="func_name">cleave</a> <a href="#function_clop" class="func_name">clop</a> <a href="#function_map" class="func_name">map</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_cleave" class="func_name">cleave</a></div></div><hr><div><h2 id="function_fourth" class="func_name">fourth <a href="#function_fourth" class="self_link"></a></h2><pre>
Replace a list with its fourth item.
[a b c d ...] fourth
--------------------------
d
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_rest">rest</a> <a href="#function_third">third</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_first" class="func_name">first</a> <a href="#function_second" class="func_name">second</a> <a href="#function_third" class="func_name">third</a> <a href="#function_rest" class="func_name">rest</a></div></div><hr><div><h2 id="function_gcd" class="func_name">gcd <a href="#function_gcd" class="self_link"></a></h2><pre>
Take two integers from the stack and replace them with their Greatest
Common Denominator.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">true</a> [<a href="#function_tuck">tuck</a> <a href="#function_mod">mod</a> <a href="#function_dup">dup</a> <a href="#">0</a> <a href="#function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">&gt;</a>] <a href="#function_loop">loop</a> <a href="#function_pop">pop</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Euclid's Algorithm</div></div><hr><div><h2 id="function_ab323e8d4f8c5d1c7d333fbe3e08b223c11f7bcc5066ace0af17172f77aa31b3" class="func_name">gcd2 <a href="#function_ab323e8d4f8c5d1c7d333fbe3e08b223c11f7bcc5066ace0af17172f77aa31b3" class="self_link"></a></h2><pre>
Compiled GCD function.
</pre><div class="discussion"><h3>Discussion</h3>See [gcd].</div><div class="crosslinks"><h3>See Also</h3><a href="#function_gcd" class="func_name">gcd</a></div></div><hr><div><h2 id="function_ge" class="func_name">ge <a href="#function_ge" class="self_link"></a></h2><pre>
Greater-than-or-equal-to comparison of two numbers.
a b ge
--------------
Boolean
(a &gt;= b)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">true</a>] [<a href="#">true</a>] [<a href="#">false</a>] <a href="#function_cmp">cmp</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_eq" class="func_name">eq</a> <a href="#function_gt" class="func_name">gt</a> <a href="#function_le" class="func_name">le</a> <a href="#function_lt" class="func_name">lt</a> <a href="#function_ne" class="func_name">ne</a></div></div><hr><div><h2 id="function_genrec" class="func_name">genrec <a href="#function_genrec" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
**Gen**eral **Rec**ursion Combinator.
[if] [then] [rec1] [rec2] genrec
---------------------------------------------------------------------
[if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte
</pre><div class="definition"><h3>Definition</h3><blockquote>[[<a href="#function_genrec">genrec</a>] <a href="#function_ccccons">ccccons</a>] <a href="#function_nullary">nullary</a> <a href="#function_swons">swons</a> <a href="#function_concat">concat</a> <a href="#function_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:
&gt; "The genrec combinator takes four program parameters in addition to
&gt; whatever data parameters it needs. Fourth from the top is an if-part,
&gt; followed by a then-part. If the if-part yields true, then the then-part
&gt; is executed and the combinator terminates. The other two parameters are
&gt; the rec1-part and the rec2-part. If the if-part yields false, the
&gt; rec1-part is executed. Following that the four program parameters and
&gt; the combinator are again pushed onto the stack bundled up in a quoted
&gt; form. Then the rec2-part is executed, where it will find the bundled
&gt; form. Typically it will then execute the bundled form, either with i
&gt; 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="#function_anamorphism" class="func_name">anamorphism</a> <a href="#function_tailrec" class="func_name">tailrec</a> <a href="#function_x" class="func_name">x</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_anamorphism" class="func_name">anamorphism</a> <a href="#function_genrec" class="func_name">genrec</a> <a href="#function_tailrec" class="func_name">tailrec</a></div></div><hr><div><h2 id="function_getitem" class="func_name">getitem <a href="#function_getitem" class="self_link"></a></h2><pre>
Expects an integer and a quote on the stack and returns the item at the
nth position in the quote counting from 0.
### Example
[a b c d] 2 getitem
-------------------------
c
</pre><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="#function_concat" class="func_name">concat</a> <a href="#function_first" class="func_name">first</a> <a href="#function_07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two</a> <a href="#function_flatten" class="func_name">flatten</a> <a href="#function_fourth" class="func_name">fourth</a> <a href="#function_remove" class="func_name">remove</a> <a href="#function_rest" class="func_name">rest</a> <a href="#function_reverse" class="func_name">reverse</a> <a href="#function_rrest" class="func_name">rrest</a> <a href="#function_second" class="func_name">second</a> <a href="#function_shift" class="func_name">shift</a> <a href="#function_shunt" class="func_name">shunt</a> <a href="#function_size" class="func_name">size</a> <a href="#function_sort" class="func_name">sort</a> <a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a> <a href="#function_swaack" class="func_name">swaack</a> <a href="#function_third" class="func_name">third</a> <a href="#function_zip" class="func_name">zip</a></div></div><hr><div><h2 id="function_grabN" class="func_name">grabN <a href="#function_grabN" class="self_link"></a></h2><pre>
Expect a number on the top of the stack and [cons] that many items from under it onto a new list.
### Example
a b c d e 3 grabN
-----------------------
a b [c d e]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a> [<a href="#function_cons">cons</a>] <a href="#function_times">times</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_appN" class="func_name">appN</a></div></div><hr><div><h2 id="function_grba" class="func_name">grba <a href="#function_grba" class="self_link"></a></h2><pre>
A weird function used in [app2] that does this:
... 1 2 3 4 5 grba
-------------------------------
... 1 2 3 [4 3 2 1 ...] 5
It grabs the stack under the top item, and substitutes it for the second item down on the stack.
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_stack">stack</a> <a href="#function_popd">popd</a>] <a href="#function_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="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a></div></div><hr><div><h2 id="function_gt" class="func_name">gt <a href="#function_gt" class="self_link"></a></h2><pre>
Greater-than comparison of two numbers.
a b gt
--------------
Boolean
(a &gt; b)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">true</a>] [<a href="#">false</a>] [<a href="#">false</a>] <a href="#function_cmp">cmp</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_eq" class="func_name">eq</a> <a href="#function_ge" class="func_name">ge</a> <a href="#function_le" class="func_name">le</a> <a href="#function_lt" class="func_name">lt</a> <a href="#function_ne" class="func_name">ne</a></div></div><hr><div><h2 id="function_help" class="func_name">help <a href="#function_help" class="self_link"></a></h2><pre>
Accepts a quoted symbol on the top of the stack and prints its
documentation.
[foo] help
----------------
</pre><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="function_hypot" class="func_name">hypot <a href="#function_hypot" class="self_link"></a></h2><pre>
x y hypot
---------------------------
sqrt(sqr(x) + sqr(y))
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_sqr">sqr</a>] <a href="#function_ii">ii</a> <a href="#function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a> <a href="#function_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="#function_sqrt" class="func_name">sqrt</a></div></div><hr><div><h2 id="function_i" class="func_name">i <a href="#function_i" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Append a quoted expression onto the pending expression.
[Q] . i
-------------
. Q
</pre><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="#function_b" class="func_name">b</a> <a href="#function_fork" class="func_name">fork</a> <a href="#function_ii" class="func_name">ii</a> <a href="#function_infra" class="func_name">infra</a> <a href="#function_pam" class="func_name">pam</a> <a href="#function_tailrec" class="func_name">tailrec</a> <a href="#function_unquoted" class="func_name">unquoted</a> <a href="#function_x" class="func_name">x</a></div></div><hr><div><h2 id="function_id" class="func_name">id <a href="#function_id" class="self_link"></a></h2><pre>
The identity function.
</pre><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="function_ifte" class="func_name">ifte <a href="#function_ifte" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
If-Then-Else combinator, a common and convenient specialization of [branch].
[if] [then] [else] ifte
---------------------------------------
[if] nullary [else] [then] branch
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_nullary">nullary</a>] <a href="#function_dipd">dipd</a> <a href="#function_swap">swap</a> <a href="#function_branch">branch</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_branch" class="func_name">branch</a> <a href="#function_loop" class="func_name">loop</a> <a href="#function_while" class="func_name">while</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_genrec" class="func_name">genrec</a> <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_ii" class="func_name">ii <a href="#function_ii" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Take a quoted program from the stack and run it twice, first under the
top item, then again with the top item.
... a [Q] ii
------------------
... Q a Q
### Example
It's a little tricky to understand how this works so here's an example trace:
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 •
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_dip">dip</a>] <a href="#function_dupdip">dupdip</a> <a href="#function_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="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_b" class="func_name">b</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_hypot" class="func_name">hypot</a> <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_infra" class="func_name">infra <a href="#function_infra" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
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.)
... 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]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_swons">swons</a> <a href="#function_swaack">swaack</a> [<a href="#function_i">i</a>] <a href="#function_dip">dip</a> <a href="#function_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="#function_swaack" class="func_name">swaack</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_infrst" class="func_name">infrst</a> <a href="#function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero</a> <a href="#function_run" class="func_name">run</a></div></div><hr><div><h2 id="function_infrst" class="func_name">infrst <a href="#function_infrst" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Does [infra] and then extracts the [first] item from the resulting list.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_infra">infra</a> <a href="#function_first">first</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_dinfrirst" class="func_name">dinfrirst</a></div></div><hr><div><h2 id="function_inscribe" class="func_name">inscribe <a href="#function_inscribe" class="self_link"></a></h2><pre>
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.
### Example
[sqr dup mul] inscribe
</pre><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="function_le" class="func_name">le <a href="#function_le" class="self_link"></a></h2><pre>
Less-Than-or-Equal-to comparison of the two items on the top of the
stack, replacing them with a Boolean value.
a b le
-------------
Boolean
(a &lt;= b)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">false</a>] [<a href="#">true</a>] [<a href="#">true</a>] <a href="#function_cmp">cmp</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_eq" class="func_name">eq</a> <a href="#function_ge" class="func_name">ge</a> <a href="#function_gt" class="func_name">gt</a> <a href="#function_lt" class="func_name">lt</a> <a href="#function_ne" class="func_name">ne</a></div></div><hr><div><h2 id="function_loop" class="func_name">loop <a href="#function_loop" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Expect a quoted program `Q` and a Boolean value on the stack. If the value is false
discard the quoted program, otherwise run a copy of `Q` and `loop` again.
false [Q] loop
--------------------
true [Q] . loop
--------------------------
. Q [Q] loop
</pre><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),
&gt; 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="#function_branch" class="func_name">branch</a> <a href="#function_fork" class="func_name">fork</a> <a href="#function_while" class="func_name">while</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_gcd" class="func_name">gcd</a> <a href="#function_while" class="func_name">while</a></div></div><hr><div><h2 id="function_lshift" class="func_name">lshift <a href="#function_lshift" class="self_link"></a></h2><pre>
[Logical Left-Shift](https://en.wikipedia.org/wiki/Logical_shift)
a n lshift
----------------
(a×2ⁿ)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">2</a> <a href="#function_684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#function_times">times</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_rshift" class="func_name">rshift</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="func_name">&lt;&lt;</a></div></div><hr><div><h2 id="function_lt" class="func_name">lt <a href="#function_lt" class="self_link"></a></h2><pre>
Less-Than comparison of the two items on the top of the
stack, replacing them with a Boolean value.
a b lt
-------------
Boolean
(a &lt; b)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">false</a>] [<a href="#">false</a>] [<a href="#">true</a>] <a href="#function_cmp">cmp</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_eq" class="func_name">eq</a> <a href="#function_ge" class="func_name">ge</a> <a href="#function_gt" class="func_name">gt</a> <a href="#function_le" class="func_name">le</a> <a href="#function_ne" class="func_name">ne</a></div></div><hr><div><h2 id="function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator <a href="#function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="self_link"></a></h2><pre>
Given an initial state value and a quoted generator function build a
generator quote.
state [generator function] make_generator
-----------------------------------------------
[state [generator function] codireco]
### Example
230 [dup ++] make_generator
---------------------------------
[230 [dup ++] codireco]
And then:
[230 [dup ++] codireco] 5 [x] times pop
---------------------------------------------
230 231 232 233 234
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_codireco">codireco</a>] <a href="#function_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="#function_codireco" class="func_name">codireco</a></div></div><hr><div><h2 id="function_map" class="func_name">map <a href="#function_map" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
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.
### Example
5 [1 2 3] [++ *] map
--------------------------
5 [10 15 20]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">_map0</a>] <a href="#function_cons">cons</a> [[] [<a href="#">_map?</a>] [<a href="#">_mape</a>]] <a href="#function_dip">dip</a> <a href="#function_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="#function_172dd4a0366000604e2c4de41457aa1eb3093bb59ead22e0f1d472a2aaade094" class="func_name">app1</a> <a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_697d4aeb7c587123c345cec0c8fe5955546ef349830b08b71fa32f910c83c868" class="func_name">app3</a> <a href="#function_appN" class="func_name">appN</a> <a href="#function_fork" class="func_name">fork</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_appN" class="func_name">appN</a> <a href="#function_pam" class="func_name">pam</a></div></div><hr><div><h2 id="function_max" class="func_name">max <a href="#function_max" class="self_link"></a></h2><pre>
Given a list find the maximum.
### Example
[1 2 3 4] max
-------------------
4
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_min" class="func_name">min</a> <a href="#function_size" class="func_name">size</a> <a href="#function_sum" class="func_name">sum</a></div></div><hr><div><h2 id="function_min" class="func_name">min <a href="#function_min" class="self_link"></a></h2><pre>
Given a list find the minimum.
### Example
[1 2 3 4] min
-------------------
1
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_max" class="func_name">max</a> <a href="#function_size" class="func_name">size</a> <a href="#function_sum" class="func_name">sum</a></div></div><hr><div><h2 id="function_mod" class="func_name">mod <a href="#function_mod" class="self_link"></a></h2><pre>
Return the remainder of `a` divided by `b`.
a b mod
-------------
(a%b)
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_divmod" class="func_name">divmod</a> <a href="#function_mul" class="func_name">mul</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_gcd" class="func_name">gcd</a></div></div><hr><div><h2 id="function_modulus" class="func_name">modulus <a href="#function_modulus" class="self_link"></a></h2><pre>
See [mod](#mod).
</pre></div><hr><div><h2 id="function_mul" class="func_name">mul <a href="#function_mul" class="self_link"></a></h2><pre>
Multiply two numbers.
a b mul
-------------
(a×b)
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_div" class="func_name">div</a> <a href="#function_product" class="func_name">product</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_sqr" class="func_name">sqr</a></div></div><hr><div><h2 id="function_ne" class="func_name">ne <a href="#function_ne" class="self_link"></a></h2><pre>
Not-Equal comparison of the two items on the top of the
stack, replacing them with a Boolean value.
a b ne
-------------
Boolean
(a = b)
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_cmp" class="func_name">cmp</a> <a href="#function_eq" class="func_name">eq</a> <a href="#function_ge" class="func_name">ge</a> <a href="#function_gt" class="func_name">gt</a> <a href="#function_le" class="func_name">le</a> <a href="#function_lt" class="func_name">lt</a></div></div><hr><div><h2 id="function_neg" class="func_name">neg <a href="#function_neg" class="self_link"></a></h2><pre>
Invert the sign of a number.
a neg
-----------
-a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">0</a> <a href="#function_swap">swap</a> <a href="#function_3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_abs" class="func_name">abs</a></div></div><hr><div><h2 id="function_not" class="func_name">not <a href="#function_not" class="self_link"></a></h2><pre>
Like [bool] but convert the item on the top of the stack to the inverse
Boolean value.
true not
--------------
false
false not
---------------
true
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">true</a>] [<a href="#">false</a>] <a href="#function_branch">branch</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_bool" class="func_name">bool</a></div><div class="backlinks"><h3>Used By</h3><a href="#" class="func_name">null</a> <a href="#function_xor" class="func_name">xor</a></div></div><hr><div><h2 id="function_nulco" class="func_name">nulco <a href="#function_nulco" class="self_link"></a></h2><pre>
Take the item on the top of the stack and [cons] it onto `[nullary]`.
[F] nulco
-------------------
[[F] nullary]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_nullary">nullary</a>] <a href="#function_cons">cons</a></blockquote></div><div class="discussion"><h3>Discussion</h3>Helper function for [\|\|] and [&amp;&amp;].</div><div class="crosslinks"><h3>See Also</h3><a href="#function_73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" class="func_name">&amp;&amp;</a> <a href="#function_565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866" class="func_name">||</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_and" class="func_name">and</a> <a href="#function_or" class="func_name">or</a> <a href="#function_while" class="func_name">while</a></div></div><hr><div><h2 id="function_nullary" class="func_name">nullary <a href="#function_nullary" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run a quoted program without using any stack values and leave the first
item of the result on the stack.
... [P] nullary
---------------------
... a
### Example
... [P] nullary
... [P] [stack] dip infra first
... stack [P] infra first
... [...] [P] infra first
... [a ...] first
... a
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_stack">stack</a>] <a href="#function_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="#function_unary" class="func_name">unary</a> <a href="#function_binary" class="func_name">binary</a> <a href="#function_ternary" class="func_name">ternary</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_and" class="func_name">and</a> <a href="#function_genrec" class="func_name">genrec</a> <a href="#function_ifte" class="func_name">ifte</a> <a href="#function_nulco" class="func_name">nulco</a> <a href="#function_or" class="func_name">or</a> <a href="#function_unary" class="func_name">unary</a></div></div><hr><div><h2 id="function_of" class="func_name">of <a href="#function_of" class="self_link"></a></h2><pre>
Like [getitem] but [swap]s the order of arguments.
### Example
2 [a b c d] of
--------------------
c
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_swap">swap</a> <a href="#function_at">at</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_getitem" class="func_name">getitem</a></div></div><hr><div><h2 id="function_or" class="func_name">or <a href="#function_or" class="self_link"></a></h2><pre>
Logical bit-wise OR.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_nulco">nulco</a> [<a href="#function_nullary">nullary</a>] <a href="#function_dip">dip</a> [<a href="#">true</a>] <a href="#function_branch">branch</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_and" class="func_name">and</a> <a href="#function_xor" class="func_name">xor</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a></div></div><hr><div><h2 id="function_over" class="func_name">over <a href="#function_over" class="self_link"></a></h2><pre>
[dup] the second item on the stack `over` the first.
a b over
--------------
a b a
### Definition
There are many many ways to define this function.
&gt; [swap] [tuck]
&gt; \[[pop]\] [nullary]
&gt; \[[dup]\] [dip] [swap]
&gt; [unit] [dupdip]
&gt; [unit] [dupdipd] [first]
And so on...
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_dup">dup</a>] <a href="#function_dip">dip</a> <a href="#function_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="#function_tuck" class="func_name">tuck</a></div></div><hr><div><h2 id="function_pam" class="func_name">pam <a href="#function_pam" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
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.)
### Example
5 7 [[+][-][*][/][%]] pam
-------------------------------
5 7 [12 -2 35 0 5]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_i">i</a>] <a href="#function_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="#function_map" class="func_name">map</a></div></div><hr><div><h2 id="function_pick" class="func_name">pick <a href="#function_pick" class="self_link"></a></h2><pre>
See [getitem](#getitem).
</pre></div><hr><div><h2 id="function_pm" class="func_name">pm <a href="#function_pm" class="self_link"></a></h2><pre>
Plus or minus. Replace two numbers with their sum and difference.
a b pm
-----------------
(a+b) (a-b)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a>] [<a href="#function_3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112">-</a>] <a href="#function_clop">clop</a></blockquote></div></div><hr><div><h2 id="function_pop" class="func_name">pop <a href="#function_pop" class="self_link"></a></h2><pre>
Pop the top item from the stack and discard it.
a pop
-----------
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_popd" class="func_name">popd</a> <a href="#function_popdd" class="func_name">popdd</a> <a href="#function_popop" class="func_name">popop</a> <a href="#function_popopd" class="func_name">popopd</a> <a href="#function_popopdd" class="func_name">popopdd</a> <a href="#function_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="#function_anamorphism" class="func_name">anamorphism</a> <a href="#function_clear" class="func_name">clear</a> <a href="#function_disenstacken" class="func_name">disenstacken</a> <a href="#function_first" class="func_name">first</a> <a href="#function_gcd" class="func_name">gcd</a> <a href="#function_popd" class="func_name">popd</a> <a href="#function_popdd" class="func_name">popdd</a> <a href="#function_popop" class="func_name">popop</a> <a href="#function_popopop" class="func_name">popopop</a> <a href="#function_size" class="func_name">size</a> <a href="#" class="func_name">small</a> <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next</a> <a href="#function_take" class="func_name">take</a> <a href="#" class="func_name">unstack</a></div></div><hr><div><h2 id="function_popd" class="func_name">popd <a href="#function_popd" class="self_link"></a></h2><pre>
[pop] the second item down on the stack.
a b popd
--------------
b
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_pop">pop</a>] <a href="#function_dip">dip</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_pop" class="func_name">pop</a> <a href="#function_popdd" class="func_name">popdd</a> <a href="#function_popop" class="func_name">popop</a> <a href="#function_popopd" class="func_name">popopd</a> <a href="#function_popopdd" class="func_name">popopdd</a> <a href="#function_popopop" class="func_name">popopop</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_binary" class="func_name">binary</a> <a href="#function_grba" class="func_name">grba</a> <a href="#function_rest" class="func_name">rest</a> <a href="#function_ternary" class="func_name">ternary</a> <a href="#function_unary" class="func_name">unary</a></div></div><hr><div><h2 id="function_popdd" class="func_name">popdd <a href="#function_popdd" class="self_link"></a></h2><pre>
[pop] the third item on the stack.
a b c popdd
-----------------
b c
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_pop">pop</a>] <a href="#function_dipd">dipd</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_pop" class="func_name">pop</a> <a href="#function_popd" class="func_name">popd</a> <a href="#function_popop" class="func_name">popop</a> <a href="#function_popopd" class="func_name">popopd</a> <a href="#function_popopdd" class="func_name">popopdd</a> <a href="#function_popopop" class="func_name">popopop</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_cleave" class="func_name">cleave</a> <a href="#function_clop" class="func_name">clop</a></div></div><hr><div><h2 id="function_popop" class="func_name">popop <a href="#function_popop" class="self_link"></a></h2><pre>
[pop] two items from the stack.
a b popop
---------------
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_pop">pop</a> <a href="#function_pop">pop</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_pop" class="func_name">pop</a> <a href="#function_popd" class="func_name">popd</a> <a href="#function_popdd" class="func_name">popdd</a> <a href="#function_popopd" class="func_name">popopd</a> <a href="#function_popopdd" class="func_name">popopdd</a> <a href="#function_popopop" class="func_name">popopop</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_popopd" class="func_name">popopd</a> <a href="#function_popopdd" class="func_name">popopdd</a> <a href="#function_popopop" class="func_name">popopop</a></div></div><hr><div><h2 id="function_popopd" class="func_name">popopd <a href="#function_popopd" class="self_link"></a></h2><pre>
[pop] the second and third items from the stack.
a b c popopd
------------------
c
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_popop">popop</a>] <a href="#function_dip">dip</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_pop" class="func_name">pop</a> <a href="#function_popd" class="func_name">popd</a> <a href="#function_popdd" class="func_name">popdd</a> <a href="#function_popop" class="func_name">popop</a> <a href="#function_popopdd" class="func_name">popopdd</a> <a href="#function_popopop" class="func_name">popopop</a></div></div><hr><div><h2 id="function_popopdd" class="func_name">popopdd <a href="#function_popopdd" class="self_link"></a></h2><pre>
a b c d popopdd
---------------------
c d
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_popop">popop</a>] <a href="#function_dipd">dipd</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_pop" class="func_name">pop</a> <a href="#function_popd" class="func_name">popd</a> <a href="#function_popdd" class="func_name">popdd</a> <a href="#function_popop" class="func_name">popop</a> <a href="#function_popopd" class="func_name">popopd</a> <a href="#function_popopop" class="func_name">popopop</a></div></div><hr><div><h2 id="function_popopop" class="func_name">popopop <a href="#function_popopop" class="self_link"></a></h2><pre>
[pop] three items from the stack.
a b c popopop
-------------------
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_pop">pop</a> <a href="#function_popop">popop</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_pop" class="func_name">pop</a> <a href="#function_popd" class="func_name">popd</a> <a href="#function_popdd" class="func_name">popdd</a> <a href="#function_popop" class="func_name">popop</a> <a href="#function_popopd" class="func_name">popopd</a> <a href="#function_popopdd" class="func_name">popopdd</a></div></div><hr><div><h2 id="function_pow" class="func_name">pow <a href="#function_pow" class="self_link"></a></h2><pre>
Take two numbers `a` and `n` from the stack and raise `a` to the `n`th
power. (`n` is on the top of the stack.)
a n pow
-------------
(aⁿ)
### Example
2 [2 3 4 5 6 7 8 9] [pow] map
-----------------------------------
2 [4 8 16 32 64 128 256 512]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">1</a> <a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll&gt;</a> <a href="#function_swap">swap</a> [<a href="#function_684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#function_cons">cons</a> <a href="#function_times">times</a></blockquote></div></div><hr><div><h2 id="function_pred" class="func_name">pred <a href="#function_pred" class="self_link"></a></h2><pre>
Predecessor. Decrement TOS.
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_succ" class="func_name">succ</a></div></div><hr><div><h2 id="function_primrec" class="func_name">primrec <a href="#function_primrec" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
From the ["Overview of the language JOY"](https://www.kevinalbrecht.com/code/joy-mirror/j00ovr.html)
&gt; The primrec combinator expects two quoted programs in addition to a
&gt; data parameter. For an integer data parameter it works like this: If
&gt; the data parameter is zero, then the first quotation has to produce the
&gt; value to be returned. If the data parameter is positive then the second
&gt; has to combine the data parameter with the result of applying the
&gt; function to its predecessor.
&gt; 5 \[1\] \[\*\] primrec
&gt; Then primrec tests whether the top element on the stack (initially the
&gt; 5) is equal to zero. If it is, it pops it off and executes one of the
&gt; quotations, the \[1\] which leaves 1 on the stack as the result.
&gt; Otherwise it pushes a decremented copy of the top element and recurses.
&gt; On the way back from the recursion it uses the other quotation, \[\*\],
&gt; to multiply what is now a factorial on top of the stack by the second
&gt; element on the stack.
0 [Base] [Recur] primrec
------------------------------
Base
n [Base] [Recur] primrec
------------------------------------------ n &gt; 0
n (n-1) [Base] [Recur] primrec Recur
</pre><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="#function_genrec" class="func_name">genrec</a> <a href="#function_tailrec" class="func_name">tailrec</a></div></div><hr><div><h2 id="function_product" class="func_name">product <a href="#function_product" class="self_link"></a></h2><pre>
Just as [sum] sums a list of numbers, this function multiplies them
together.
### Definition
&gt; 1 [swap] \[[mul]\] [step]
Or,
&gt; \[1\] \[[mul]\] [primrec]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">1</a> <a href="#function_swap">swap</a> [<a href="#function_684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1">*</a>] <a href="#function_step">step</a></blockquote></div></div><hr><div><h2 id="function_quoted" class="func_name">quoted <a href="#function_quoted" class="self_link"></a></h2><pre>
"Quote D" Wrap the second item on the stack in a list.
a b quoted
----------------
[a] b
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_unit">unit</a>] <a href="#function_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="#function_unit" class="func_name">unit</a></div></div><hr><div><h2 id="function_range" class="func_name">range <a href="#function_range" class="self_link"></a></h2><pre>
Expect a number `n` on the stack and replace it with a list:
`[(n-1)...0]`.
### Example
5 range
-----------------
[4 3 2 1 0]
-5 range
--------------
[]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">0</a> <a href="#function_b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866">&lt;=</a>] [<a href="#function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a> <a href="#function_dup">dup</a>] <a href="#function_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="#function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero</a></div></div><hr><div><h2 id="function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero <a href="#function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="self_link"></a></h2><pre>
Take a number `n` from the stack and replace it with a list
`[0...n]`.
### Example
5 range_to_zero
---------------------
[0 1 2 3 4 5]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_unit">unit</a> [<a href="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d">down_to_zero</a>] <a href="#function_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="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a> <a href="#function_range" class="func_name">range</a></div></div><hr><div><h2 id="function_reco" class="func_name">reco <a href="#function_reco" class="self_link"></a></h2><pre>
Replace the first item in a list with the item under it.
a [b ...] reco
--------------------
[a ...]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_rest">rest</a> <a href="#function_cons">cons</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_codireco" class="func_name">codireco</a> <a href="#function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_codireco" class="func_name">codireco</a></div></div><hr><div><h2 id="function_rem" class="func_name">rem <a href="#function_rem" class="self_link"></a></h2><pre>
See [mod](#mod).
</pre></div><hr><div><h2 id="function_remainder" class="func_name">remainder <a href="#function_remainder" class="self_link"></a></h2><pre>
See [mod](#mod).
</pre></div><hr><div><h2 id="function_remove" class="func_name">remove <a href="#function_remove" class="self_link"></a></h2><pre>
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.
[1 2 3 1] 1 remove
------------------------
[2 3 1]
### Definition
See the ["Remove Function" notebook](https://osdn.net/projects/joypy/scm/git/Thun/blobs/master/docs/notebooks/Remove-Function.ipynb).
</pre></div><hr><div><h2 id="function_rest" class="func_name">rest <a href="#function_rest" class="self_link"></a></h2><pre>
[a ...] rest
------------------
[...]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_uncons">uncons</a> <a href="#function_popd">popd</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_first" class="func_name">first</a> <a href="#function_uncons" class="func_name">uncons</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_drop" class="func_name">drop</a> <a href="#function_fourth" class="func_name">fourth</a> <a href="#function_reco" class="func_name">reco</a> <a href="#function_rrest" class="func_name">rrest</a> <a href="#function_second" class="func_name">second</a> <a href="#" class="func_name">small</a> <a href="#function_third" class="func_name">third</a> <a href="#function_uncons" class="func_name">uncons</a></div></div><hr><div><h2 id="function_reverse" class="func_name">reverse <a href="#function_reverse" class="self_link"></a></h2><pre>
Reverse the list on the top of the stack.
### Example
[1 2 3] reverse
---------------------
[3 2 1]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a> <a href="#function_shunt">shunt</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_appN" class="func_name">appN</a> <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="function_2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="func_name">roll&lt; <a href="#function_2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="self_link"></a></h2><pre>
See [rolldown](#rolldown).
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_swapd">swapd</a> <a href="#function_swap">swap</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_rolldown" class="func_name">rolldown</a></div></div><hr><div><h2 id="function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll&gt; <a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="self_link"></a></h2><pre>
See [rollup](#rollup).
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_swap">swap</a> <a href="#function_swapd">swapd</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_pow" class="func_name">pow</a> <a href="#function_rollup" class="func_name">rollup</a> <a href="#function_edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="func_name">step_zero</a></div></div><hr><div><h2 id="function_rolldown" class="func_name">rolldown <a href="#function_rolldown" class="self_link"></a></h2><pre>
a b c rolldown
--------------------
b c a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd">roll&lt;</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_rollup" class="func_name">rollup</a></div></div><hr><div><h2 id="function_rollup" class="func_name">rollup <a href="#function_rollup" class="self_link"></a></h2><pre>
a b c rollup
------------------
c a b
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll&gt;</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_rolldown" class="func_name">rolldown</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name">&lt;&lt;{}</a></div></div><hr><div><h2 id="function_round" class="func_name">round <a href="#function_round" class="self_link"></a></h2><pre>
Round a number to a given precision in decimal digits.
</pre><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="function_rrest" class="func_name">rrest <a href="#function_rrest" class="self_link"></a></h2><pre>
[a b ...] rrest
---------------------
[...]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_rest">rest</a> <a href="#function_rest">rest</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_rest" class="func_name">rest</a></div></div><hr><div><h2 id="function_rshift" class="func_name">rshift <a href="#function_rshift" class="self_link"></a></h2><pre>
[Logical Right-Shift](https://en.wikipedia.org/wiki/Logical_shift)
a n rshift
----------------
(a2ⁿ)
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">2</a> <a href="#function_8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1">/</a>] <a href="#function_times">times</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_lshift" class="func_name">lshift</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="func_name">&gt;&gt;</a></div></div><hr><div><h2 id="function_run" class="func_name">run <a href="#function_run" class="self_link"></a></h2><pre>
Run a quoted program in a list.
### Example
[1 2 +] run
-----------------
[3]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7">&lt;{}</a> <a href="#function_infra">infra</a></blockquote></div></div><hr><div><h2 id="function_second" class="func_name">second <a href="#function_second" class="self_link"></a></h2><pre>
[a b ...] second
----------------------
b
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_rest">rest</a> <a href="#function_first">first</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_first" class="func_name">first</a> <a href="#function_third" class="func_name">third</a> <a href="#function_fourth" class="func_name">fourth</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_third" class="func_name">third</a></div></div><hr><div><h2 id="function_select" class="func_name">select <a href="#function_select" class="self_link"></a></h2><pre>
Use a Boolean value to select one of two items from a sequence. :
[a b] false select
------------------------
a
[a b] true select
-----------------------
b
</pre><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="#function_choice" class="func_name">choice</a></div></div><hr><div><h2 id="function_sharing" class="func_name">sharing <a href="#function_sharing" class="self_link"></a></h2><pre>
Print redistribution information.
</pre><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="#function_warranty" class="func_name">warranty</a></div></div><hr><div><h2 id="function_shift" class="func_name">shift <a href="#function_shift" class="self_link"></a></h2><pre>
Move the top item from one list to another.
### Example
[x y z] [a b c] shift
---------------------------
[a x y z] [b c]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_uncons">uncons</a> [<a href="#function_swons">swons</a>] <a href="#function_dip">dip</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_shunt" class="func_name">shunt</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_take" class="func_name">take</a></div></div><hr><div><h2 id="function_shunt" class="func_name">shunt <a href="#function_shunt" class="self_link"></a></h2><pre>
Like [concat] but [reverse] the top list into the second.
### Example
[a b c] [d e f] shunt
---------------------------
[f e d a b c]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_swons">swons</a>] <a href="#function_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="#function_concat" class="func_name">concat</a> <a href="#function_reverse" class="func_name">reverse</a> <a href="#function_shift" class="func_name">shift</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_reverse" class="func_name">reverse</a></div></div><hr><div><h2 id="function_size" class="func_name">size <a href="#function_size" class="self_link"></a></h2><pre>
Replace a list with its size.
### Example
[23 [cats] 4] size
------------------------
3
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_pop">pop</a> <a href="#function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a>] <a href="#function_edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482">step_zero</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_average" class="func_name">average</a></div></div><hr><div><h2 id="function_sort" class="func_name">sort <a href="#function_sort" class="self_link"></a></h2><pre>
Given a list return it sorted.
### Example
[4 2 5 7 1] sort
----------------------
[1 2 4 5 7]
</pre></div><hr><div><h2 id="function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="self_link"></a></h2><pre>
Example code.
</pre><div class="definition"><h3>Definition</h3><blockquote>[[[<a href="#function_abs">abs</a>] <a href="#function_ii">ii</a> <a href="#function_b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866">&lt;=</a>] [[<a href="#function_24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64">&lt;&gt;</a>] [<a href="#function_pop">pop</a> <a href="#function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a>] <a href="#function_or">or</a>] <a href="#function_and">and</a>] [[<a href="#function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a>] [[<a href="#function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a>]] [[<a href="#function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a>]] <a href="#function_ifte">ifte</a> <a href="#function_dip">dip</a>] [[<a href="#function_pop">pop</a> <a href="#function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a>] [<a href="#function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c">--</a>] [<a href="#function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e">++</a>] <a href="#function_ifte">ifte</a>] <a href="#function_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="function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at <a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="self_link"></a></h2><pre>
Split a list (second on the stack) at the position given by the number on
the top of the stack.
### Example
[1 2 3 4 5 6 7] 4 split_at
--------------------------------
[5 6 7] [4 3 2 1]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_drop">drop</a>] [<a href="#function_take">take</a>] <a href="#function_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="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="self_link"></a></h2><pre>
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.
[1 2 3 4 5 6 7] 4 split_list
----------------------------------
[1 2 3 4] [5 6 7]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_take">take</a> <a href="#function_reverse">reverse</a>] [<a href="#function_drop">drop</a>] <a href="#function_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="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a></div></div><hr><div><h2 id="function_sqr" class="func_name">sqr <a href="#function_sqr" class="self_link"></a></h2><pre>
Square the number on the top of the stack.
n sqr
------------
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_dup">dup</a> <a href="#function_mul">mul</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_hypot" class="func_name">hypot</a></div></div><hr><div><h2 id="function_sqrt" class="func_name">sqrt <a href="#function_sqrt" class="self_link"></a></h2><pre>
Function Combinator
Return the square root of the number a. Negative numbers return complex
roots.
</pre><div class="discussion"><h3>Discussion</h3>Another "numeric tower" hatch...</div><div class="backlinks"><h3>Used By</h3><a href="#function_hypot" class="func_name">hypot</a></div></div><hr><div><h2 id="function_stack" class="func_name">stack <a href="#function_stack" class="self_link"></a></h2><pre>
Put the stack onto the stack.
... c b a stack
---------------------------
... c b a [a b c ...]
</pre><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="#function_enstacken" class="func_name">enstacken</a> <a href="#function_disenstacken" class="func_name">disenstacken</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_enstacken" class="func_name">enstacken</a> <a href="#function_grba" class="func_name">grba</a> <a href="#function_nullary" class="func_name">nullary</a> <a href="#function_stackd" class="func_name">stackd</a> <a href="#function_stuncons" class="func_name">stuncons</a></div></div><hr><div><h2 id="function_stackd" class="func_name">stackd <a href="#function_stackd" class="self_link"></a></h2><pre>
Grab the stack under the top item and put it onto the stack.
### Example
... 1 2 3 stackd
------------------------
... 1 2 [2 1 ...] 3
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_stack">stack</a>] <a href="#function_dip">dip</a></blockquote></div></div><hr><div><h2 id="function_step" class="func_name">step <a href="#function_step" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run a quoted program on each item in a sequence.
... [] [Q] step
---------------------
...
... [a] [Q] step
----------------------
... a Q
... [a b c] [Q] . step
----------------------------------------
... a . Q [b c] [Q] step
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">_step0</a>] <a href="#function_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="#function_edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="func_name">step_zero</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_flatten" class="func_name">flatten</a> <a href="#function_product" class="func_name">product</a> <a href="#function_shunt" class="func_name">shunt</a> <a href="#function_edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="func_name">step_zero</a></div></div><hr><div><h2 id="function_edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="func_name">step_zero <a href="#function_edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Like [step] but with 0 as the initial value.
[...] [F] step_zero
-------------------------
0 [...] [F] step
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#">0</a> <a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll&gt;</a> <a href="#function_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="#function_step" class="func_name">step</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_size" class="func_name">size</a> <a href="#function_sum" class="func_name">sum</a></div></div><hr><div><h2 id="function_stuncons" class="func_name">stuncons <a href="#function_stuncons" class="self_link"></a></h2><pre>
Take the [stack] and [uncons] the top item.
### Example
1 2 3 stuncons
--------------------
1 2 3 3 [2 1]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_stack">stack</a> <a href="#function_uncons">uncons</a></blockquote></div></div><hr><div><h2 id="function_stununcons" class="func_name">stununcons <a href="#function_stununcons" class="self_link"></a></h2><pre>
Take the [stack] and [uncons] the top two items.
### Example
1 2 3 stununcons
----------------------
1 2 3 3 2 [1]
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_stuncons" class="func_name">stuncons</a></div></div><hr><div><h2 id="function_sub" class="func_name">sub <a href="#function_sub" class="self_link"></a></h2><pre>
Subtract the number on the top of the stack from the number below it.
a b sub
-------------
(a-b)
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_add" class="func_name">add</a></div></div><hr><div><h2 id="function_succ" class="func_name">succ <a href="#function_succ" class="self_link"></a></h2><pre>
Successor. Increment TOS.
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_pred" class="func_name">pred</a></div></div><hr><div><h2 id="function_sum" class="func_name">sum <a href="#function_sum" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Given a quoted sequence of numbers return the sum.
### Example
[1 2 3 4 5] sum
---------------------
15
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b">+</a>] <a href="#function_edf68e5f7ac38ac9f3205404f47d1262bceaef3b245b5d076c0f0b002c801482">step_zero</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_size" class="func_name">size</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_average" class="func_name">average</a></div></div><hr><div><h2 id="function_swaack" class="func_name">swaack <a href="#function_swaack" class="self_link"></a></h2><pre>
Swap stack. Take a list from the top of the stack, replace the stack
with the list, and put the old stack onto it.
### Example
1 2 3 [4 5 6] swaack
--------------------------
6 5 4 [3 2 1]
</pre><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="#function_infra" class="func_name">infra</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_clear" class="func_name">clear</a> <a href="#function_disenstacken" class="func_name">disenstacken</a> <a href="#function_infra" class="func_name">infra</a> <a href="#" class="func_name">unstack</a></div></div><hr><div><h2 id="function_swap" class="func_name">swap <a href="#function_swap" class="self_link"></a></h2><pre>
Swap the top two items on the stack.
a b swap
--------------
b a
</pre><div class="crosslinks"><h3>See Also</h3><a href="#function_swapd" class="func_name">swapd</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="func_name">&lt;{}</a> <a href="#function_anamorphism" class="func_name">anamorphism</a> <a href="#function_d5856351bbc14599e687dac105150e8a919b21477f3c00386405228caac1e43a" class="func_name">app2</a> <a href="#function_cmp" class="func_name">cmp</a> <a href="#function_ifte" class="func_name">ifte</a> <a href="#function_neg" class="func_name">neg</a> <a href="#" class="func_name">null</a> <a href="#function_of" class="func_name">of</a> <a href="#function_over" class="func_name">over</a> <a href="#function_pow" class="func_name">pow</a> <a href="#function_product" class="func_name">product</a> <a href="#function_2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="func_name">roll&lt;</a> <a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll&gt;</a> <a href="#function_swapd" class="func_name">swapd</a> <a href="#function_swoncat" class="func_name">swoncat</a> <a href="#function_swons" class="func_name">swons</a> <a href="#function_unswons" class="func_name">unswons</a> <a href="#function_while" class="func_name">while</a></div></div><hr><div><h2 id="function_swapd" class="func_name">swapd <a href="#function_swapd" class="self_link"></a></h2><pre>
Swap the second and third items on the stack.
a b c swapd
-----------------
b a c
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_swap">swap</a>] <a href="#function_dip">dip</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_over" class="func_name">over</a> <a href="#function_tuck" class="func_name">tuck</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="func_name">roll&lt;</a> <a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll&gt;</a> <a href="#function_tuck" class="func_name">tuck</a></div></div><hr><div><h2 id="function_swoncat" class="func_name">swoncat <a href="#function_swoncat" class="self_link"></a></h2><pre>
[concat] two lists, but [swap] the lists first.
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_swap">swap</a> <a href="#function_concat">concat</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_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="function_swons" class="func_name">swons <a href="#function_swons" class="self_link"></a></h2><pre>
Like [cons] but [swap] the item and list.
[...] a swons
-------------------
[a ...]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_swap">swap</a> <a href="#function_cons">cons</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_anamorphism" class="func_name">anamorphism</a> <a href="#function_cmp" class="func_name">cmp</a> <a href="#function_genrec" class="func_name">genrec</a> <a href="#function_infra" class="func_name">infra</a> <a href="#function_shift" class="func_name">shift</a> <a href="#function_shunt" class="func_name">shunt</a></div></div><hr><div><h2 id="function_tailrec" class="func_name">tailrec <a href="#function_tailrec" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
A specialization of the [genrec] combinator.
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_i">i</a>] <a href="#function_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="#function_genrec" class="func_name">genrec</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_map" class="func_name">map</a></div></div><hr><div><h2 id="function_take" class="func_name">take <a href="#function_take" class="self_link"></a></h2><pre>
Expects an integer `n` and a list on the stack and replace them with a list
with just the top `n` items in reverse order.
[a b c d] 2 take
----------------------
[b a]
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108">&lt;&lt;{}</a> [<a href="#function_shift">shift</a>] <a href="#function_times">times</a> <a href="#function_pop">pop</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at</a> <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list</a></div></div><hr><div><h2 id="function_ternary" class="func_name">ternary <a href="#function_ternary" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Run a quoted program using exactly three stack values and leave the first
item of the result on the stack.
... z y x [P] ternary
-------------------------
... a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_binary">binary</a> <a href="#function_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="#function_binary" class="func_name">binary</a> <a href="#function_nullary" class="func_name">nullary</a> <a href="#function_unary" class="func_name">unary</a></div></div><hr><div><h2 id="function_third" class="func_name">third <a href="#function_third" class="self_link"></a></h2><pre>
[a b c ...] third
-----------------------
c
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_rest">rest</a> <a href="#function_second">second</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_first" class="func_name">first</a> <a href="#function_second" class="func_name">second</a> <a href="#function_fourth" class="func_name">fourth</a> <a href="#function_rest" class="func_name">rest</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_fourth" class="func_name">fourth</a></div></div><hr><div><h2 id="function_times" class="func_name">times <a href="#function_times" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Expect a quoted program and an integer `n` on the stack and do the
program `n` times.
... n [Q] . times
----------------------- w/ n &lt;= 0
... .
... 1 [Q] . times
-----------------------
... . Q
... n [Q] . times
------------------------------------- w/ n &gt; 1
... . Q (n-1) [Q] times
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#">_times0</a>] <a href="#function_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 &gt;] swap while pop
1 3 [++] [-- dip] • cons [swap] infra [0 &gt;] swap while pop
1 3 [[++] -- dip] • [swap] infra [0 &gt;] swap while pop
1 3 [[++] -- dip] [swap] • infra [0 &gt;] swap while pop
dip -- [++] • swap [3 1] swaack [0 &gt;] swap while pop
dip [++] -- • [3 1] swaack [0 &gt;] swap while pop
dip [++] -- [3 1] • swaack [0 &gt;] swap while pop
1 3 [-- [++] dip] • [0 &gt;] swap while pop
1 3 [-- [++] dip] [0 &gt;] • swap while pop
1 3 [0 &gt;] [-- [++] dip] • while pop
This is a common pattern in Joy. You accept some parameters from the
stack which typically include qouted programs and use them to build
another program which does the actual work. This is kind of like macros
in Lisp, or preprocessor directives in C.</div><div class="backlinks"><h3>Used By</h3><a href="#function_drop" class="func_name">drop</a> <a href="#function_grabN" class="func_name">grabN</a> <a href="#function_lshift" class="func_name">lshift</a> <a href="#function_pow" class="func_name">pow</a> <a href="#function_rshift" class="func_name">rshift</a> <a href="#function_take" class="func_name">take</a></div></div><hr><div><h2 id="function_truthy" class="func_name">truthy <a href="#function_truthy" class="self_link"></a></h2><pre>
See [bool](#bool).
</pre></div><hr><div><h2 id="function_tuck" class="func_name">tuck <a href="#function_tuck" class="self_link"></a></h2><pre>
[dup] the item on the top of the stack under the second item on the
stack.
a b tuck
--------------
b a b
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_dup">dup</a> <a href="#function_swapd">swapd</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_over" class="func_name">over</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_gcd" class="func_name">gcd</a></div></div><hr><div><h2 id="function_unary" class="func_name">unary <a href="#function_unary" class="self_link"></a></h2><pre>
(Combinator)
Run a quoted program using exactly one stack value and leave the first
item of the result on the stack.
... x [P] unary
---------------------
... a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_nullary">nullary</a> <a href="#function_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="#function_binary" class="func_name">binary</a> <a href="#function_nullary" class="func_name">nullary</a> <a href="#function_ternary" class="func_name">ternary</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_binary" class="func_name">binary</a></div></div><hr><div><h2 id="function_uncons" class="func_name">uncons <a href="#function_uncons" class="self_link"></a></h2><pre>
Removes an item from a list and leaves it on the stack under the rest of
the list. You cannot `uncons` an item from an empty list.
[a ...] uncons
--------------------
a [...]
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_first">first</a>] <a href="#function_dupdip">dupdip</a> <a href="#function_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="#function_cons" class="func_name">cons</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_first" class="func_name">first</a> <a href="#function_rest" class="func_name">rest</a> <a href="#function_shift" class="func_name">shift</a> <a href="#function_stuncons" class="func_name">stuncons</a> <a href="#function_unswons" class="func_name">unswons</a></div></div><hr><div><h2 id="function_unique" class="func_name">unique <a href="#function_unique" class="self_link"></a></h2><pre>
Given a list remove duplicate items.
</pre></div><hr><div><h2 id="function_unit" class="func_name">unit <a href="#function_unit" class="self_link"></a></h2><pre>
a unit
------------
[a]
</pre><div class="definition"><h3>Definition</h3><blockquote>[] <a href="#function_cons">cons</a></blockquote></div><div class="backlinks"><h3>Used By</h3><a href="#function_quoted" class="func_name">quoted</a> <a href="#function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero</a></div></div><hr><div><h2 id="function_unquoted" class="func_name">unquoted <a href="#function_unquoted" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Unquote (using [i]) the list that is second on the stack.
### Example
1 2 [3 4] 5 unquoted
--------------------------
1 2 3 4 5
</pre><div class="definition"><h3>Definition</h3><blockquote>[<a href="#function_i">i</a>] <a href="#function_dip">dip</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_unit" class="func_name">unit</a></div></div><hr><div><h2 id="function_unswons" class="func_name">unswons <a href="#function_unswons" class="self_link"></a></h2><pre>
[a ...] unswons
---------------------
[...] a
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_uncons">uncons</a> <a href="#function_swap">swap</a></blockquote></div></div><hr><div><h2 id="function_void" class="func_name">void <a href="#function_void" class="self_link"></a></h2><pre>
True if the form on TOS is void otherwise False.
</pre><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="function_warranty" class="func_name">warranty <a href="#function_warranty" class="self_link"></a></h2><pre>
Print warranty information.
</pre></div><hr><div><h2 id="function_while" class="func_name">while <a href="#function_while" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
A specialization of [loop] that accepts a quoted predicate program `P`
and runs it [nullary].
[P] [F] while
------------------- P -&gt; false
[P] [F] while
--------------------- P -&gt; true
F [P] [F] while
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_swap">swap</a> <a href="#function_nulco">nulco</a> <a href="#function_dupdipd">dupdipd</a> <a href="#function_concat">concat</a> <a href="#function_loop">loop</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_loop" class="func_name">loop</a></div><div class="backlinks"><h3>Used By</h3><a href="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero</a></div></div><hr><div><h2 id="function_words" class="func_name">words <a href="#function_words" class="self_link"></a></h2><pre>
Print all the words in alphabetical order.
</pre><div class="discussion"><h3>Discussion</h3>Mathematically this is a form of [id].</div><div class="crosslinks"><h3>See Also</h3><a href="#function_help" class="func_name">help</a></div></div><hr><div><h2 id="function_x" class="func_name">x <a href="#function_x" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Take a quoted function `F` and run it with itself as the first item on
the stack.
[F] x
-----------
[F] F
</pre><div class="definition"><h3>Definition</h3><blockquote><a href="#function_dup">dup</a> <a href="#function_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="#function_step" class="func_name">step</a> <a href="#function_times" class="func_name">times</a></div></div><hr><div><h2 id="function_xor" class="func_name">xor <a href="#function_xor" class="self_link"></a></h2><pre>
Logical bit-wise eXclusive OR.
</pre><div class="definition"><h3>Definition</h3><blockquote>[] [<a href="#function_not">not</a>] <a href="#function_branch">branch</a></blockquote></div><div class="crosslinks"><h3>See Also</h3><a href="#function_and" class="func_name">and</a> <a href="#function_or" class="func_name">or</a></div></div><hr><div><h2 id="function_zip" class="func_name">zip <a href="#function_zip" class="self_link"></a></h2><pre>
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.
### Example
[1 2 3] [4 5 6] zip
-------------------------
[[4 1] [5 2] [6 3]]
</pre></div><hr><div><h2 id="function_565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866" class="func_name">|| <a href="#function_565d240f5343e625ae579a4d45a770f1f02c6368b5ed4d06da4fbe6f47c28866" class="self_link"></a></h2><p><span class="kind">combinator</span></p><pre>
Short-circuiting Boolean OR
</pre><div class="discussion"><h3>Discussion</h3>Accept two quoted programs, run the first and expect a Boolean value, if
its `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 -&gt; false
B
[A] [B] ||
---------------- A -&gt; true
true</div><div class="crosslinks"><h3>See Also</h3><a href="#function_73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" class="func_name">&amp;&amp;</a></div></div></body></html>