2 <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
4 <meta charset="utf-8" />
5 <meta name="generator" content="pandoc" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7 <title>Functor-Reference</title>
11 font-family: Georgia, serif;
14 background-color: #fdfdfd;
24 word-wrap: break-word;
25 text-rendering: optimizeLegibility;
28 @media (max-width: 600px) {
36 background-color: transparent;
45 page-break-after: avoid;
60 h1, h2, h3, h4, h5, h6 {
78 margin: 1em 0 1em 1.7em;
80 border-left: 2px solid #e6e6e6;
84 font-family: Menlo, Monaco, 'Lucida Console', Consolas, monospace;
97 background-color: transparent;
101 background-color: #1a1a1a;
108 border-collapse: collapse;
112 font-variant-numeric: lining-nums tabular-nums;
115 margin-bottom: 0.75em;
119 border-top: 1px solid #1a1a1a;
120 border-bottom: 1px solid #1a1a1a;
123 border-top: 1px solid #1a1a1a;
124 padding: 0.25em 0.5em 0.25em 0.5em;
127 padding: 0.125em 0.5em 0.25em 0.5em;
137 text-decoration: none;
139 code{white-space: pre-wrap;}
140 span.smallcaps{font-variant: small-caps;}
141 span.underline{text-decoration: underline;}
142 div.column{display: inline-block; vertical-align: top; width: 50%;}
143 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
144 ul.task-list{list-style: none;}
145 .display.math{display: block; text-align: center; margin: 0.5rem auto;}
148 <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
152 <nav id="TOC" role="doc-toc">
154 <li><a href="#functor-reference">Functor Reference</a>
156 <li><a href="#section">!-</a></li>
157 <li><a href="#app1">app1</a></li>
158 <li><a href="#b">b</a></li>
159 <li><a href="#binary">binary</a></li>
160 <li><a href="#ccons">ccons</a></li>
161 <li><a href="#cons">cons</a></li>
162 <li><a href="#i">i</a></li>
163 <li><a href="#infra">infra</a></li>
164 <li><a href="#nullary">nullary</a></li>
165 <li><a href="#ternary">ternary</a></li>
166 <li><a href="#unary">unary</a></li>
167 <li><a href="#uncons">uncons</a></li>
168 <li><a href="#x">x</a></li>
172 <h1 id="functor-reference">Functor Reference</h1>
173 <p>Version -10.0.0</p>
174 <p>Each function, combinator, or definition should be documented here.</p>
176 <h2 id="section">!-</h2>
177 <p>“not negative”</p>
178 <p>(Function, Boolean Predicate)</p>
179 <p>Integer on top of stack is replaced by Boolean value indicating whether it is non-negative.</p>
187 <h3 id="definition">Definition</h3>
188 <pre><code>0 >=</code></pre>
190 <h2 id="app1">app1</h2>
191 <p>“apply one”</p>
193 <p>Given a quoted program on TOS and anything as the second stack item run the program without disturbing the stack and replace the two args with the first result of the program.</p>
194 <pre><code> ... x [Q] app1
195 ---------------------------------
196 ... [x ...] [Q] infra first</code></pre>
197 <h3 id="definition-1">Definition</h3>
198 <pre><code>nullary popd</code></pre>
199 <h3 id="discussion">Discussion</h3>
200 <p>Just a specialization of <code>nullary</code> really. Its parallelizable cousins are more useful.</p>
204 <p>Run two quoted programs</p>
205 <pre><code> [P] [Q] b
208 <h3 id="definition-2">Definition</h3>
209 <pre><code>[i] dip i</code></pre>
210 <h3 id="derivation">Derivation</h3>
216 <h3 id="discussion-1">Discussion</h3>
217 <p>This combinator comes in handy.</p>
218 <h3 id="crosslinks">Crosslinks</h3>
219 <p><a href="#dupdip">dupdip</a> <a href="#ii">ii</a></p>
221 <h2 id="binary">binary</h2>
223 <p>Run a quoted program using exactly two stack values and leave the first item of the result on the stack.</p>
224 <pre><code> ... y x [P] binary
225 -----------------------
227 <h3 id="definition-3">Definition</h3>
228 <pre><code>unary popd</code></pre>
229 <h3 id="discussion-2">Discussion</h3>
230 <p>Runs any other quoted function and returns its first result while consuming exactly two items from the stack.</p>
231 <h3 id="crosslinks-1">Crosslinks</h3>
232 <p><a href="#nullary">nullary</a> <a href="#ternary">ternary</a> <a href="#unary">unary</a></p>
234 <h2 id="ccons">ccons</h2>
236 <p>Given two items and a list, append the items to the list to make a new list.</p>
237 <pre><code> B A [...] ccons
238 ---------------------
239 [B A ...]</code></pre>
240 <h3 id="definition-4">Definition</h3>
241 <pre><code>cons cons</code></pre>
242 <h3 id="discussion-3">Discussion</h3>
243 <p>Does <code>cons</code> twice.</p>
244 <h3 id="crosslinks-2">Crosslinks</h3>
245 <p><a href="#cons">cons</a></p>
247 <h2 id="cons">cons</h2>
248 <p>(Basis Function)</p>
249 <p>Given an item and a list, append the item to the list to make a new list.</p>
250 <pre><code> A [...] cons
253 <h3 id="source">Source</h3>
254 <pre><code>func(cons, [list(A), B|S], [list([B|A])|S]).</code></pre>
255 <h3 id="discussion-4">Discussion</h3>
256 <p>Cons is a venerable old function from Lisp. It doesn’t inspect the item but it will not cons onto a non-list. It’s inverse operation is called <code>uncons</code>.</p>
257 <h3 id="crosslinks-3">Crosslinks</h3>
258 <p><a href="#ccons">ccons</a> <a href="#uncons">uncons</a></p>
261 <p>(Basis Combinator)</p>
262 <p>Append a quoted expression onto the pending expression.</p>
266 <h3 id="source-1">Source</h3>
267 <pre><code>combo(i, [list(P)|S], S, Ei, Eo) :- append(P, Ei, Eo).</code></pre>
268 <h3 id="discussion-5">Discussion</h3>
269 <p>This is probably the fundamental combinator. You wind up using it in all kinds of places (for example, the <code>x</code> combinator can be defined as <code>dup i</code>.)</p>
271 <h2 id="infra">infra</h2>
273 <p>Accept a quoted program and a list on the stack and run the program with the list as its stack. Does not affect the stack (below the list.)</p>
274 <pre><code> ... [a b c] [Q] infra
275 ---------------------------
276 c b a Q [...] swaack</code></pre>
277 <h3 id="definition-5">Definition</h3>
278 <pre><code>swons swaack [i] dip swaack</code></pre>
279 <h3 id="discussion-6">Discussion</h3>
280 <p>This is one of the more useful combinators. It allows a quoted expression to serve as a stack for a program, effectively running it in a kind of “pocket universe”. If the list represents a datastructure then <code>infra</code> lets you work on its internal structure.</p>
281 <h3 id="crosslinks-4">Crosslinks</h3>
282 <p><a href="#swaack">swaack</a></p>
284 <h2 id="nullary">nullary</h2>
286 <p>Run a quoted program without using any stack values and leave the first item of the result on the stack.</p>
287 <pre><code> ... [P] nullary
288 ---------------------
290 <h3 id="definition-6">Definition</h3>
291 <pre><code>[stack] dip infra first</code></pre>
292 <h3 id="derivation-1">Derivation</h3>
293 <pre><code>... [P] nullary
294 ... [P] [stack] dip infra first
295 ... stack [P] infra first
296 ... [...] [P] infra first
299 <h3 id="discussion-7">Discussion</h3>
300 <p>A very useful function that runs any other quoted function and returns it’s first result without disturbing the stack (under the quoted program.)</p>
301 <h3 id="crosslinks-5">Crosslinks</h3>
302 <p><a href="#unary">unary</a> <a href="#binary">binary</a> <a href="#ternary">ternary</a></p>
304 <h2 id="ternary">ternary</h2>
306 <p>Run a quoted program using exactly three stack values and leave the first item of the result on the stack.</p>
307 <pre><code> ... z y x [P] unary
308 -------------------------
310 <h3 id="definition-7">Definition</h3>
311 <pre><code>binary popd</code></pre>
312 <h3 id="discussion-8">Discussion</h3>
313 <p>Runs any other quoted function and returns its first result while consuming exactly three items from the stack.</p>
314 <h3 id="crosslinks-6">Crosslinks</h3>
315 <p><a href="#binary">binary</a> <a href="#nullary">nullary</a> <a href="#unary">unary</a></p>
317 <h2 id="unary">unary</h2>
319 <p>Run a quoted program using exactly one stack value and leave the first item of the result on the stack.</p>
320 <pre><code> ... x [P] unary
321 ---------------------
323 <h3 id="definition-8">Definition</h3>
324 <pre><code>nullary popd</code></pre>
325 <h3 id="discussion-9">Discussion</h3>
326 <p>Runs any other quoted function and returns its first result while consuming exactly one item from the stack.</p>
327 <h3 id="crosslinks-7">Crosslinks</h3>
328 <p><a href="#binary">binary</a> <a href="#nullary">nullary</a> <a href="#ternary">ternary</a></p>
330 <h2 id="uncons">uncons</h2>
331 <p>(Basis Function)</p>
332 <p>Removes an item from a list and leaves it on the stack under the rest of the list. You cannot <code>uncons</code> an item from an empty list.</p>
333 <pre><code> [A ...] uncons
336 <h3 id="source-2">Source</h3>
337 <pre><code>func(uncons, Si, So) :- func(cons, So, Si).</code></pre>
338 <h3 id="discussion-10">Discussion</h3>
339 <p>This is the inverse of <code>cons</code>.</p>
340 <h3 id="crosslinks-8">Crosslinks</h3>
341 <p><a href="#cons">cons</a></p>
348 <h3 id="definition-9">Definition</h3>
349 <pre><code>dup i</code></pre>
350 <h3 id="discussion-11">Discussion</h3>
351 <p>The <code>x</code> combinator …</p>