3646 lines
93 KiB
HTML
3646 lines
93 KiB
HTML
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Thun Function Reference</title><link rel="stylesheet" href="/css/fonts.css"><link rel="stylesheet" href="/css/func_ref.css"></head><body><h1>Thun Function Reference</h1><a href="/">Home</a><p>Version -10.0.0</p><p>Each function, combinator, or definition should be documented here.</p><ul><li><a href="#function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf">!-</a></li> <li><a href="#function_c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2">!=</a></li> <li><a href="#function_bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec">%</a></li> <li><a href="#function_951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338">&</a></li> <li><a href="#function_73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef">&&</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"><</a></li> <li><a href="#function_4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e"><<</a></li> <li><a href="#function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108"><<{}</a></li> <li><a href="#function_b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866"><=</a></li> <li><a href="#function_24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64"><></a></li> <li><a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7"><{}</a></li> <li><a href="#function_380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3">=</a></li> <li><a href="#function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221">></a></li> <li><a href="#function_92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f">>=</a></li> <li><a href="#function_0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44">>></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<</a></li> <li><a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a">roll></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> <li><a href="#function_4f8865abeddbfab37520d0c56eed1bf17f37e3778e1a55e6dc54895d2ae17849">•</a></li> </ul><div><h2 id="function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf" class="func_name">!- <a href="#function_e96b8d9a989c510f8f60d2751588fef720f2f984a9599151beab05f52a984ddf" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Not negative.
|
||
|
||
|
||
n !-
|
||
----------- n < 0
|
||
false
|
||
|
||
|
||
n !-
|
||
---------- n >= 0
|
||
true
|
||
|
||
|
||
### Definition
|
||
|
||
0 \>=
|
||
|
||
### Discussion
|
||
|
||
Return a Boolean value indicating if a number is greater than or equal to
|
||
zero.
|
||
|
||
</pre></div><div><h2 id="function_c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2" class="func_name">!= <a href="#function_c10987bd7cf853f6ea92ddac1b6c95fa830e3aee160cc5d4ba2fea3743be1aa2" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [ne](#ne).
|
||
|
||
</pre></div><div><h2 id="function_bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec" class="func_name">% <a href="#function_bbf3f11cb5b43e700273a78d12de55e4a7eab741ed2abf13787a4d2dc832b8ec" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [mod](#mod).
|
||
|
||
</pre></div><div><h2 id="function_951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338" class="func_name">& <a href="#function_951dcee3a7a4f3aac67ec76a2ce4469cc76df650f134bf2572bf60a65c982338" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [and](#and).
|
||
|
||
</pre></div><div><h2 id="function_73e7b6f86214bc78ee505fb5f7d4fb97cfa99924a67ca3105113c9a3d52f8fef" class="func_name">&& <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] &&
|
||
---------------- true
|
||
B
|
||
|
||
|
||
[A] [B] &&
|
||
---------------- 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.
|
||
|
||
### Discussion
|
||
|
||
This is seldom useful, I suspect, but this way you have it.
|
||
|
||
### Crosslinks
|
||
|
||
[||](#section-25)
|
||
|
||
</pre></div><div><h2 id="function_684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1" class="func_name">* <a href="#function_684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [mul](#mul).
|
||
|
||
</pre></div><div><h2 id="function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b" class="func_name">+ <a href="#function_a318c24216defe206feeb73ef5be00033fa9c4a74d0b967f6532a26ca5906d3b" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [add](#add).
|
||
|
||
</pre></div><div><h2 id="function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e" class="func_name">++ <a href="#function_cfc0c0607a3380f7975346b30c14af8284f5493d9781b0ed847f499f01b4768e" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [succ](#succ).
|
||
|
||
</pre></div><div><h2 id="function_3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112" class="func_name">- <a href="#function_3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [sub](#sub).
|
||
|
||
</pre></div><div><h2 id="function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c" class="func_name">-- <a href="#function_d8156bae0c4243d3742fc4e9774d8aceabe0410249d720c855f98afc88ff846c" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [pred](#pred).
|
||
|
||
</pre></div><div><h2 id="function_8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1" class="func_name">/ <a href="#function_8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [floordiv](#floordiv).
|
||
|
||
</pre></div><div><h2 id="function_a2c2339691fc48fbd14fb307292dff3e21222712d9240810742d7df0c6d74dfb" class="func_name">// <a href="#function_a2c2339691fc48fbd14fb307292dff3e21222712d9240810742d7df0c6d74dfb" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [floordiv](#floordiv).
|
||
|
||
</pre></div><div><h2 id="function_25fec5b6fc916113006299298a2df014df5c407ebb11013f36163d3ec1cc1c53" class="func_name">/floor <a href="#function_25fec5b6fc916113006299298a2df014df5c407ebb11013f36163d3ec1cc1c53" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [floordiv](#floordiv).
|
||
|
||
</pre></div><div><h2 id="function_dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72" class="func_name">< <a href="#function_dabd3aff769f07eb2965401eb029974ebba3407afd02b26ddb564ea5f8efae72" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [lt](#lt).
|
||
|
||
</pre></div><div><h2 id="function_4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="func_name"><< <a href="#function_4be261c018f23deac37f17f24abb5f42c4f32044fa3116d7b618446fb03ca09e" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [lshift](#lshift).
|
||
|
||
</pre></div><div><h2 id="function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="func_name"><<{} <a href="#function_c6484f3156f82b92eadb0aeb7423d93ebd37f15dbbe3538f82d8da2acabaa108" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
|
||
... b a <{}
|
||
-----------------
|
||
... [] b a
|
||
|
||
|
||
### Definition
|
||
|
||
[] rollup
|
||
|
||
|
||
### Discussion
|
||
|
||
Tuck an empty list just under the first two items on the stack.
|
||
|
||
### Crosslinks
|
||
|
||
[<{}](#section-16)
|
||
|
||
</pre></div><div><h2 id="function_b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866" class="func_name"><= <a href="#function_b60080dc8b8982d2a2bff6f8f3715c1939614dc553cd223ef21832b88c815866" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [le](#le).
|
||
|
||
</pre></div><div><h2 id="function_24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64" class="func_name"><> <a href="#function_24295a9c545a402da4f2cc833dae7b4f3b80182f7f803516d580ca07c0642b64" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [ne](#ne).
|
||
|
||
</pre></div><div><h2 id="function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="func_name"><{} <a href="#function_7562cc288bc56648a8695b314d63d7e8a92eba12768b38c102fd7067877423e7" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
|
||
... a <{}
|
||
----------------
|
||
... [] a
|
||
|
||
|
||
### Definition
|
||
|
||
[] swap
|
||
|
||
### Discussion
|
||
|
||
Tuck an empty list just under the first item on the stack.
|
||
|
||
### Crosslinks
|
||
|
||
[<<{}](#section-18)
|
||
|
||
</pre></div><div><h2 id="function_380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3" class="func_name">= <a href="#function_380918b946a526640a40df5dced6516794f3d97bbd9e6bb553d037c4439f31c3" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [eq](#eq).
|
||
|
||
</pre></div><div><h2 id="function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221" class="func_name">> <a href="#function_62b67e1f685b7fef51102005dddd27774be3fee38c42965c53aab035d0b6b221" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [gt](#gt).
|
||
|
||
</pre></div><div><h2 id="function_92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f" class="func_name">>= <a href="#function_92a00d7d91da9f0f06c3f218c49c9b98323469962b291365b85d3c16b6b7f95f" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [ge](#ge).
|
||
|
||
</pre></div><div><h2 id="function_0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="func_name">>> <a href="#function_0f02c6bad08d9ff1858d26cf1af766e336d71e34c2e74e8c7d417b3550cbfc44" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [rshift](#rshift).
|
||
|
||
</pre></div><div><h2 id="function_8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="func_name">? <a href="#function_8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Is the item on the top of the stack "truthy"?
|
||
|
||
### Definition
|
||
|
||
> [dup](#dup) [bool](#bool)
|
||
|
||
### Discussion
|
||
|
||
You often want to test the truth value of an item on the stack without
|
||
consuming the item.
|
||
|
||
### Crosslinks
|
||
|
||
[bool](#bool)
|
||
|
||
</pre></div><div><h2 id="function_74cd9ef9c7e15f57bdad73c511462ca65cb674c46c49639c60f1b44650fa1dcb" class="func_name">^ <a href="#function_74cd9ef9c7e15f57bdad73c511462ca65cb674c46c49639c60f1b44650fa1dcb" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [xor](#xor).
|
||
|
||
</pre></div><div><h2 id="function_abs" class="func_name">abs <a href="#function_abs" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Return the absolute value of the argument.
|
||
|
||
### Definition
|
||
|
||
> [dup](#dup) 0 < [] \[[neg](#neg)\] [branch](#branch)
|
||
|
||
</pre></div><div><h2 id="function_add" class="func_name">add <a href="#function_add" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Add two numbers together: a + b.
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[pop](#pop) \[\]\] [swap](#swap) \[[dip](#dip) [swons](#swons)\] [genrec](#genrec)
|
||
|
||
### Example
|
||
|
||
The `range` function generates a list of the integers from 0 to n - 1:
|
||
|
||
> \[0 <=\] \[\-\- dup\] anamorphism
|
||
|
||
### Discussion
|
||
|
||
See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
|
||
|
||
</pre></div><div><h2 id="function_and" class="func_name">and <a href="#function_and" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Logical bit-wise AND.
|
||
|
||
### Crosslinks
|
||
|
||
[or](#or)
|
||
[xor](#xor)
|
||
|
||
</pre></div><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.
|
||
|
||
### Definition
|
||
|
||
> [nullary](#nullary) [popd](#popd)
|
||
|
||
### Discussion
|
||
|
||
Just a specialization of `nullary` really. Its parallelizable cousins
|
||
are more useful.
|
||
|
||
### Crosslinks
|
||
|
||
[app2](#app2)
|
||
[app3](#app3)
|
||
[appN](#appN)
|
||
[unary](#unary)
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[grba] [swap] [grba] [swap]\] [dip] \[[infrst]\] [cons] [ii]
|
||
|
||
### Discussion
|
||
|
||
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.
|
||
|
||
### Crosslinks
|
||
|
||
[app1](#app1)
|
||
[app3](#app3)
|
||
[appN](#appN)
|
||
[unary](#unary)
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> 3 [appN]
|
||
|
||
### Discussion
|
||
|
||
See [app2].
|
||
|
||
### Crosslinks
|
||
|
||
[app1](#app1)
|
||
[app2](#app2)
|
||
[appN](#appN)
|
||
[unary](#unary)
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[grabN]\] [codi] [map] [disenstacken]
|
||
|
||
### Discussion
|
||
|
||
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].
|
||
|
||
### Crosslinks
|
||
|
||
[app1](#app1)
|
||
[app2](#app2)
|
||
[app3](#app3)
|
||
[unary](#unary)
|
||
|
||
</pre></div><div><h2 id="function_at" class="func_name">at <a href="#function_at" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [getitem](#getitem).
|
||
|
||
</pre></div><div><h2 id="function_average" class="func_name">average <a href="#function_average" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Compute the average of a list of numbers.
|
||
(Currently broken until I can figure out what to do about "numeric tower"
|
||
in Thun.)
|
||
|
||
### Definition
|
||
|
||
> \[[sum]\] \[[size]\] [cleave] [/]
|
||
|
||
### Discussion
|
||
|
||
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).
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[i]\] [dip] [i]
|
||
|
||
### Discussion
|
||
|
||
This combinator may seem trivial but it comes in handy.
|
||
|
||
### Crosslinks
|
||
|
||
[dupdip](#dupdip)
|
||
[ii](#ii)
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> [unary] [popd]
|
||
|
||
### Discussion
|
||
|
||
Runs any other quoted function and returns its first result while
|
||
consuming exactly two items from the stack.
|
||
|
||
### Crosslinks
|
||
|
||
[nullary](#nullary)
|
||
[ternary](#ternary)
|
||
[unary](#unary)
|
||
|
||
</pre></div><div><h2 id="function_bool" class="func_name">bool <a href="#function_bool" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Convert the item on the top of the stack to a Boolean value.
|
||
|
||
### Discussion
|
||
|
||
For integers 0 is `false` and any other number is `true`; for lists the
|
||
empty list is `false` and all other lists are `true`.
|
||
|
||
### Crosslinks
|
||
|
||
[not]
|
||
|
||
</pre></div><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
|
||
|
||
|
||
### Definition
|
||
|
||
> [rolldown] [choice] [i]
|
||
|
||
### Discussion
|
||
|
||
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].
|
||
|
||
### Crosslinks
|
||
|
||
[choice]
|
||
[ifte]
|
||
[select]
|
||
|
||
</pre></div><div><h2 id="function_ccccons" class="func_name">ccccons <a href="#function_ccccons" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
a b c d [...] ccccons
|
||
---------------------------
|
||
[a b c d ...]
|
||
|
||
Do [cons] four times.
|
||
|
||
### Definition
|
||
|
||
> [ccons] [ccons]
|
||
|
||
### Crosslinks
|
||
|
||
[ccons] [cons] [times]
|
||
|
||
</pre></div><div><h2 id="function_ccons" class="func_name">ccons <a href="#function_ccons" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
a b [...] ccons
|
||
---------------------
|
||
[a b ...]
|
||
|
||
Do [cons] two times.
|
||
|
||
### Definition
|
||
|
||
> [cons] [cons]
|
||
|
||
### Crosslinks
|
||
|
||
[cons]
|
||
[ccons]
|
||
|
||
</pre></div><div><h2 id="function_choice" class="func_name">choice <a href="#function_choice" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Use a Boolean value to select one of two items.
|
||
|
||
a b false choice
|
||
----------------------
|
||
a
|
||
|
||
a b true choice
|
||
---------------------
|
||
b
|
||
|
||
### Definition
|
||
|
||
> \[[pop]\] \[[popd]\] [branch]
|
||
|
||
### Discussion
|
||
|
||
It's a matter of taste whether you implement this in terms of [branch] or
|
||
the other way around.
|
||
|
||
### Crosslinks
|
||
|
||
[branch]
|
||
[select]
|
||
|
||
</pre></div><div><h2 id="function_clear" class="func_name">clear <a href="#function_clear" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Clear everything from the stack.
|
||
|
||
### Definition
|
||
|
||
> [stack] [bool] \[[pop] [stack] [bool]\] [loop]
|
||
|
||
### Crosslinks
|
||
|
||
[stack]
|
||
[swaack]
|
||
|
||
</pre></div><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
|
||
|
||
> [fork] [popdd]
|
||
|
||
### Example
|
||
|
||
1 2 3 [+] [-] cleave
|
||
--------------------------
|
||
1 2 5 -1
|
||
|
||
### Discussion
|
||
|
||
One of a handful of useful parallel combinators.
|
||
|
||
### Crosslinks
|
||
|
||
[clop]
|
||
[fork]
|
||
[map]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> [cleave] [popdd]
|
||
|
||
### Discussion
|
||
|
||
Like [cleave] but consumes an additional item from the stack.
|
||
|
||
1 2 3 4 [+] [-] clop
|
||
--------------------------
|
||
1 2 7 -1
|
||
|
||
### Crosslinks
|
||
|
||
[cleave]
|
||
[fork]
|
||
[map]
|
||
|
||
</pre></div><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 > b
|
||
G
|
||
|
||
a b [G] [E] [L] cmp
|
||
------------------------- a = b
|
||
E
|
||
|
||
a b [G] [E] [L] cmp
|
||
------------------------- a < b
|
||
L
|
||
### Discussion
|
||
|
||
This is useful sometimes, and you can [dup] or [dupd] with two quoted
|
||
programs to handle the cases when you just want to deal with [<=] or [>=]
|
||
and not all three possibilities, e.g.:
|
||
|
||
[G] [EL] dup cmp
|
||
|
||
[GE] [L] dupd cmp
|
||
|
||
Or even:
|
||
|
||
[GL] [E] over cmp
|
||
|
||
### Crosslinks
|
||
|
||
TODO: link to tree notebooks where this was used.
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> [cons] [dip]
|
||
|
||
### Discussion
|
||
|
||
This is one of those weirdly specific functions that turns out to be
|
||
useful in a few places.
|
||
|
||
### Crosslinks
|
||
|
||
[appN]
|
||
[codireco]
|
||
|
||
</pre></div><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.
|
||
|
||
### Definition
|
||
|
||
> [codi] [reco]
|
||
|
||
### Discussion
|
||
|
||
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.
|
||
|
||
### Crosslinks
|
||
|
||
[make_generator]
|
||
|
||
</pre></div><div><h2 id="function_concat" class="func_name">concat <a href="#function_concat" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Concatinate two lists.
|
||
|
||
[a b c] [d e f] concat
|
||
----------------------------
|
||
[a b c d e f]
|
||
|
||
### Crosslinks
|
||
|
||
[first]
|
||
[first_two]
|
||
[flatten]
|
||
[fourth]
|
||
[getitem]
|
||
[remove]
|
||
[rest]
|
||
[reverse]
|
||
[rrest]
|
||
[second]
|
||
[shift]
|
||
[shunt]
|
||
[size]
|
||
[sort]
|
||
[split_at]
|
||
[split_list]
|
||
[swaack]
|
||
[third]
|
||
[zip]
|
||
|
||
</pre></div><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
|
||
|
||
### Discussion
|
||
|
||
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
|
||
|
||
|
||
### Crosslinks
|
||
|
||
[ifte]
|
||
|
||
</pre></div><div><h2 id="function_cons" class="func_name">cons <a href="#function_cons" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Given an item and a list, append the item to the list to make a new list.
|
||
|
||
a [...] cons
|
||
------------------
|
||
[a ...]
|
||
|
||
### Discussion
|
||
|
||
Cons is a [venerable old function from Lisp](https://en.wikipedia.org/wiki/Cons#Lists).
|
||
Its inverse operation is [uncons].
|
||
|
||
### Crosslinks
|
||
|
||
[uncons]
|
||
|
||
</pre></div><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.)
|
||
|
||
### Definition
|
||
|
||
> [dip] [infrst]
|
||
|
||
</pre></div><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
|
||
|
||
### Discussion
|
||
|
||
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.)
|
||
|
||
### Crosslinks
|
||
|
||
[dipd]
|
||
[dipdd]
|
||
[dupdip]
|
||
[dupdipd]
|
||
[infra]
|
||
|
||
</pre></div><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
|
||
|
||
### Discussion
|
||
|
||
See [dip].
|
||
|
||
### Crosslinks
|
||
|
||
[dip]
|
||
[dipdd]
|
||
[dupdip]
|
||
[dupdipd]
|
||
[infra]
|
||
</pre></div><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
|
||
### Discussion
|
||
|
||
See [dip].
|
||
|
||
### Crosslinks
|
||
|
||
[dip]
|
||
[dipd]
|
||
[dupdip]
|
||
[dupdipd]
|
||
[infra]
|
||
|
||
</pre></div><div><h2 id="function_disenstacken" class="func_name">disenstacken <a href="#function_disenstacken" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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
|
||
|
||
### Definition
|
||
|
||
> \[[clear]\] [dip] [reverse] [unstack](#unstack)
|
||
|
||
### Discussion
|
||
|
||
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.
|
||
|
||
### Crosslinks
|
||
|
||
[enstacken]
|
||
[stack]
|
||
[unstack](#unstack)
|
||
|
||
</pre></div><div><h2 id="function_div" class="func_name">div <a href="#function_div" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [floordiv](#floordiv).
|
||
|
||
</pre></div><div><h2 id="function_divmod" class="func_name">divmod <a href="#function_divmod" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
x y divmod
|
||
------------------
|
||
q r
|
||
(x/y) (x%y)
|
||
|
||
Invariant: `qy + r = x`.
|
||
|
||
|
||
### Definition
|
||
|
||
> \[[floordiv]\] \[[mod]\] [clop]
|
||
|
||
</pre></div><div><h2 id="function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="func_name">down_to_zero <a href="#function_24eeb094bfbc05ab9fab7609e43f67a4b6f7f94db85bbab53d63ba083f006c9d" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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
|
||
|
||
### Definition
|
||
|
||
> \[0 \>\] \[[dup] [--]\] [while]
|
||
|
||
### Crosslinks
|
||
|
||
[range]
|
||
|
||
</pre></div><div><h2 id="function_drop" class="func_name">drop <a href="#function_drop" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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]
|
||
|
||
### Definition
|
||
|
||
> \[[rest]\] [times]
|
||
|
||
### Crosslinks
|
||
|
||
[take]
|
||
|
||
</pre></div><div><h2 id="function_dup" class="func_name">dup <a href="#function_dup" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
"Dup"licate the top item on the stack.
|
||
|
||
a dup
|
||
-----------
|
||
a a
|
||
|
||
### Crosslinks
|
||
|
||
[dupd]
|
||
[dupdd]
|
||
[dupdip]
|
||
[dupdipd]
|
||
|
||
</pre></div><div><h2 id="function_dupd" class="func_name">dupd <a href="#function_dupd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[dup] the second item down on the stack.
|
||
|
||
a b dupd
|
||
--------------
|
||
a a b
|
||
|
||
### Definition
|
||
|
||
> \[[dup]\] [dip]
|
||
|
||
### Crosslinks
|
||
|
||
[dup]
|
||
[dupdd]
|
||
[dupdip]
|
||
[dupdipd]
|
||
|
||
</pre></div><div><h2 id="function_dupdd" class="func_name">dupdd <a href="#function_dupdd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[dup] the third item down on the stack.
|
||
|
||
a b c dupdd
|
||
-----------------
|
||
a a b c
|
||
|
||
### Definition
|
||
|
||
> \[[dup]\] [dipd]
|
||
|
||
### Crosslinks
|
||
|
||
[dup]
|
||
[dupd]
|
||
[dupdip]
|
||
[dupdipd]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> [dupd] [dip]
|
||
|
||
### Derivation
|
||
|
||
a [F] dupdip
|
||
a [F] dupd dip
|
||
a [F] [dup] dip dip
|
||
a dup [F] dip
|
||
a a [F] dip
|
||
a F a
|
||
|
||
### Discussion
|
||
|
||
A very common and useful combinator.
|
||
|
||
### Crosslinks
|
||
|
||
[dupdipd]
|
||
|
||
</pre></div><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]
|
||
|
||
### Definition
|
||
|
||
> [dup] [dipd]
|
||
|
||
### Crosslinks
|
||
|
||
[dupdip]
|
||
|
||
</pre></div><div><h2 id="function_enstacken" class="func_name">enstacken <a href="#function_enstacken" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Put the stack onto the stack replacing the contents of the stack.
|
||
|
||
... a b c enstacken
|
||
-------------------------
|
||
[c b a ...]
|
||
|
||
|
||
### Definition
|
||
|
||
> [stack] \[[clear]\] [dip]
|
||
|
||
### Discussion
|
||
|
||
This is a destructive version of [stack]. See the note under
|
||
[disenstacken] about the apparent but illusory reversal of the stack.
|
||
|
||
### Crosslinks
|
||
|
||
[stack]
|
||
[unstack]
|
||
[disenstacken]
|
||
|
||
</pre></div><div><h2 id="function_eq" class="func_name">eq <a href="#function_eq" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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)
|
||
|
||
### Crosslinks
|
||
|
||
[cmp]
|
||
[ge]
|
||
[gt]
|
||
[le]
|
||
[lt]
|
||
[ne]
|
||
|
||
</pre></div><div><h2 id="function_first" class="func_name">first <a href="#function_first" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Replace a list with its first item.
|
||
|
||
[a ...]
|
||
--------------
|
||
a
|
||
|
||
### Definition
|
||
|
||
> [uncons] [pop]
|
||
|
||
### Crosslinks
|
||
|
||
[second]
|
||
[third]
|
||
[fourth]
|
||
[rest]
|
||
|
||
</pre></div><div><h2 id="function_07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="func_name">first_two <a href="#function_07b63cfff44ede6136263bf5857f5174d6e3657dfa7a1d9bb018089ee03d7236" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Replace a list with its first two items.
|
||
|
||
[a b ...] first_two
|
||
-------------------------
|
||
a b
|
||
|
||
### Definition
|
||
|
||
> [uncons] [first]
|
||
|
||
### Crosslinks
|
||
|
||
[first]
|
||
[second]
|
||
[third]
|
||
[fourth]
|
||
[rest]
|
||
|
||
</pre></div><div><h2 id="function_flatten" class="func_name">flatten <a href="#function_flatten" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Given a list of lists, concatinate them.
|
||
|
||
### Example
|
||
|
||
[[1 2] [3 [4] 5] [6 7]] flatten
|
||
-------------------------------------
|
||
[1 2 3 [4] 5 6 7]
|
||
|
||
### Definition
|
||
|
||
> [\<\{\}] \[[concat]\] [step]
|
||
|
||
### Discussion
|
||
|
||
Note that only one "level" of lists is flattened. In the example above
|
||
`[4]` is not unquoted.
|
||
|
||
### Crosslinks
|
||
|
||
[concat]
|
||
[first]
|
||
[first_two]
|
||
[fourth]
|
||
[getitem]
|
||
[remove]
|
||
[rest]
|
||
[reverse]
|
||
[rrest]
|
||
[second]
|
||
[shift]
|
||
[shunt]
|
||
[size]
|
||
[sort]
|
||
[split_at]
|
||
[split_list]
|
||
[swaack]
|
||
[third]
|
||
[zip]
|
||
|
||
</pre></div><div><h2 id="function_floor" class="func_name">floor <a href="#function_floor" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Return the largest integer \<= x.
|
||
|
||
### Discussion
|
||
|
||
This function doesn't make sense (yet) to have because there are (as yet)
|
||
only integers in the system.
|
||
|
||
</pre></div><div><h2 id="function_floordiv" class="func_name">floordiv <a href="#function_floordiv" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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)
|
||
|
||
### Discussion
|
||
|
||
All the division commands need to be revisited when the "numeric tower"
|
||
for Thun gets nailed down.
|
||
|
||
### Crosslinks
|
||
|
||
[divmod]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[i]\] [app2]
|
||
|
||
### Discussion
|
||
|
||
The basic parallelism combinator, the two programs are run independently.
|
||
|
||
### Crosslinks
|
||
|
||
[cleave]
|
||
[clop]
|
||
[map]
|
||
|
||
</pre></div><div><h2 id="function_fourth" class="func_name">fourth <a href="#function_fourth" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Replace a list with its fourth item.
|
||
|
||
[a b c d ...] fourth
|
||
--------------------------
|
||
d
|
||
|
||
### Definition
|
||
|
||
> [rest] [third]
|
||
|
||
### Crosslinks
|
||
|
||
[first]
|
||
[second]
|
||
[third]
|
||
[rest]
|
||
|
||
</pre></div><div><h2 id="function_gcd" class="func_name">gcd <a href="#function_gcd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Take two integers from the stack and replace them with their Greatest
|
||
Common Denominator.
|
||
|
||
### Definition
|
||
|
||
> true \[[tuck] [mod] [dup] 0 [>]\] [loop] [pop]
|
||
|
||
### Discussion
|
||
|
||
Euclid's Algorithm
|
||
|
||
</pre></div><div><h2 id="function_ab323e8d4f8c5d1c7d333fbe3e08b223c11f7bcc5066ace0af17172f77aa31b3" class="func_name">gcd2 <a href="#function_ab323e8d4f8c5d1c7d333fbe3e08b223c11f7bcc5066ace0af17172f77aa31b3" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Compiled GCD function.
|
||
|
||
### Discussion
|
||
|
||
See [gcd].
|
||
|
||
### Crosslinks
|
||
|
||
[gcd]
|
||
|
||
</pre></div><div><h2 id="function_ge" class="func_name">ge <a href="#function_ge" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Greater-than-or-equal-to comparison of two numbers.
|
||
|
||
a b ge
|
||
--------------
|
||
Boolean
|
||
(a >= b)
|
||
|
||
### Crosslinks
|
||
|
||
[cmp]
|
||
[eq]
|
||
[gt]
|
||
[le]
|
||
[lt]
|
||
[ne]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[\[[genrec]\] [ccccons]\] [nullary] [swons] [concat] [ifte]
|
||
|
||
(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.)
|
||
|
||
### Discussion
|
||
|
||
See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
|
||
|
||
From ["Recursion Theory and Joy"](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html)
|
||
by Manfred von Thun:
|
||
|
||
> "The genrec combinator takes four program parameters in addition to
|
||
> whatever data parameters it needs. Fourth from the top is an if-part,
|
||
> followed by a then-part. If the if-part yields true, then the then-part
|
||
> is executed and the combinator terminates. The other two parameters are
|
||
> the rec1-part and the rec2-part. If the if-part yields false, the
|
||
> rec1-part is executed. Following that the four program parameters and
|
||
> the combinator are again pushed onto the stack bundled up in a quoted
|
||
> form. Then the rec2-part is executed, where it will find the bundled
|
||
> form. Typically it will then execute the bundled form, either with i
|
||
> or with app2, or some other combinator."
|
||
|
||
The way to design one of these is to fix your base case `[then]` and the
|
||
test `[if]`, and then treat `rec1` and `rec2` as an else-part
|
||
"sandwiching" a quotation of the whole function.
|
||
|
||
For example, given a (general recursive) function `F`:
|
||
|
||
F == [I] [T] [R1] [R2] genrec
|
||
|
||
If the `[I]` if-part fails you must derive `R1` and `R2` from: :
|
||
|
||
... R1 [F] R2
|
||
|
||
Just set the stack arguments in front, and figure out what `R1` and `R2`
|
||
have to do to apply the quoted `[F]` in the proper way. In effect, the
|
||
`genrec` combinator turns into an [ifte] combinator with a quoted copy of
|
||
the original definition in the else-part:
|
||
|
||
F == [I] [T] [R1] [R2] genrec
|
||
== [I] [T] [R1 [F] R2] ifte
|
||
|
||
Tail recursive functions are those where `R2` is the `i` combinator:
|
||
|
||
P == [I] [T] [R] tailrec
|
||
== [I] [T] [R [P] i] ifte
|
||
== [I] [T] [R P] ifte
|
||
|
||
### Crosslinks
|
||
|
||
[anamorphism]
|
||
[tailrec]
|
||
[x]
|
||
|
||
</pre></div><div><h2 id="function_getitem" class="func_name">getitem <a href="#function_getitem" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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
|
||
|
||
### Definition
|
||
|
||
> [drop] [first]
|
||
|
||
### Discussion
|
||
|
||
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.)
|
||
|
||
### Crosslinks
|
||
|
||
[concat]
|
||
[first]
|
||
[first_two]
|
||
[flatten]
|
||
[fourth]
|
||
[remove]
|
||
[rest]
|
||
[reverse]
|
||
[rrest]
|
||
[second]
|
||
[shift]
|
||
[shunt]
|
||
[size]
|
||
[sort]
|
||
[split_at]
|
||
[split_list]
|
||
[swaack]
|
||
[third]
|
||
[zip]
|
||
</pre></div><div><h2 id="function_grabN" class="func_name">grabN <a href="#function_grabN" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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]
|
||
|
||
### Definition
|
||
|
||
> [\<\{\}] \[[cons]\] [times]
|
||
</pre></div><div><h2 id="function_grba" class="func_name">grba <a href="#function_grba" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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.
|
||
|
||
### Definition
|
||
|
||
> \[[stack] [popd]\] [dip]
|
||
|
||
### Discussion
|
||
|
||
This function "grabs" an item from the stack along with a copy of the stack.
|
||
It's part of the [app2] definition.
|
||
|
||
### Crosslinks
|
||
|
||
[app2]
|
||
</pre></div><div><h2 id="function_gt" class="func_name">gt <a href="#function_gt" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Greater-than comparison of two numbers.
|
||
|
||
a b gt
|
||
--------------
|
||
Boolean
|
||
(a > b)
|
||
|
||
### Crosslinks
|
||
|
||
[cmp]
|
||
[eq]
|
||
[ge]
|
||
[le]
|
||
[lt]
|
||
[ne]
|
||
</pre></div><div><h2 id="function_help" class="func_name">help <a href="#function_help" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Accepts a quoted symbol on the top of the stack and prints its
|
||
documentation.
|
||
|
||
[foo] help
|
||
----------------
|
||
|
||
### Discussion
|
||
|
||
Technically this is equivalent to `pop`, but it will only work if the
|
||
item on the top of the stack is a quoted symbol.
|
||
|
||
</pre></div><div><h2 id="function_hypot" class="func_name">hypot <a href="#function_hypot" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
x y hypot
|
||
---------------------------
|
||
sqrt(sqr(x) + sqr(y))
|
||
|
||
### Definition
|
||
|
||
> \[[sqr]\] [ii] [+] [sqrt]
|
||
|
||
### Discussion
|
||
|
||
This is another function that has to wait on the numeric tower.
|
||
|
||
### Crosslinks
|
||
|
||
[sqrt]
|
||
|
||
</pre></div><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
|
||
|
||
### Discussion
|
||
|
||
This is a fundamental combinator. It is used in all kinds of places. For
|
||
example, the [x] combinator can be defined as `dup i`.
|
||
|
||
</pre></div><div><h2 id="function_id" class="func_name">id <a href="#function_id" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
The identity function.
|
||
|
||
### Discussion
|
||
|
||
Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy.
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[nullary]\] [dipd] [swap] [branch]
|
||
|
||
### Crosslinks
|
||
|
||
[branch]
|
||
[loop]
|
||
[while]
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[dip]\] [dupdip] [i]
|
||
|
||
### 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 •
|
||
|
||
### Discussion
|
||
|
||
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
|
||
|
||
### Crosslinks
|
||
|
||
[app2]
|
||
[b]
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> [swons] [swaack] \[[i]\] [dip] [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]
|
||
|
||
|
||
### Discussion
|
||
|
||
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.
|
||
|
||
### Crosslinks
|
||
|
||
[swaack](#swaack)
|
||
|
||
</pre></div><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.
|
||
|
||
### Definition
|
||
|
||
> [infra] [first]
|
||
|
||
</pre></div><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
|
||
|
||
### Discussion
|
||
|
||
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.
|
||
</pre></div><div><h2 id="function_le" class="func_name">le <a href="#function_le" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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 <= b)
|
||
|
||
### Crosslinks
|
||
|
||
[cmp]
|
||
[eq]
|
||
[ge]
|
||
[gt]
|
||
[lt]
|
||
[ne]
|
||
</pre></div><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
|
||
|
||
### Discussion
|
||
|
||
This, along with [branch] and [fork], is one of the four main combinators
|
||
of all programming. The fourth, sequence, is implied by juxtaposition.
|
||
That is to say, in Joy `F G` is like `G(F(...))` in a language bassed on
|
||
function application. Or again, to quote the [Joy Wikipedia
|
||
entry](https://en.wikipedia.org/wiki/Joy_(programming_language)#Mathematical_purity),
|
||
|
||
> In Joy, the meaning function is a homomorphism from the syntactic monoid onto the semantic monoid. That is, the syntactic relation of concatenation of symbols maps directly onto the semantic relation of composition of functions.
|
||
|
||
Anyway, [branch], [fork], amd [loop] are the fundamental combinators in Joy.
|
||
Just as [branch] has it's more common and convenient form [ifte],
|
||
[loop] has [while].
|
||
|
||
### Crosslinks
|
||
|
||
[branch]
|
||
[fork]
|
||
[while]
|
||
</pre></div><div><h2 id="function_lshift" class="func_name">lshift <a href="#function_lshift" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[Logical Left-Shift](https://en.wikipedia.org/wiki/Logical_shift)
|
||
|
||
a n lshift
|
||
----------------
|
||
(a×2ⁿ)
|
||
|
||
### Crosslinks
|
||
|
||
[rshift]
|
||
</pre></div><div><h2 id="function_lt" class="func_name">lt <a href="#function_lt" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Less-Than comparison of the two items on the top of the
|
||
stack, replacing them with a Boolean value.
|
||
|
||
a b lt
|
||
-------------
|
||
Boolean
|
||
(a < b)
|
||
|
||
### Crosslinks
|
||
|
||
[cmp]
|
||
[eq]
|
||
[ge]
|
||
[gt]
|
||
[le]
|
||
[ne]
|
||
</pre></div><div><h2 id="function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="func_name">make_generator <a href="#function_766bd5a63cdb24e22cc7bed4516b51a3ebff706d9118393863881e7af8e4385d" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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
|
||
|
||
### Definition
|
||
|
||
> \[[codireco]\] [ccons]
|
||
|
||
### Discussion
|
||
|
||
See the ["Using `x` to Generate Values" notebook](https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation).
|
||
|
||
### Crosslinks
|
||
|
||
[codireco]
|
||
|
||
</pre></div><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]
|
||
|
||
### Discussion
|
||
|
||
This is a common operation in many languages. In Joy it can be a
|
||
parallelism combinator due to the "pure" nature of the language.
|
||
|
||
### Crosslinks
|
||
|
||
[app1]
|
||
[app2]
|
||
[app3]
|
||
[appN](#appn)
|
||
[fork]
|
||
|
||
</pre></div><div><h2 id="function_max" class="func_name">max <a href="#function_max" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Given a list find the maximum.
|
||
|
||
### Example
|
||
|
||
[1 2 3 4] max
|
||
-------------------
|
||
4
|
||
|
||
### Crosslinks
|
||
|
||
[min]
|
||
[size]
|
||
[sum]
|
||
|
||
</pre></div><div><h2 id="function_min" class="func_name">min <a href="#function_min" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Given a list find the minimum.
|
||
|
||
### Example
|
||
|
||
[1 2 3 4] min
|
||
-------------------
|
||
1
|
||
|
||
### Crosslinks
|
||
|
||
[max]
|
||
[size]
|
||
[sum]
|
||
|
||
</pre></div><div><h2 id="function_mod" class="func_name">mod <a href="#function_mod" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Return the remainder of `a` divided by `b`.
|
||
|
||
a b mod
|
||
-------------
|
||
(a%b)
|
||
|
||
### Crosslinks
|
||
|
||
[divmod]
|
||
[mul]
|
||
|
||
</pre></div><div><h2 id="function_modulus" class="func_name">modulus <a href="#function_modulus" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [mod](#mod).
|
||
|
||
</pre></div><div><h2 id="function_mul" class="func_name">mul <a href="#function_mul" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Multiply two numbers.
|
||
|
||
a b mul
|
||
-------------
|
||
(a×b)
|
||
|
||
### Crosslinks
|
||
|
||
[div]
|
||
[product]
|
||
|
||
</pre></div><div><h2 id="function_ne" class="func_name">ne <a href="#function_ne" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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)
|
||
|
||
### Crosslinks
|
||
|
||
[cmp]
|
||
[eq]
|
||
[ge]
|
||
[gt]
|
||
[le]
|
||
[lt]
|
||
</pre></div><div><h2 id="function_neg" class="func_name">neg <a href="#function_neg" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Invert the sign of a number.
|
||
|
||
a neg
|
||
-----------
|
||
-a
|
||
### Definition
|
||
|
||
> 0 [swap] [-]
|
||
|
||
</pre></div><div><h2 id="function_not" class="func_name">not <a href="#function_not" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Like [bool] but convert the item on the top of the stack to the inverse
|
||
Boolean value.
|
||
|
||
true not
|
||
--------------
|
||
false
|
||
|
||
false not
|
||
---------------
|
||
true
|
||
|
||
### Definition
|
||
|
||
> [bool] \[true\] \[false\] [branch]
|
||
|
||
### Crosslinks
|
||
|
||
[bool]
|
||
|
||
</pre></div><div><h2 id="function_nulco" class="func_name">nulco <a href="#function_nulco" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Take the item on the top of the stack and [cons] it onto `[nullary]`.
|
||
|
||
[F] nulco
|
||
-------------------
|
||
[[F] nullary]
|
||
|
||
### Definition
|
||
|
||
> \[[nullary]\] [cons]
|
||
|
||
### Discussion
|
||
|
||
Helper function for [\|\|] and [&&].
|
||
|
||
### Crosslinks
|
||
|
||
[&&]
|
||
[\|\|]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[stack]\] [dip] [infra] [first]
|
||
|
||
### Example
|
||
|
||
... [P] nullary
|
||
... [P] [stack] dip infra first
|
||
... stack [P] infra first
|
||
... [...] [P] infra first
|
||
... [a ...] first
|
||
... a
|
||
|
||
### Discussion
|
||
|
||
A very useful function that runs any other quoted function and returns
|
||
it's first result without disturbing the stack (under the quoted
|
||
program.)
|
||
|
||
### Crosslinks
|
||
|
||
[unary](#unary)
|
||
[binary](#binary)
|
||
[ternary](#ternary)
|
||
|
||
</pre></div><div><h2 id="function_of" class="func_name">of <a href="#function_of" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Like [getitem] but [swap]s the order of arguments.
|
||
|
||
### Example
|
||
|
||
2 [a b c d] of
|
||
--------------------
|
||
c
|
||
|
||
### Definition
|
||
|
||
> [swap] [getitem]
|
||
|
||
### Crosslinks
|
||
|
||
[getitem]
|
||
|
||
</pre></div><div><h2 id="function_or" class="func_name">or <a href="#function_or" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Logical bit-wise OR.
|
||
|
||
### Crosslinks
|
||
|
||
[and]
|
||
[xor]
|
||
|
||
</pre></div><div><h2 id="function_over" class="func_name">over <a href="#function_over" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[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.
|
||
|
||
> [swap] [tuck]
|
||
|
||
> \[[pop]\] [nullary]
|
||
|
||
> \[[dup]\] [dip] [swap]
|
||
|
||
> [unit] [dupdip]
|
||
|
||
> [unit] [dupdipd] [first]
|
||
|
||
And so on...
|
||
|
||
### Discussion
|
||
|
||
A fine old word from Forth.
|
||
|
||
### Crosslinks
|
||
|
||
[tuck]
|
||
|
||
</pre></div><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]
|
||
|
||
### Definition
|
||
|
||
> \[[i]\] [map]
|
||
|
||
### Discussion
|
||
|
||
A specialization of [map] that runs a list of functions in parallel (if
|
||
the underlying [map] function is so implemented, of course.)
|
||
|
||
### Crosslinks
|
||
|
||
[map]
|
||
|
||
</pre></div><div><h2 id="function_pick" class="func_name">pick <a href="#function_pick" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [getitem](#getitem).
|
||
|
||
</pre></div><div><h2 id="function_pm" class="func_name">pm <a href="#function_pm" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Plus or minus. Replace two numbers with their sum and difference.
|
||
|
||
a b pm
|
||
-----------------
|
||
(a+b) (a-b)
|
||
|
||
### Definition
|
||
|
||
> \[+\] \[-\] [clop]
|
||
|
||
</pre></div><div><h2 id="function_pop" class="func_name">pop <a href="#function_pop" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Pop the top item from the stack and discard it.
|
||
|
||
a pop
|
||
-----------
|
||
|
||
### Crosslinks
|
||
|
||
[popd]
|
||
[popdd]
|
||
[popop]
|
||
[popopd]
|
||
[popopdd]
|
||
[popopop]
|
||
|
||
</pre></div><div><h2 id="function_popd" class="func_name">popd <a href="#function_popd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[pop] the second item down on the stack.
|
||
|
||
a b popd
|
||
--------------
|
||
b
|
||
|
||
### Definition
|
||
|
||
> [swap] [pop]
|
||
|
||
### Crosslinks
|
||
|
||
[pop]
|
||
[popdd]
|
||
[popop]
|
||
[popopd]
|
||
[popopdd]
|
||
[popopop]
|
||
|
||
</pre></div><div><h2 id="function_popdd" class="func_name">popdd <a href="#function_popdd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[pop] the third item on the stack.
|
||
|
||
a b c popdd
|
||
-----------------
|
||
b c
|
||
|
||
### Definition
|
||
|
||
> [rolldown] [pop]
|
||
|
||
### Crosslinks
|
||
|
||
[pop]
|
||
[popd]
|
||
[popop]
|
||
[popopd]
|
||
[popopdd]
|
||
[popopop]
|
||
|
||
</pre></div><div><h2 id="function_popop" class="func_name">popop <a href="#function_popop" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[pop] two items from the stack.
|
||
|
||
a b popop
|
||
---------------
|
||
|
||
### Definition
|
||
|
||
> [pop] [pop]
|
||
|
||
### Crosslinks
|
||
|
||
[pop]
|
||
[popd]
|
||
[popdd]
|
||
[popopd]
|
||
[popopdd]
|
||
[popopop]
|
||
|
||
</pre></div><div><h2 id="function_popopd" class="func_name">popopd <a href="#function_popopd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[pop] the second and third items from the stack.
|
||
|
||
a b c popopd
|
||
------------------
|
||
c
|
||
|
||
### Definition
|
||
|
||
> [rollup] [popop]
|
||
|
||
### Crosslinks
|
||
|
||
[pop]
|
||
[popd]
|
||
[popdd]
|
||
[popop]
|
||
[popopdd]
|
||
[popopop]
|
||
|
||
</pre></div><div><h2 id="function_popopdd" class="func_name">popopdd <a href="#function_popopdd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
a b c d popopdd
|
||
---------------------
|
||
c d
|
||
|
||
### Definition
|
||
|
||
> \[[popop]\] [dipd]
|
||
|
||
### Crosslinks
|
||
|
||
[pop]
|
||
[popd]
|
||
[popdd]
|
||
[popop]
|
||
[popopd]
|
||
[popopop]
|
||
|
||
</pre></div><div><h2 id="function_popopop" class="func_name">popopop <a href="#function_popopop" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[pop] three items from the stack.
|
||
|
||
a b c popopop
|
||
-------------------
|
||
|
||
### Definition
|
||
|
||
> [pop] [popop]
|
||
|
||
### Crosslinks
|
||
|
||
[pop]
|
||
[popd]
|
||
[popdd]
|
||
[popop]
|
||
[popopd]
|
||
[popopdd]
|
||
|
||
</pre></div><div><h2 id="function_pow" class="func_name">pow <a href="#function_pow" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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><div><h2 id="function_pred" class="func_name">pred <a href="#function_pred" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Predecessor. Decrement TOS.
|
||
|
||
### Definition
|
||
|
||
> 1 -
|
||
|
||
### Crosslinks
|
||
|
||
[succ]
|
||
|
||
</pre></div><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)
|
||
|
||
> The primrec combinator expects two quoted programs in addition to a
|
||
> data parameter. For an integer data parameter it works like this: If
|
||
> the data parameter is zero, then the first quotation has to produce the
|
||
> value to be returned. If the data parameter is positive then the second
|
||
> has to combine the data parameter with the result of applying the
|
||
> function to its predecessor.
|
||
|
||
> 5 \[1\] \[\*\] primrec
|
||
|
||
> Then primrec tests whether the top element on the stack (initially the
|
||
> 5) is equal to zero. If it is, it pops it off and executes one of the
|
||
> quotations, the \[1\] which leaves 1 on the stack as the result.
|
||
> Otherwise it pushes a decremented copy of the top element and recurses.
|
||
> On the way back from the recursion it uses the other quotation, \[\*\],
|
||
> to multiply what is now a factorial on top of the stack by the second
|
||
> element on the stack.
|
||
|
||
|
||
0 [Base] [Recur] primrec
|
||
------------------------------
|
||
Base
|
||
|
||
n [Base] [Recur] primrec
|
||
------------------------------------------ n > 0
|
||
n (n-1) [Base] [Recur] primrec Recur
|
||
|
||
### Discussion
|
||
|
||
Simple and useful specialization of the [genrec] combinator from the
|
||
[original Joy system](https://www.kevinalbrecht.com/code/joy-mirror/index.html).
|
||
|
||
### Crosslinks
|
||
|
||
[genrec]
|
||
[tailrec]
|
||
|
||
</pre></div><div><h2 id="function_product" class="func_name">product <a href="#function_product" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Just as [sum] sums a list of numbers, this function multiplies them
|
||
together.
|
||
|
||
### Definition
|
||
|
||
> 1 [swap] \[[mul]\] [step]
|
||
|
||
Or,
|
||
|
||
> \[1\] \[[mul]\] [primrec]
|
||
|
||
|
||
</pre></div><div><h2 id="function_quoted" class="func_name">quoted <a href="#function_quoted" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
"Quote D" Wrap the second item on the stack in a list.
|
||
|
||
a b quoted
|
||
----------------
|
||
[a] b
|
||
|
||
### Definition
|
||
|
||
> \[[unit]\] [dip]
|
||
|
||
### Discussion
|
||
|
||
This comes from the original Joy stuff.
|
||
|
||
### Crosslinks
|
||
|
||
[unit]
|
||
|
||
</pre></div><div><h2 id="function_range" class="func_name">range <a href="#function_range" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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
|
||
--------------
|
||
[]
|
||
|
||
### Definition
|
||
|
||
> \[0 \<=\] \[1 - [dup]\] [anamorphism]
|
||
|
||
### Discussion
|
||
|
||
If `n` is less than 1 the resulting list is empty.
|
||
|
||
### Crosslinks
|
||
|
||
[range_to_zero]
|
||
|
||
</pre></div><div><h2 id="function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="func_name">range_to_zero <a href="#function_ee391b3e0636502027aa14f8e4fd6498ee690f4cff6ebc247120e4cbb583a774" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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]
|
||
|
||
### Definition
|
||
|
||
> [unit] \[[down_to_zero]\] [infra]
|
||
|
||
### Discussion
|
||
|
||
Note that the order is reversed compared to [range].
|
||
|
||
### Crosslinks
|
||
|
||
[down_to_zero]
|
||
[range]
|
||
|
||
</pre></div><div><h2 id="function_reco" class="func_name">reco <a href="#function_reco" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Replace the first item in a list with the item under it.
|
||
|
||
a [b ...] reco
|
||
--------------------
|
||
[a ...]
|
||
|
||
### Definition
|
||
|
||
> [rest] [cons]
|
||
|
||
### Crosslinks
|
||
|
||
[codireco]
|
||
[make_generator]
|
||
|
||
</pre></div><div><h2 id="function_rem" class="func_name">rem <a href="#function_rem" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [mod](#mod).
|
||
|
||
</pre></div><div><h2 id="function_remainder" class="func_name">remainder <a href="#function_remainder" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [mod](#mod).
|
||
|
||
</pre></div><div><h2 id="function_remove" class="func_name">remove <a href="#function_remove" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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><div><h2 id="function_rest" class="func_name">rest <a href="#function_rest" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[a ...] rest
|
||
------------------
|
||
[...]
|
||
|
||
### Crosslinks
|
||
|
||
[first]
|
||
[uncons]
|
||
|
||
</pre></div><div><h2 id="function_reverse" class="func_name">reverse <a href="#function_reverse" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Reverse the list on the top of the stack.
|
||
|
||
### Example
|
||
|
||
[1 2 3] reverse
|
||
---------------------
|
||
[3 2 1]
|
||
|
||
### Definition
|
||
|
||
> [\<\{\}] [shunt]
|
||
|
||
</pre></div><div><h2 id="function_2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="func_name">roll< <a href="#function_2a40b97c2fcb8f8cea992e519101735a642ca89734b9b57ecca5e4586327a4bd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [rolldown](#rolldown).
|
||
|
||
</pre></div><div><h2 id="function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="func_name">roll> <a href="#function_93e14595116819706f1c5b8b64589abc8f3c47cfa09082a3fcb9156b5318d44a" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [rollup](#rollup).
|
||
|
||
</pre></div><div><h2 id="function_rolldown" class="func_name">rolldown <a href="#function_rolldown" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
a b c rolldown
|
||
--------------------
|
||
b c a
|
||
|
||
### Definition
|
||
|
||
> [swapd] [swap]
|
||
|
||
### Crosslinks
|
||
|
||
[rollup]
|
||
|
||
</pre></div><div><h2 id="function_rollup" class="func_name">rollup <a href="#function_rollup" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
a b c rollup
|
||
------------------
|
||
c a b
|
||
|
||
### Definition
|
||
|
||
> [swap] [swapd]
|
||
|
||
### Crosslinks
|
||
|
||
[rolldown]
|
||
|
||
</pre></div><div><h2 id="function_round" class="func_name">round <a href="#function_round" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Round a number to a given precision in decimal digits.
|
||
|
||
### Discussion
|
||
|
||
Another one that won't make sense until the "numeric tower" is nailed
|
||
down.
|
||
|
||
</pre></div><div><h2 id="function_rrest" class="func_name">rrest <a href="#function_rrest" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[a b ...] rrest
|
||
---------------------
|
||
[...]
|
||
### Definition
|
||
|
||
> [rest] [rest]
|
||
|
||
### Crosslinks
|
||
|
||
[rest]
|
||
|
||
</pre></div><div><h2 id="function_rshift" class="func_name">rshift <a href="#function_rshift" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[Logical Right-Shift](https://en.wikipedia.org/wiki/Logical_shift)
|
||
|
||
a n rshift
|
||
----------------
|
||
(a∕2ⁿ)
|
||
|
||
### Crosslinks
|
||
|
||
[lshift]
|
||
</pre></div><div><h2 id="function_run" class="func_name">run <a href="#function_run" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Run a quoted program in a list.
|
||
|
||
### Example
|
||
|
||
[1 2 +] run
|
||
-----------------
|
||
[3]
|
||
|
||
### Definition
|
||
|
||
> [\<\{\}] [infra]
|
||
|
||
</pre></div><div><h2 id="function_second" class="func_name">second <a href="#function_second" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[a b ...] second
|
||
----------------------
|
||
b
|
||
|
||
### Definition
|
||
|
||
> [rest] [first]
|
||
|
||
### Crosslinks
|
||
|
||
[first]
|
||
[third]
|
||
[fourth]
|
||
|
||
</pre></div><div><h2 id="function_select" class="func_name">select <a href="#function_select" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Use a Boolean value to select one of two items from a sequence. :
|
||
|
||
[a b] false select
|
||
------------------------
|
||
a
|
||
|
||
[a b] true select
|
||
-----------------------
|
||
b
|
||
|
||
### Discussion
|
||
|
||
The sequence can contain more than two items but not fewer.
|
||
|
||
### Crosslinks
|
||
|
||
[choice]
|
||
|
||
</pre></div><div><h2 id="function_sharing" class="func_name">sharing <a href="#function_sharing" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Print redistribution information.
|
||
|
||
### Discussion
|
||
|
||
Mathematically this is a form of [id], but it has the side-effect of
|
||
printing out the GPL notice.
|
||
|
||
### Crosslinks
|
||
|
||
[warranty]
|
||
|
||
</pre></div><div><h2 id="function_shift" class="func_name">shift <a href="#function_shift" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Move the top item from one list to another.
|
||
|
||
### Example
|
||
|
||
[x y z] [a b c] shift
|
||
---------------------------
|
||
[a x y z] [b c]
|
||
|
||
### Definition
|
||
|
||
> [uncons] \[[swons]\] [dip]
|
||
|
||
### Crosslinks
|
||
|
||
[shunt]
|
||
|
||
</pre></div><div><h2 id="function_shunt" class="func_name">shunt <a href="#function_shunt" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Like [concat] but [reverse] the top list into the second.
|
||
|
||
### Example
|
||
|
||
[a b c] [d e f] shunt
|
||
---------------------------
|
||
[f e d a b c]
|
||
|
||
### Definition
|
||
|
||
> \[[swons]\] [step]
|
||
|
||
### Discussion
|
||
|
||
This is more efficient than [concat] so prefer it if you don't need to
|
||
preserve order.
|
||
|
||
### Crosslinks
|
||
|
||
[concat]
|
||
[reverse]
|
||
[shift]
|
||
|
||
</pre></div><div><h2 id="function_size" class="func_name">size <a href="#function_size" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Replace a list with its size.
|
||
|
||
### Example
|
||
|
||
[23 [cats] 4] size
|
||
------------------------
|
||
3
|
||
|
||
### Definition
|
||
|
||
> \[[pop] [++]\] [step_zero]
|
||
|
||
</pre></div><div><h2 id="function_sort" class="func_name">sort <a href="#function_sort" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Given a list return it sorted.
|
||
|
||
### Example
|
||
|
||
[4 2 5 7 1] sort
|
||
----------------------
|
||
[1 2 4 5 7]
|
||
|
||
</pre></div><div><h2 id="function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="func_name">spiral_next <a href="#function_b75cae41e7f9ba4ab72cc1c5ec83aa5313ea180fae61bc25370ce4e4b540c3c7" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Example code.
|
||
|
||
### Discussion
|
||
|
||
See the ["Square Spiral Example Joy Code" notebook](https://joypy.osdn.io/notebooks/Square_Spiral.html).
|
||
|
||
</pre></div><div><h2 id="function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="func_name">split_at <a href="#function_11410ec2e9e5af6b7643845e3382d79fd07d4518548586894c0201f69e98447c" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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]
|
||
|
||
### Definition
|
||
|
||
> \[[drop]\] \[[take]\] [clop]
|
||
|
||
### Discussion
|
||
|
||
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.
|
||
|
||
### Crosslinks
|
||
|
||
[split_list]
|
||
|
||
</pre></div><div><h2 id="function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="func_name">split_list <a href="#function_ba4c8ebb56beba87283248c7ef9ea77b0cf1d215cd283aa0c9fa0a3e971e8415" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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]
|
||
|
||
### Definition
|
||
|
||
> \[[take] [reverse]\] \[[drop]\] [clop]
|
||
|
||
### Discussion
|
||
|
||
Compare with [split_at]. This function does extra work to ensure that
|
||
[concat] would reconstruct the original list.
|
||
|
||
### Crosslinks
|
||
|
||
[split_at]
|
||
|
||
</pre></div><div><h2 id="function_sqr" class="func_name">sqr <a href="#function_sqr" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Square the number on the top of the stack.
|
||
|
||
n sqr
|
||
------------
|
||
n²
|
||
|
||
### Definition
|
||
|
||
> [dup] [mul]
|
||
|
||
</pre></div><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.
|
||
|
||
### Discussion
|
||
|
||
Another "numeric tower" hatch...
|
||
|
||
</pre></div><div><h2 id="function_stack" class="func_name">stack <a href="#function_stack" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Put the stack onto the stack.
|
||
|
||
... c b a stack
|
||
---------------------------
|
||
... c b a [a b c ...]
|
||
|
||
### Definition
|
||
|
||
> \[\] [swaack] [dup] [swaack] [first]
|
||
|
||
### Discussion
|
||
|
||
This function forms a pair with [unstack], and together they form the
|
||
complement to the "destructive" pair [enstacken] and [disenstacken].
|
||
|
||
### Crosslinks
|
||
|
||
[unstack]
|
||
[enstacken]
|
||
[disenstacken]
|
||
|
||
</pre></div><div><h2 id="function_stackd" class="func_name">stackd <a href="#function_stackd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Grab the stack under the top item and put it onto the stack.
|
||
|
||
### Example
|
||
|
||
... 1 2 3 stackd
|
||
------------------------
|
||
... 1 2 [2 1 ...] 3
|
||
|
||
### Definition
|
||
|
||
> \[[stack]\] [dip]
|
||
|
||
</pre></div><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
|
||
|
||
### Discussion
|
||
|
||
See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
|
||
|
||
### Crosslinks
|
||
|
||
[step_zero]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> 0 [roll>] [step]
|
||
|
||
### Discussion
|
||
|
||
[size] and [sum] can both be defined in terms of this specialization of
|
||
[step].
|
||
|
||
### Crosslinks
|
||
|
||
[step]
|
||
|
||
</pre></div><div><h2 id="function_stuncons" class="func_name">stuncons <a href="#function_stuncons" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Take the [stack] and [uncons] the top item.
|
||
|
||
### Example
|
||
|
||
1 2 3 stuncons
|
||
--------------------
|
||
1 2 3 3 [2 1]
|
||
|
||
### Definition
|
||
|
||
> [stack] [uncons]
|
||
|
||
</pre></div><div><h2 id="function_stununcons" class="func_name">stununcons <a href="#function_stununcons" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Take the [stack] and [uncons] the top two items.
|
||
|
||
### Example
|
||
|
||
1 2 3 stununcons
|
||
----------------------
|
||
1 2 3 3 2 [1]
|
||
|
||
### Definition
|
||
|
||
> [stack] [uncons] [uncons]
|
||
|
||
### Crosslinks
|
||
|
||
[stuncons]
|
||
|
||
</pre></div><div><h2 id="function_sub" class="func_name">sub <a href="#function_sub" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Subtract the number on the top of the stack from the number below it.
|
||
|
||
a b sub
|
||
-------------
|
||
(a-b)
|
||
|
||
### Crosslinks
|
||
|
||
[add]
|
||
|
||
</pre></div><div><h2 id="function_succ" class="func_name">succ <a href="#function_succ" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Successor. Increment TOS.
|
||
|
||
### Definition
|
||
|
||
> 1 +
|
||
|
||
### Crosslinks
|
||
|
||
[pred]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[+\] [step_zero]
|
||
|
||
### Crosslinks
|
||
|
||
[size]
|
||
|
||
</pre></div><div><h2 id="function_swaack" class="func_name">swaack <a href="#function_swaack" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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]
|
||
|
||
### Discussion
|
||
|
||
This function works as a kind of "context switch". It's used in the
|
||
definition of [infra].
|
||
|
||
### Crosslinks
|
||
|
||
[infra]
|
||
|
||
</pre></div><div><h2 id="function_swap" class="func_name">swap <a href="#function_swap" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Swap the top two items on the stack.
|
||
|
||
a b swap
|
||
--------------
|
||
b a
|
||
|
||
### Crosslinks
|
||
|
||
[swapd]
|
||
|
||
</pre></div><div><h2 id="function_swapd" class="func_name">swapd <a href="#function_swapd" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Swap the second and third items on the stack.
|
||
|
||
a b c swapd
|
||
-----------------
|
||
b a c
|
||
|
||
### Definition
|
||
|
||
> \[[swap]\] [dip]
|
||
|
||
### Crosslinks
|
||
|
||
[over]
|
||
[tuck]
|
||
|
||
</pre></div><div><h2 id="function_swoncat" class="func_name">swoncat <a href="#function_swoncat" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[concat] two lists, but [swap] the lists first.
|
||
|
||
### Definition
|
||
|
||
> [swap] [concat]
|
||
|
||
### Crosslinks
|
||
|
||
[concat]
|
||
|
||
</pre></div><div><h2 id="function_swons" class="func_name">swons <a href="#function_swons" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Like [cons] but [swap] the item and list.
|
||
|
||
[...] a swons
|
||
-------------------
|
||
[a ...]
|
||
|
||
### Definition
|
||
|
||
> [swap] [cons]
|
||
|
||
</pre></div><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.
|
||
|
||
### Definition
|
||
|
||
> \[[i]\] [genrec]
|
||
|
||
### Discussion
|
||
|
||
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).
|
||
|
||
### Crosslinks
|
||
|
||
[genrec]
|
||
|
||
</pre></div><div><h2 id="function_take" class="func_name">take <a href="#function_take" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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]
|
||
|
||
### Definition
|
||
|
||
> [\<\<\{\}] \[[shift]\] [times] [pop]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> [binary] [popd]
|
||
|
||
### Discussion
|
||
|
||
Runs any other quoted function and returns its first result while
|
||
consuming exactly three items from the stack.
|
||
|
||
### Crosslinks
|
||
|
||
[binary](#binary)
|
||
[nullary](#nullary)
|
||
[unary](#unary)
|
||
|
||
</pre></div><div><h2 id="function_third" class="func_name">third <a href="#function_third" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[a b c ...] third
|
||
-----------------------
|
||
c
|
||
|
||
### Definition
|
||
|
||
> [rest] [second]
|
||
|
||
### Crosslinks
|
||
|
||
[first]
|
||
[second]
|
||
[fourth]
|
||
[rest]
|
||
|
||
</pre></div><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 <= 0
|
||
... .
|
||
|
||
... 1 [Q] . times
|
||
-----------------------
|
||
... . Q
|
||
|
||
... n [Q] . times
|
||
------------------------------------- w/ n > 1
|
||
... . Q (n-1) [Q] times
|
||
|
||
### Definition
|
||
|
||
> \[\-- dip\] cons \[swap\] infra \[0 \>\] swap while pop :
|
||
|
||
|
||
### Discussion
|
||
|
||
This works by building a little [while] program and running it:
|
||
|
||
1 3 [++] • [-- dip] cons [swap] infra [0 >] swap while pop
|
||
1 3 [++] [-- dip] • cons [swap] infra [0 >] swap while pop
|
||
1 3 [[++] -- dip] • [swap] infra [0 >] swap while pop
|
||
1 3 [[++] -- dip] [swap] • infra [0 >] swap while pop
|
||
dip -- [++] • swap [3 1] swaack [0 >] swap while pop
|
||
dip [++] -- • [3 1] swaack [0 >] swap while pop
|
||
dip [++] -- [3 1] • swaack [0 >] swap while pop
|
||
1 3 [-- [++] dip] • [0 >] swap while pop
|
||
1 3 [-- [++] dip] [0 >] • swap while pop
|
||
1 3 [0 >] [-- [++] dip] • while pop
|
||
|
||
This is a common pattern in Joy. You accept some parameters from the
|
||
stack which typically include qouted programs and use them to build
|
||
another program which does the actual work. This is kind of like macros
|
||
in Lisp, or preprocessor directives in C.
|
||
|
||
</pre></div><div><h2 id="function_truthy" class="func_name">truthy <a href="#function_truthy" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [bool](#bool).
|
||
|
||
</pre></div><div><h2 id="function_tuck" class="func_name">tuck <a href="#function_tuck" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[dup] the item on the top of the stack under the second item on the
|
||
stack.
|
||
|
||
a b tuck
|
||
--------------
|
||
b a b
|
||
|
||
### Definition
|
||
|
||
> [dup] \[[swap]\] [dip]
|
||
|
||
### Crosslinks
|
||
|
||
[over]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> [nullary] [popd]
|
||
|
||
### Discussion
|
||
|
||
Runs any other quoted function and returns its first result while
|
||
consuming exactly one item from the stack.
|
||
|
||
### Crosslinks
|
||
|
||
[binary](#binary)
|
||
[nullary](#nullary)
|
||
[ternary](#ternary)
|
||
|
||
</pre></div><div><h2 id="function_uncons" class="func_name">uncons <a href="#function_uncons" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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 [...]
|
||
|
||
### Discussion
|
||
|
||
This is the inverse of [cons].
|
||
|
||
### Crosslinks
|
||
|
||
[cons]
|
||
|
||
</pre></div><div><h2 id="function_unique" class="func_name">unique <a href="#function_unique" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Given a list remove duplicate items.
|
||
|
||
</pre></div><div><h2 id="function_unit" class="func_name">unit <a href="#function_unit" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
a unit
|
||
------------
|
||
[a]
|
||
|
||
### Definition
|
||
|
||
> \[\] [cons]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
> \[[i]\] [dip]
|
||
|
||
### Crosslinks
|
||
|
||
[unit]
|
||
|
||
</pre></div><div><h2 id="function_unswons" class="func_name">unswons <a href="#function_unswons" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
[a ...] unswons
|
||
---------------------
|
||
[...] a
|
||
|
||
### Definition
|
||
|
||
> [uncons] [swap]
|
||
|
||
</pre></div><div><h2 id="function_void" class="func_name">void <a href="#function_void" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
True if the form on TOS is void otherwise False.
|
||
|
||
### Discussion
|
||
|
||
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/)
|
||
|
||
</pre></div><div><h2 id="function_warranty" class="func_name">warranty <a href="#function_warranty" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Print warranty information.
|
||
|
||
</pre></div><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 -> false
|
||
|
||
[P] [F] while
|
||
--------------------- P -> true
|
||
F [P] [F] while
|
||
|
||
### Definition
|
||
|
||
> [swap] [nulco] [dupdipd] [concat] [loop]
|
||
|
||
### Crosslinks
|
||
|
||
[loop]
|
||
|
||
</pre></div><div><h2 id="function_words" class="func_name">words <a href="#function_words" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Print all the words in alphabetical order.
|
||
|
||
### Discussion
|
||
|
||
Mathematically this is a form of [id].
|
||
|
||
### Crosslinks
|
||
|
||
[help]
|
||
|
||
</pre></div><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
|
||
|
||
### Definition
|
||
|
||
dup i
|
||
|
||
### Discussion
|
||
|
||
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
|
||
|
||
|
||
</pre></div><div><h2 id="function_xor" class="func_name">xor <a href="#function_xor" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
Logical bit-wise eXclusive OR.
|
||
|
||
### Crosslinks
|
||
|
||
[and]
|
||
[or]
|
||
|
||
</pre></div><div><h2 id="function_zip" class="func_name">zip <a href="#function_zip" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
Function
|
||
|
||
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><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
|
||
|
||
|
||
### Definition
|
||
|
||
> [nulco](#nulco) \[[nullary](#nullary)\] [dip](#dip) \[true\] [branch](#branch)
|
||
|
||
### Discussion
|
||
|
||
Accept two quoted programs, run the first and expect a Boolean value, if
|
||
it’s `false` pop it and run the second program (which should also return a
|
||
Boolean value) otherwise pop the second program (leaving `true` on the
|
||
stack.)
|
||
|
||
[A] [B] ||
|
||
---------------- A -> false
|
||
B
|
||
|
||
|
||
[A] [B] ||
|
||
---------------- A -> true
|
||
true
|
||
|
||
### Crosslinks
|
||
|
||
[&&](#section-1)
|
||
</pre></div><div><h2 id="function_4f8865abeddbfab37520d0c56eed1bf17f37e3778e1a55e6dc54895d2ae17849" class="func_name">• <a href="#function_4f8865abeddbfab37520d0c56eed1bf17f37e3778e1a55e6dc54895d2ae17849" class="self_link">¶</a></h2><pre>
|
||
|
||
|
||
See [id](#id).
|
||
|
||
</pre></div></body></html>
|