6 <meta charset="utf-8" />
7 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
9 <title>Joy Interpreter — Thun 0.4.1 documentation</title>
10 <link rel="stylesheet" type="text/css" href="_static/pygments.css" />
11 <link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
12 <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
13 <script src="_static/jquery.js"></script>
14 <script src="_static/underscore.js"></script>
15 <script src="_static/doctools.js"></script>
16 <link rel="index" title="Index" href="genindex.html" />
17 <link rel="search" title="Search" href="search.html" />
18 <link rel="next" title="Stack or Quote or Sequence or List…" href="stack.html" />
19 <link rel="prev" title="Thun: Joy in Python" href="notebooks/Intro.html" />
21 <link rel="stylesheet" href="_static/custom.css" type="text/css" />
24 <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
29 <div class="document">
30 <div class="documentwrapper">
31 <div class="bodywrapper">
34 <div class="body" role="main">
36 <section id="joy-interpreter">
37 <h1>Joy Interpreter<a class="headerlink" href="#joy-interpreter" title="Permalink to this headline">¶</a></h1>
38 <section id="module-joy.joy">
39 <span id="joy-joy"></span><h2><code class="docutils literal notranslate"><span class="pre">joy.joy</span></code><a class="headerlink" href="#module-joy.joy" title="Permalink to this headline">¶</a></h2>
40 <p>This module implements an interpreter for a dialect of Joy that
41 attempts to stay very close to the spirit of Joy but does not precisely
42 match the behaviour of the original version(s) written in C.</p>
43 <dl class="py exception">
44 <dt class="sig sig-object py" id="joy.joy.UnknownSymbolError">
45 <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">joy.joy.</span></span><span class="sig-name descname"><span class="pre">UnknownSymbolError</span></span><a class="reference internal" href="_modules/joy/joy.html#UnknownSymbolError"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#joy.joy.UnknownSymbolError" title="Permalink to this definition">¶</a></dt>
48 <dl class="py function">
49 <dt class="sig sig-object py" id="joy.joy.interp">
50 <span class="sig-prename descclassname"><span class="pre">joy.joy.</span></span><span class="sig-name descname"><span class="pre">interp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stack</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dictionary</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/joy.html#interp"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#joy.joy.interp" title="Permalink to this definition">¶</a></dt>
51 <dd><p>Simple REPL with no extra output, suitable for use in scripts.</p>
54 <dl class="py function">
55 <dt class="sig sig-object py" id="joy.joy.joy">
56 <span class="sig-prename descclassname"><span class="pre">joy.joy.</span></span><span class="sig-name descname"><span class="pre">joy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stack</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expression</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dictionary</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">viewer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/joy.html#joy"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#joy.joy.joy" title="Permalink to this definition">¶</a></dt>
57 <dd><p>Evaluate a Joy expression on a stack.</p>
58 <p>This function iterates through a sequence of terms which are either
59 literals (strings, numbers, sequences of terms) or function symbols.
60 Literals are put onto the stack and functions are looked up in the
61 dictionary and executed.</p>
63 <div><p>The viewer is a function that is called with the stack and expression
64 on every iteration, its return value is ignored.</p>
65 <dl class="field-list simple">
66 <dt class="field-odd">param stack stack</dt>
67 <dd class="field-odd"><p>The stack.</p>
69 <dt class="field-even">param stack expression</dt>
70 <dd class="field-even"><p>The expression to evaluate.</p>
72 <dt class="field-odd">param dict dictionary</dt>
73 <dd class="field-odd"><p>A <code class="docutils literal notranslate"><span class="pre">dict</span></code> mapping names to Joy functions.</p>
75 <dt class="field-even">param function viewer</dt>
76 <dd class="field-even"><p>Optional viewer function.</p>
78 <dt class="field-odd">rtype</dt>
79 <dd class="field-odd"><p>(stack, (), dictionary)</p>
85 <dl class="py function">
86 <dt class="sig sig-object py" id="joy.joy.repl">
87 <span class="sig-prename descclassname"><span class="pre">joy.joy.</span></span><span class="sig-name descname"><span class="pre">repl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stack</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dictionary</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/joy.html#repl"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#joy.joy.repl" title="Permalink to this definition">¶</a></dt>
88 <dd><p>Read-Evaluate-Print Loop</p>
89 <p>Accept input and run it on the stack, loop.</p>
90 <dl class="field-list simple">
91 <dt class="field-odd">Parameters</dt>
92 <dd class="field-odd"><ul class="simple">
93 <li><p><strong>stack</strong> (<em>stack</em>) – The stack.</p></li>
94 <li><p><strong>dictionary</strong> (<em>dict</em>) – A <code class="docutils literal notranslate"><span class="pre">dict</span></code> mapping names to Joy functions.</p></li>
97 <dt class="field-even">Return type</dt>
98 <dd class="field-even"><p>stack</p>
103 <dl class="py function">
104 <dt class="sig sig-object py" id="joy.joy.run">
105 <span class="sig-prename descclassname"><span class="pre">joy.joy.</span></span><span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stack</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dictionary</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">viewer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/joy/joy.html#run"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#joy.joy.run" title="Permalink to this definition">¶</a></dt>
106 <dd><p>Return the stack resulting from running the Joy code text on the stack.</p>
107 <dl class="field-list simple">
108 <dt class="field-odd">Parameters</dt>
109 <dd class="field-odd"><ul class="simple">
110 <li><p><strong>text</strong> (<em>str</em>) – Joy code.</p></li>
111 <li><p><strong>stack</strong> (<em>stack</em>) – The stack.</p></li>
112 <li><p><strong>dictionary</strong> (<em>dict</em>) – A <code class="docutils literal notranslate"><span class="pre">dict</span></code> mapping names to Joy functions.</p></li>
113 <li><p><strong>viewer</strong> (<em>function</em>) – Optional viewer function.</p></li>
116 <dt class="field-even">Return type</dt>
117 <dd class="field-even"><p>(stack, (), dictionary)</p>
130 <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
131 <div class="sphinxsidebarwrapper">
132 <h1 class="logo"><a href="index.html">Thun</a></h1>
143 <li class="toctree-l1"><a class="reference internal" href="notebooks/Intro.html">Thun: Joy in Python</a></li>
144 <li class="toctree-l1 current"><a class="current reference internal" href="#">Joy Interpreter</a><ul>
145 <li class="toctree-l2"><a class="reference internal" href="#module-joy.joy"><code class="docutils literal notranslate"><span class="pre">joy.joy</span></code></a></li>
148 <li class="toctree-l1"><a class="reference internal" href="stack.html">Stack or Quote or Sequence or List…</a></li>
149 <li class="toctree-l1"><a class="reference internal" href="parser.html">Parsing Text into Joy Expressions</a></li>
150 <li class="toctree-l1"><a class="reference internal" href="pretty.html">Tracing Joy Execution</a></li>
151 <li class="toctree-l1"><a class="reference internal" href="library.html">Function Reference</a></li>
152 <li class="toctree-l1"><a class="reference internal" href="lib.html">Functions Grouped by, er, Function with Examples</a></li>
153 <li class="toctree-l1"><a class="reference internal" href="types.html">Type Inference of Joy Expressions</a></li>
154 <li class="toctree-l1"><a class="reference internal" href="notebooks/index.html">Essays about Programming in Joy</a></li>
157 <div class="relations">
158 <h3>Related Topics</h3>
160 <li><a href="index.html">Documentation overview</a><ul>
161 <li>Previous: <a href="notebooks/Intro.html" title="previous chapter">Thun: Joy in Python</a></li>
162 <li>Next: <a href="stack.html" title="next chapter">Stack or Quote or Sequence or List…</a></li>
166 <div id="searchbox" style="display: none" role="search">
167 <h3 id="searchlabel">Quick search</h3>
168 <div class="searchformwrapper">
169 <form class="search" action="search.html" method="get">
170 <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
171 <input type="submit" value="Go" />
175 <script>$('#searchbox').show(0);</script>
186 <div class="clearer"></div>
188 <div class="footer" role="contentinfo">
189 <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">
190 <img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" />
193 <span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">Thun Documentation</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="https://joypy.osdn.io/" property="cc:attributionName" rel="cc:attributionURL">Simon Forman</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.<br />Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="https://osdn.net/projects/joypy/" rel="dct:source">https://osdn.net/projects/joypy/</a>.
194 Created using <a href="http://sphinx-doc.org/">Sphinx</a> 4.3.0.