Compare commits

..

No commits in common. "trunk" and "one_ref" have entirely different histories.

26 changed files with 917 additions and 936 deletions

View File

@ -22,7 +22,7 @@ Joy is:
* [Stack-based](https://en.wikipedia.org/wiki/Stack-oriented_programming_language)
* [Concatinative](https://en.wikipedia.org/wiki/Concatenative_programming_language)
(See also [concatenative.org](http://www.concatenative.org/wiki/view/Concatenative%20language))
* [Categorical](https://ariadne.systems/pub/~sforman/Thun/notebooks/Categorical.html)
* [Categorical](https://joypy.osdn.io/notebooks/Categorical.html)
The best source for learning about Joy is the information made available
at the [website of La Trobe University](http://www.latrobe.edu.au/humanities/research/research-projects/past-projects/joy-programming-language)
@ -45,26 +45,26 @@ Here is an example of Joy code. This function `square_spiral` accepts
two integers and increments or decrements one of them such that the new
pair of numbers is the next coordinate pair in a square spiral (like the
kind used to construct an [Ulam Spiral](https://en.wikipedia.org/wiki/Ulam_spiral)).
For more information see [Square Spiral Example Joy Code](https://ariadne.systems/pub/~sforman/Thun/notebooks/Square_Spiral.html).
For more information see [Square Spiral Example Joy Code](https://joypy.osdn.io/notebooks/Square_Spiral.html).
square_spiral [p] [then] [else] ifte
square_spiral [_p] [_then] [_else] ifte
p [p0] [p1] and
p0 [abs] ii <=
p1 [<>] [pop !-] or
_p [_p0] [_p1] and
_p0 [abs] ii <=
_p1 [<>] [pop !-] or
then [ !-] [[++]] [[--]] ifte dip
else [pop !-] [--] [++] ifte
_then [ !-] [[++]] [[--]] ifte dip
_else [pop !-] [--] [++] ifte
It might seem unreadable but with familiarity it becomes as legible as
any other notation.
## Project Hosted on [Ariadne Systems](https://ariadne.systems/gogs/sforman/Thun)
## Project Hosted on [SourceHut](https://git.sr.ht/~sforman/Thun)
* [Source Repository](https://ariadne.systems/gogs/sforman/Thun)
* [Source Repository](https://git.sr.ht/~sforman/Thun)
([mirror](https://github.com/calroc/Thun))
* [Bug tracker](https://ariadne.systems/gogs/sforman/Thun/issues)
* [Bug tracker](https://todo.sr.ht/~sforman/thun-der)
([old tracker](https://osdn.net/projects/joypy/ticket/))
* [Forums](https://osdn.net/projects/joypy/forums/)
* [Mailing list](https://osdn.net/projects/joypy/lists/)
@ -74,31 +74,24 @@ any other notation.
The `Thun.md` document describes the Thun dialect. Most of the rest of
documentation is in the form of
[Jupyter Notebooks](https://ariadne.systems/pub/~sforman/Thun/notebooks/index.html)
[Jupyter Notebooks](https://joypy.osdn.io/notebooks/index.html)
that go into more detail.
**[Jupyter Notebooks](https://ariadne.systems/pub/~sforman/Thun/notebooks/index.html)**
**[Jupyter Notebooks](https://joypy.osdn.io/notebooks/index.html)**
I had a Joy kernel for the Jupyter Notebook system, but I can no longer
figure out how to use it, so I'm rewriting the notebooks by hand.
There's also a [Function Reference](https://ariadne.systems/gogs/sforman/Thun/src/trunk/docs/reference/Function-Reference.md) that lists each
There's also a [Function Reference](https://git.sr.ht/~sforman/Thun/tree/trunk/item/docs/reference) that lists each
function and combinator by name and gives a brief description. (It's
usually out of date, I'm working on it.)
**[Function Reference](https://ariadne.systems/gogs/sforman/Thun/src/trunk/docs/reference/Function-Reference.md)**
**[Function Reference](https://git.sr.ht/~sforman/Thun/tree/trunk/item/docs/reference)**
There is more in the `docs` directory but it's kind of a mess right now
(Aug 2023).
### Building the Docs
Run `make` in the `docs` directory. (This is a lie, it's more complex than
that. Really you need to run (GNU) make in the `docs/notebooks` and
`docs/reference` dirs first, _then_ run `make` in the `docs` directory.)
## Directory structure
Thun
@ -137,7 +130,7 @@ that. Really you need to run (GNU) make in the `docs/notebooks` and
Clone the repo:
git clone https://ariadne.systems/gogs/sforman/Thun.git
git clone https://git.sr.ht/~sforman/Thun
Then follow the instructions in the individual `implementations`
directories. In most cases you can just run `make` and that will build a

View File

@ -13,17 +13,15 @@ def title_of(html):
html = markdown.markdown(text, output_format="html5")
rel = '../' if 'notebooks' in filename else ''
print(f'''\
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{title_of(html)}</title>
<link rel="stylesheet" href="{rel}css/font/fonts.css">
<link rel="stylesheet" href="{rel}css/site.css">
<script src="{rel}Joy.js"></script>
<link rel="stylesheet" href="/css/font/fonts.css">
<link rel="stylesheet" href="/css/site.css">
<script src="/Joy.js"></script>
</head>
<body>
<div id="joy_interpreter"></div>

File diff suppressed because one or more lines are too long

View File

@ -3,14 +3,14 @@
<head>
<meta charset="utf-8">
<title>Thun Specification</title>
<link rel="stylesheet" href="css/font/fonts.css">
<link rel="stylesheet" href="css/site.css">
<script src="Joy.js"></script>
<link rel="stylesheet" href="/css/font/fonts.css">
<link rel="stylesheet" href="/css/site.css">
<script src="/Joy.js"></script>
</head>
<body>
<div id="joy_interpreter"></div>
<h1>Thun Specification</h1>
<p><a href="https://ariadne.systems/pub/~sforman/Thun/">Thun Version 0.5.0</a></p>
<p>Version 0.5.0</p>
<h2>Grammar</h2>
<p>The grammar of Thun is very simple. A Thun expression is zero or more
Thun terms separated by blanks. Terms can be integers in decimal
@ -125,7 +125,7 @@ of these:</p>
</ul>
<h3>Definitions</h3>
<p>Thun can be extended by adding new definitions to the
<a href="https://ariadne.systems/gogs/sforman/Thun/src/trunk/implementations/defs.txt">defs.txt</a>
<a href="https://git.sr.ht/~sforman/Thun/tree/trunk/item/implementations/defs.txt">defs.txt</a>
file and rebuilding the binaries. Each line in the file is a definition
consisting of the new symbol name followed by an expression for the body
of the function.</p>

View File

@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<title>Thun</title>
<link rel="stylesheet" href="css/font/fonts.css">
<link rel="stylesheet" href="css/site.css">
<script src="Joy.js"></script>
<link rel="stylesheet" href="/css/font/fonts.css">
<link rel="stylesheet" href="/css/site.css">
<script src="/Joy.js"></script>
</head>
<body>
<div id="joy_interpreter"></div>
@ -20,26 +20,26 @@ programming language created by Manfred von Thun that is easy to use and
understand and has many other nice properties. <strong>Thun</strong> is a dialect of
Joy that attempts to stay very close to the spirit of Joy but does not
precisely match the behaviour of the original version written in C. It
started as a Python project called "Joypy", but after someone claimed
that name on PyPI before me I renamed it to Thun in honor of Manfred Von
Thun. Now there are interpreters implemented in several additional
languages (C, Elm, Nim, OCaml, Prolog, and Scheme).</p>
started as a Python project called "Joypy", but after someone claimed that
name on PyPI before me I renamed it to Thun in honor of Manfred Von Thun.
Now there are interpreters implemented in several additional languages
(C, Nim, Prolog, Rust).</p>
<p>Joy is:</p>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Purely_functional_programming">Purely Functional</a></li>
<li><a href="https://en.wikipedia.org/wiki/Stack-oriented_programming_language">Stack-based</a></li>
<li><a href="https://en.wikipedia.org/wiki/Concatenative_programming_language">Concatinative</a>
(See also <a href="http://www.concatenative.org/wiki/view/Concatenative%20language">concatenative.org</a>)</li>
<li><a href="notebooks/Categorical.html">Categorical</a></li>
<li><a href="https://joypy.osdn.io/notebooks/Categorical.html">Categorical</a></li>
</ul>
<p>The best source for learning about Joy is the information made available
at the <a href="http://www.latrobe.edu.au/humanities/research/research-projects/past-projects/joy-programming-language">website of La Trobe University</a>
| <a href="https://www.kevinalbrecht.com/code/joy-mirror/">(mirror)</a> which
contains source code for the original C interpreter, Joy language source
code for various functions, and a great deal of fascinating material
mostly written by Von Thun on Joy and its deeper facets as well as how to
program in it and several interesting aspects. It's quite a treasure
trove.</p>
<p>The best source (no pun intended) for learning about Joy is the
information made available at the
<a href="http://www.latrobe.edu.au/humanities/research/research-projects/past-projects/joy-programming-language">website of La Trobe University</a>
| <a href="https://www.kevinalbrecht.com/code/joy-mirror/">(mirror)</a>
which contains source code for the original C interpreter, Joy language source code for various functions,
and a great deal of fascinating material mostly written by Von Thun on
Joy and its deeper facets as well as how to program in it and several
interesting aspects. It's quite a treasure trove.</p>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Joy_%28programming_language%29">Wikipedia entry for Joy</a></li>
<li><a href="http://www.latrobe.edu.au/humanities/research/research-projects/past-projects/joy-programming-language">Homepage at La Trobe University</a>
@ -51,37 +51,81 @@ trove.</p>
two integers and increments or decrements one of them such that the new
pair of numbers is the next coordinate pair in a square spiral (like the
kind used to construct an <a href="https://en.wikipedia.org/wiki/Ulam_spiral">Ulam Spiral</a>).
For more information see <a href="notebooks/Square_Spiral.html">Square Spiral Example Joy Code</a>.</p>
<pre><code>square_spiral [p] [then] [else] ifte
For more information see <a href="/notebooks/Square_Spiral.html">Square Spiral Example Joy Code</a>.</p>
<pre><code>square_spiral [_p] [_then] [_else] ifte
p [p0] [p1] and
p0 [abs] ii &lt;=
p1 [&lt;&gt;] [pop !-] or
_p [_p0] [_p1] and
_p0 [abs] ii &lt;=
_p1 [&lt;&gt;] [pop !-] or
then [ !-] [[++]] [[--]] ifte dip
else [pop !-] [--] [++] ifte
_then [ !-] [[++]] [[--]] ifte dip
_else [pop !-] [--] [++] ifte
</code></pre>
<p>It might seem unreadable but with familiarity it becomes as legible as
any other notation.</p>
<h2>Project Hosted on <a href="https://ariadne.systems/gogs/sforman/Thun">Ariadne Systems</a></h2>
<p>It might seem unreadable but with familiarity it becomes as legible as any other notation.</p>
<h2>Project Hosted on <a href="https://git.sr.ht/~sforman/Thun">SourceHut</a></h2>
<ul>
<li><a href="https://ariadne.systems/gogs/sforman/Thun">Source Repository</a>
<li><a href="https://git.sr.ht/~sforman/Thun">Source Repository</a>
(<a href="https://github.com/calroc/Thun">mirror</a>)</li>
<li><a href="https://ariadne.systems/gogs/sforman/Thun/issues">Bug tracker</a>
<li><a href="https://todo.sr.ht/~sforman/thun-der">Bug tracker</a>
(<a href="https://osdn.net/projects/joypy/ticket/">old tracker</a>)</li>
<li><a href="https://osdn.net/projects/joypy/forums/">Forums</a></li>
<li><a href="https://osdn.net/projects/joypy/lists/">Mailing list</a></li>
</ul>
<h2>Documentation</h2>
<p>The <a href="Thun.html">Thun specification</a> document describes the Thun dialect,
however most of the
documentation is in the form of <a href="notebooks/index.html">Jupyter Notebooks</a>
<p>This document describes Joy in a general way below, however most of the
documentation is in the form of <a href="/notebooks/index.html">Jupyter Notebooks</a>
that go into more detail.</p>
<p><strong><a href="notebooks/index.html">Jupyter Notebooks</a></strong></p>
<p>There's also a <a href="FuncRef.html">Function Reference</a> that lists each
<p><strong><a href="/notebooks/index.html">Jupyter Notebooks</a></strong></p>
<p>There's also a <a href="/FuncRef.html">Function Reference</a> that lists each
function and combinator by name and gives a brief description. (It's
usually out of date, I'm working on it.)</p>
<p><strong><a href="FuncRef.html">Function Reference</a></strong></p>
<p><strong><a href="/FuncRef.html">Function Reference</a></strong></p>
<h3>Building the Docs</h3>
<p>Run <code>make</code> in the <code>docs</code> directory. (This is a lie, it's more complex than
that. Really you need to run (GNU) make in the <code>docs/notebooks</code> and
<code>docs/reference</code> dirs first, <em>then</em> run <code>make</code> in the <code>docs</code> directory.)</p>
<h2>Directory structure</h2>
<pre><code>Thun
|-- LICENSE - GPLv3
|-- README.md - this file
|
|-- archive
| |-- Joy-Programming.zip
| `-- README
|
|-- docs
| |-- dep-graphs - Generated dependency graphs.
| |-- html - Generated HTML docs.
| |-- notebooks - Jupyter Notebooks and supporting modules
| `-- reference - Docs for each function.
|
|-- implementations
| |-- defs.txt - common Joy definitions for all interpreters
| |-- C - interpreter
| |-- GNUProlog - interpreter
| | type inference
| | work-in-progress compiler
| |
| |-- Nim - interpreter
| |-- Ocaml - work-in-progress interpreter
| `-- Python - interpreter
|
`-- joy_code - Source code written in Joy.
`-- bigints
`-- bigints.joy
</code></pre>
<h2>Installation</h2>
<p>Clone the repo and follow the instructions in the individual
<code>implementations</code> directories. There isn't really any installation. You
can put the binaries in your <code>PATH</code>.</p>
<p>(I had the Python package set up to upload to PyPI as "Thun", but the
whole Python distribution story seems unsettled at the moment (2023) so
I've gone back to the <em>old ways</em>: there is a single script <code>joy.py</code>
that gets modified (<code>defs.txt</code> is inserted) to create a <code>joy</code> script
that uses the "shebang" trick to pretend to be a binary. In other words,
run <code>make</code> and put the resulting <code>joy</code> script in your PATH, if that's
what you want to do. In a year or two the Python folks will have sorted
things out and we can go back to <code>pip install Thun</code> or whatever.)</p>
<h2>Basics of Joy</h2>
<p>The original Joy has several datatypes (such as strings and sets)
but the Thun dialect currently only uses four:</p>

View File

@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<title>BigNums in Joy</title>
<link rel="stylesheet" href="../css/font/fonts.css">
<link rel="stylesheet" href="../css/site.css">
<script src="../Joy.js"></script>
<link rel="stylesheet" href="/css/font/fonts.css">
<link rel="stylesheet" href="/css/site.css">
<script src="/Joy.js"></script>
</head>
<body>
<div id="joy_interpreter"></div>

View File

@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<title>Zip</title>
<link rel="stylesheet" href="../css/font/fonts.css">
<link rel="stylesheet" href="../css/site.css">
<script src="../Joy.js"></script>
<link rel="stylesheet" href="/css/font/fonts.css">
<link rel="stylesheet" href="/css/site.css">
<script src="/Joy.js"></script>
</head>
<body>
<div id="joy_interpreter"></div>

View File

@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<title>Generator Programs</title>
<link rel="stylesheet" href="../css/font/fonts.css">
<link rel="stylesheet" href="../css/site.css">
<script src="../Joy.js"></script>
<link rel="stylesheet" href="/css/font/fonts.css">
<link rel="stylesheet" href="/css/site.css">
<script src="/Joy.js"></script>
</head>
<body>
<div id="joy_interpreter"></div>

View File

@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<title>Nerd Sniped</title>
<link rel="stylesheet" href="../css/font/fonts.css">
<link rel="stylesheet" href="../css/site.css">
<script src="../Joy.js"></script>
<link rel="stylesheet" href="/css/font/fonts.css">
<link rel="stylesheet" href="/css/site.css">
<script src="/Joy.js"></script>
</head>
<body>
<div id="joy_interpreter"></div>

View File

@ -3,51 +3,51 @@
<head>
<meta charset="utf-8">
<title>Thun Notebooks</title>
<link rel="stylesheet" href="../css/font/fonts.css">
<link rel="stylesheet" href="../css/site.css">
<link rel="stylesheet" href="/css/font/fonts.css">
<link rel="stylesheet" href="/css/site.css">
</head>
<body>
<h1>Thun Notebooks</h1>
<p><a href="..">Home</a></p>
<p><a href="/">Home</a></p>
<p>Various Jupyter notebooks, some more polished than others, a few incomplete.
I'm in the process of rewriting them.</p>
<ul>
<li><a href="0._This_Implementation_of_Joy_in_Python.html">0. This Implementation of Joy in Python</a></li>
<li><a href="1._Basic_Use_of_Joy_in_a_Notebook.html">1. Basic Use of Joy in a Notebook</a></li>
<li><a href="2._Library_Examples.html">2. Library Examples</a></li>
<li><a href="3._Developing_a_Program.html">3. Developing a Program</a></li>
<li><a href="Developing_a_Program.html">Developing a Program</a></li>
<li><a href="Advent_of_Code_2017_December_1st.html">Advent of Code 2017 December 1st</a></li>
<li><a href="Advent_of_Code_2017_December_2nd.html">Advent of Code 2017 December 2nd</a></li>
<li><a href="Advent_of_Code_2017_December_3rd.html">Advent of Code 2017 December 3rd</a></li>
<li><a href="Advent_of_Code_2017_December_4th.html">Advent of Code 2017 December 4th</a></li>
<li><a href="Advent_of_Code_2017_December_5th.html">Advent of Code 2017 December 5th</a></li>
<li><a href="Advent_of_Code_2017_December_6th.html">Advent of Code 2017 December 6th</a></li>
<li><a href="BigInts.html">BigNums</a></li>
<li><a href="Compiling_Joy.html">Compiling Joy</a></li>
<li><a href="Correcet_Programming.html">Correcet Programming</a></li>
<li><a href="Derivatives_of_Regular_Expressions.html">Derivatives of Regular Expressions</a></li>
<li><a href="Generator_Programs.html">Generator Programs</a></li>
<li><a href="Hylo-,_Ana-,_Cata-,_and_Para-morphisms_-_Recursion_Combinators.html">Hylo-, Ana-, Cata-, and Para-morphisms - Recursion Combinators</a></li>
<li><a href="Intro-to-Joy.html">Intro-to-Joy</a></li>
<li><a href="Joy-in-Jupyter.html">Joy-in-Jupyter</a></li>
<li><a href="Multiples-of-3-and-5.html">Multiples-of-3-and-5</a></li>
<li><a href="NeoAero.html">NeoAero</a></li>
<li><a href="Newton-Raphson.html">Newton-Raphson</a></li>
<li><a href="Ordered_Binary_Trees.html">Ordered Binary Trees</a></li>
<li><a href="Quadratic.html">Quadratic</a></li>
<li><a href="Recursion_Combinators.html">Recursion Combinators</a></li>
<li><a href="Remove-Function.html">Remove-Function</a></li>
<li><a href="Replacing.html">Replacing</a></li>
<li><a href="Square_Spiral.html">Square Spiral</a></li>
<li><a href="The_Four_Operations.html">The Four Operations</a></li>
<li><a href="Trees.html">Trees</a></li>
<li><a href="Treestep.html">Treestep</a></li>
<li><a href="TypeChecking.html">TypeChecking</a></li>
<li><a href="Types.html">Types</a></li>
<li><a href="Zipper.html">Zipper</a></li>
<li><a href="fun_with_scan.html">fun with scan</a></li>
<li><a href="with_sympy.html">with sympy</a></li>
<li><a href="/notebooks/0._This_Implementation_of_Joy_in_Python.html">0. This Implementation of Joy in Python</a></li>
<li><a href="/notebooks/1._Basic_Use_of_Joy_in_a_Notebook.html">1. Basic Use of Joy in a Notebook</a></li>
<li><a href="/notebooks/2._Library_Examples.html">2. Library Examples</a></li>
<li><a href="/notebooks/3._Developing_a_Program.html">3. Developing a Program</a></li>
<li><a href="/notebooks/Developing_a_Program.html">Developing a Program</a></li>
<li><a href="/notebooks/Advent_of_Code_2017_December_1st.html">Advent of Code 2017 December 1st</a></li>
<li><a href="/notebooks/Advent_of_Code_2017_December_2nd.html">Advent of Code 2017 December 2nd</a></li>
<li><a href="/notebooks/Advent_of_Code_2017_December_3rd.html">Advent of Code 2017 December 3rd</a></li>
<li><a href="/notebooks/Advent_of_Code_2017_December_4th.html">Advent of Code 2017 December 4th</a></li>
<li><a href="/notebooks/Advent_of_Code_2017_December_5th.html">Advent of Code 2017 December 5th</a></li>
<li><a href="/notebooks/Advent_of_Code_2017_December_6th.html">Advent of Code 2017 December 6th</a></li>
<li><a href="/notebooks/BigInts.html">BigNums</a></li>
<li><a href="/notebooks/Compiling_Joy.html">Compiling Joy</a></li>
<li><a href="/notebooks/Correcet_Programming.html">Correcet Programming</a></li>
<li><a href="/notebooks/Derivatives_of_Regular_Expressions.html">Derivatives of Regular Expressions</a></li>
<li><a href="/notebooks/Generator_Programs.html">Generator Programs</a></li>
<li><a href="/notebooks/Hylo-,_Ana-,_Cata-,_and_Para-morphisms_-_Recursion_Combinators.html">Hylo-, Ana-, Cata-, and Para-morphisms - Recursion Combinators</a></li>
<li><a href="/notebooks/Intro-to-Joy.html">Intro-to-Joy</a></li>
<li><a href="/notebooks/Joy-in-Jupyter.html">Joy-in-Jupyter</a></li>
<li><a href="/notebooks/Multiples-of-3-and-5.html">Multiples-of-3-and-5</a></li>
<li><a href="/notebooks/NeoAero.html">NeoAero</a></li>
<li><a href="/notebooks/Newton-Raphson.html">Newton-Raphson</a></li>
<li><a href="/notebooks/Ordered_Binary_Trees.html">Ordered Binary Trees</a></li>
<li><a href="/notebooks/Quadratic.html">Quadratic</a></li>
<li><a href="/notebooks/Recursion_Combinators.html">Recursion Combinators</a></li>
<li><a href="/notebooks/Remove-Function.html">Remove-Function</a></li>
<li><a href="/notebooks/Replacing.html">Replacing</a></li>
<li><a href="/notebooks/Square_Spiral.html">Square Spiral</a></li>
<li><a href="/notebooks/The_Four_Operations.html">The Four Operations</a></li>
<li><a href="/notebooks/Trees.html">Trees</a></li>
<li><a href="/notebooks/Treestep.html">Treestep</a></li>
<li><a href="/notebooks/TypeChecking.html">TypeChecking</a></li>
<li><a href="/notebooks/Types.html">Types</a></li>
<li><a href="/notebooks/Zipper.html">Zipper</a></li>
<li><a href="/notebooks/fun_with_scan.html">fun with scan</a></li>
<li><a href="/notebooks/with_sympy.html">with sympy</a></li>
</ul>
</body>
</html>

View File

@ -583,6 +583,7 @@ Concatinate two lists.
[flatten]
[fourth]
[getitem]
[remove]
[rest]
[reverse]
[rrest]
@ -590,6 +591,7 @@ Concatinate two lists.
[shift]
[shunt]
[size]
[sort]
[split_at]
[split_list]
[swaack]
@ -1097,6 +1099,7 @@ Note that only one "level" of lists is flattened. In the example above
[first_two]
[fourth]
[getitem]
[remove]
[rest]
[reverse]
[rrest]
@ -1104,6 +1107,7 @@ Note that only one "level" of lists is flattened. In the example above
[shift]
[shunt]
[size]
[sort]
[split_at]
[split_list]
[swaack]
@ -1279,6 +1283,7 @@ implementation-dependant.)
[first_two]
[flatten]
[fourth]
[remove]
[rest]
[reverse]
[rrest]
@ -1286,6 +1291,7 @@ implementation-dependant.)
[shift]
[shunt]
[size]
[sort]
[split_at]
[split_list]
[swaack]
@ -1368,6 +1374,22 @@ Greater-than comparison of two numbers.
------------------------------------------------------------------------
## help
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.
--------------
## --
See [pred](#pred).
@ -1380,6 +1402,16 @@ See [pred](#pred).
See [sub](#sub).
------------------------------------------------------------------------
## id
The identity function.
### Discussion
Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy.
------------------------------------------------------------------------
## ifte
@ -2306,7 +2338,6 @@ This comes from the original Joy stuff.
### Crosslinks
[quote-two]
[unit]
@ -2389,6 +2420,23 @@ See [mod](#mod).
See [mod](#mod).
------------------------------------------------------------------------
## remove
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).
------------------------------------------------------------------------
## rest
@ -2622,6 +2670,19 @@ and an error if it is not a list.
[null]
------------------------------------------------------------------------
## sort
Given a list return it sorted.
### Example
[4 2 5 7 1] sort
----------------------
[1 2 4 5 7]
------------------------------------------------------------------------
## spiral_next
@ -2793,6 +2854,23 @@ Take the [stack] and [uncons] the top item.
--------------------
1 2 3 3 [2 1]
------------------------------------------------------------------------
## stununcons
Take the [stack] and [uncons] the top two items.
### Example
1 2 3 stununcons
----------------------
1 2 3 3 2 [1]
### Crosslinks
[stuncons]
------------------------------------------------------------------------
## sub
@ -3092,6 +3170,13 @@ This is the inverse of [cons].
[cons]
------------------------------------------------------------------------
## unique
Given a list remove duplicate items.
------------------------------------------------------------------------
## unit
@ -3174,6 +3259,19 @@ stack.) The quoted programs are run with [nullary].
[and]
------------------------------------------------------------------------
## void
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/)
------------------------------------------------------------------------
## warranty
@ -3201,6 +3299,22 @@ and runs it [nullary].
[loop]
------------------------------------------------------------------------
## words
Print all the words in alphabetical order.
### Discussion
Mathematically this is a form of [id].
### Crosslinks
[help]
--------------------
## x
@ -3235,74 +3349,3 @@ from each list. The smallest list sets the length of the result list.
-------------------------
[[1 4] [2 5] [3 6]]
------------------------------------------------------------------------
## empty?
Expects a list on the stack and pushes `true` if it's empty and `false` otherwise.
It doesn't consume the list.
### Crosslinks
[null]
------------------------------------------------------------------------
## max-of-two
Expects two integers on the stack and removes the lesser of them, if they are equal just remove one.
------------------------------------------------------------------------
## min-of-two
Expects two integers on the stack and removes the greater of them, if they are equal just remove one.
------------------------------------------------------------------------
## quote-two
Take two items from the stack and put them into a new list.
joy? 1 2 3 4
1 2 3 4
joy? quote-two
1 2 [3 4]
### Crosslinks
[quoted]
------------------------------------------------------------------------
## uncons-two
Expect two non-empty lists on the stack and `uncons` the first item from each.
joy? [1 2] [3 4] uncons-two
1 3 [2] [4]
------------------------------------------------------------------------
## uncons-pair
Expect two non-empty lists on the stack and `uncons` the first item from each and put them in a new list.
joy? [1 2] [3 4] uncons-pair
[1 3] [2] [4]

View File

@ -32,13 +32,13 @@ def symbols_of(expression):
return
used_in = {
name: sorted(set(symbols_of(joy.text_to_expression(def_str))))
for name, def_str in definitions.items()
name: sorted(set(symbols_of(joy.text_to_expression(definitions[name]))))
for name in definitions
}
used_by = defaultdict(list)
for name, syms in used_in.items():
for term in syms:
for name in used_in:
for term in used_in[name]:
used_by[term].append(name)
for el in used_by.values():
el.sort()
@ -71,13 +71,9 @@ gt lt ge le neq eq
<< >>
lshift rshift'''.split())
# Split the file into chunks at the Horizontal Rules.
k = re.split('^-+$', md, flags=re.MULTILINE)
#k = md.split('------------------------------------------------------------------------\n')
del k[0]
k = [section.splitlines() for section in k]
##s = set(range(len(k)))
@ -108,7 +104,7 @@ for section in k:
combinators = set(
name
for name, section in sections.items()
for (name, section) in sections.items()
if 'Combinator' in section
)
for name in combinators:

View File

@ -1,6 +1,6 @@
# Thun Specification
[Thun Version 0.5.0](https://ariadne.systems/pub/~sforman/Thun/)
Version 0.5.0
## Grammar
@ -150,7 +150,7 @@ of these:
### Definitions
Thun can be extended by adding new definitions to the
[defs.txt](https://ariadne.systems/gogs/sforman/Thun/src/trunk/implementations/defs.txt)
[defs.txt](https://git.sr.ht/~sforman/Thun/tree/trunk/item/implementations/defs.txt)
file and rebuilding the binaries. Each line in the file is a definition
consisting of the new symbol name followed by an expression for the body
of the function.

View File

@ -11,10 +11,10 @@ programming language created by Manfred von Thun that is easy to use and
understand and has many other nice properties. **Thun** is a dialect of
Joy that attempts to stay very close to the spirit of Joy but does not
precisely match the behaviour of the original version written in C. It
started as a Python project called "Joypy", but after someone claimed
that name on PyPI before me I renamed it to Thun in honor of Manfred Von
Thun. Now there are interpreters implemented in several additional
languages (C, Elm, Nim, OCaml, Prolog, and Scheme).
started as a Python project called "Joypy", but after someone claimed that
name on PyPI before me I renamed it to Thun in honor of Manfred Von Thun.
Now there are interpreters implemented in several additional languages
(C, Nim, Prolog, Rust).
Joy is:
@ -22,16 +22,16 @@ Joy is:
* [Stack-based](https://en.wikipedia.org/wiki/Stack-oriented_programming_language)
* [Concatinative](https://en.wikipedia.org/wiki/Concatenative_programming_language)
(See also [concatenative.org](http://www.concatenative.org/wiki/view/Concatenative%20language))
* [Categorical](notebooks/Categorical.html)
* [Categorical](https://joypy.osdn.io/notebooks/Categorical.html)
The best source for learning about Joy is the information made available
at the [website of La Trobe University](http://www.latrobe.edu.au/humanities/research/research-projects/past-projects/joy-programming-language)
| [(mirror)](https://www.kevinalbrecht.com/code/joy-mirror/) which
contains source code for the original C interpreter, Joy language source
code for various functions, and a great deal of fascinating material
mostly written by Von Thun on Joy and its deeper facets as well as how to
program in it and several interesting aspects. It's quite a treasure
trove.
The best source (no pun intended) for learning about Joy is the
information made available at the
[website of La Trobe University](http://www.latrobe.edu.au/humanities/research/research-projects/past-projects/joy-programming-language)
| [(mirror)](https://www.kevinalbrecht.com/code/joy-mirror/)
which contains source code for the original C interpreter, Joy language source code for various functions,
and a great deal of fascinating material mostly written by Von Thun on
Joy and its deeper facets as well as how to program in it and several
interesting aspects. It's quite a treasure trove.
* [Wikipedia entry for Joy](https://en.wikipedia.org/wiki/Joy_%28programming_language%29)
* [Homepage at La Trobe University](http://www.latrobe.edu.au/humanities/research/research-projects/past-projects/joy-programming-language)
@ -45,26 +45,25 @@ Here is an example of Joy code. This function `square_spiral` accepts
two integers and increments or decrements one of them such that the new
pair of numbers is the next coordinate pair in a square spiral (like the
kind used to construct an [Ulam Spiral](https://en.wikipedia.org/wiki/Ulam_spiral)).
For more information see [Square Spiral Example Joy Code](notebooks/Square_Spiral.html).
For more information see [Square Spiral Example Joy Code](/notebooks/Square_Spiral.html).
square_spiral [p] [then] [else] ifte
square_spiral [_p] [_then] [_else] ifte
p [p0] [p1] and
p0 [abs] ii <=
p1 [<>] [pop !-] or
_p [_p0] [_p1] and
_p0 [abs] ii <=
_p1 [<>] [pop !-] or
then [ !-] [[++]] [[--]] ifte dip
else [pop !-] [--] [++] ifte
_then [ !-] [[++]] [[--]] ifte dip
_else [pop !-] [--] [++] ifte
It might seem unreadable but with familiarity it becomes as legible as
any other notation.
It might seem unreadable but with familiarity it becomes as legible as any other notation.
## Project Hosted on [Ariadne Systems](https://ariadne.systems/gogs/sforman/Thun)
## Project Hosted on [SourceHut](https://git.sr.ht/~sforman/Thun)
* [Source Repository](https://ariadne.systems/gogs/sforman/Thun)
* [Source Repository](https://git.sr.ht/~sforman/Thun)
([mirror](https://github.com/calroc/Thun))
* [Bug tracker](https://ariadne.systems/gogs/sforman/Thun/issues)
* [Bug tracker](https://todo.sr.ht/~sforman/thun-der)
([old tracker](https://osdn.net/projects/joypy/ticket/))
* [Forums](https://osdn.net/projects/joypy/forums/)
* [Mailing list](https://osdn.net/projects/joypy/lists/)
@ -72,19 +71,73 @@ any other notation.
## Documentation
The [Thun specification](Thun.html) document describes the Thun dialect,
however most of the
documentation is in the form of [Jupyter Notebooks](notebooks/index.html)
This document describes Joy in a general way below, however most of the
documentation is in the form of [Jupyter Notebooks](/notebooks/index.html)
that go into more detail.
**[Jupyter Notebooks](notebooks/index.html)**
**[Jupyter Notebooks](/notebooks/index.html)**
There's also a [Function Reference](FuncRef.html) that lists each
There's also a [Function Reference](/FuncRef.html) that lists each
function and combinator by name and gives a brief description. (It's
usually out of date, I'm working on it.)
**[Function Reference](FuncRef.html)**
**[Function Reference](/FuncRef.html)**
### Building the Docs
Run `make` in the `docs` directory. (This is a lie, it's more complex than
that. Really you need to run (GNU) make in the `docs/notebooks` and
`docs/reference` dirs first, _then_ run `make` in the `docs` directory.)
## Directory structure
Thun
|-- LICENSE - GPLv3
|-- README.md - this file
|
|-- archive
| |-- Joy-Programming.zip
| `-- README
|
|-- docs
| |-- dep-graphs - Generated dependency graphs.
| |-- html - Generated HTML docs.
| |-- notebooks - Jupyter Notebooks and supporting modules
| `-- reference - Docs for each function.
|
|-- implementations
| |-- defs.txt - common Joy definitions for all interpreters
| |-- C - interpreter
| |-- GNUProlog - interpreter
| | type inference
| | work-in-progress compiler
| |
| |-- Nim - interpreter
| |-- Ocaml - work-in-progress interpreter
| `-- Python - interpreter
|
`-- joy_code - Source code written in Joy.
`-- bigints
`-- bigints.joy
## Installation
Clone the repo and follow the instructions in the individual
`implementations` directories. There isn't really any installation. You
can put the binaries in your ``PATH``.
(I had the Python package set up to upload to PyPI as "Thun", but the
whole Python distribution story seems unsettled at the moment (2023) so
I've gone back to the *old ways*: there is a single script ``joy.py``
that gets modified (``defs.txt`` is inserted) to create a ``joy`` script
that uses the "shebang" trick to pretend to be a binary. In other words,
run ``make`` and put the resulting ``joy`` script in your PATH, if that's
what you want to do. In a year or two the Python folks will have sorted
things out and we can go back to ``pip install Thun`` or whatever.)
## Basics of Joy

View File

@ -143,7 +143,6 @@ run, def_run
second, def_second
shift, def_shift
shunt, def_shunt
select, def_select
size, def_size
small, def_small
spiral_next, def_spiral_next

View File

@ -7,7 +7,7 @@ CFLAGS = -ansi -Wall -Wextra -Werror -pedantic -Wstrict-overflow -fno-strict-ali
CFLAGS += -I/usr/local/include
# TODO: move these to KEYWORDS.in.
# TODO: move these to KEYWORDS.txt.
GPERF_OPTS = --readonly-tables --enum --includes --hash-function-name=keyword_hash
#--global-table

View File

@ -36,7 +36,6 @@ first
lshift
rshift
mod
stack
rest'''.splitlines()

View File

@ -106,7 +106,6 @@ JoyList def_run_body;
JoyList def_second_body;
JoyList def_shift_body;
JoyList def_shunt_body;
JoyList def_select_body;
JoyList def_size_body;
JoyList def_small_body;
JoyList def_spiral_next_body;
@ -216,7 +215,7 @@ init_defs(void)
def_dupd_body = text_to_expression("[dup] dip");
def_dupdipd_body = text_to_expression("dup dipd");
def_dupdip_body = text_to_expression("dupd dip");
def_enstacken_body = text_to_expression("[] swaack");
def_enstacken_body = text_to_expression("stack [clear] dip");
def_first_two_body = text_to_expression("uncons first");
def_flatten_body = text_to_expression("<{} [concat] step");
def_fork_body = text_to_expression("[i] app2");
@ -268,9 +267,8 @@ init_defs(void)
def_second_body = text_to_expression("rest first");
def_shift_body = text_to_expression("uncons [swons] dip");
def_shunt_body = text_to_expression("[swons] step");
def_select_body = text_to_expression("[first] [second] branch");
def_size_body = text_to_expression("[pop ++] step_zero");
def_small_body = text_to_expression("empty? [rest null] [pop true] branch");
def_small_body = text_to_expression("dup null [rest null] [pop true] branch");
def_spiral_next_body = text_to_expression("[[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte");
def_split_at_body = text_to_expression("[drop] [take] clop");
def_split_list_body = text_to_expression("[take reverse] [drop] clop");
@ -292,7 +290,7 @@ init_defs(void)
def_uncons_body = text_to_expression("[first] dupdip rest");
def_unit_body = text_to_expression("[] cons");
def_unquoted_body = text_to_expression("[i] dip");
def_unstack_body = text_to_expression("[enstacken] dip swoncat swaack pop");
def_unstack_body = text_to_expression("[[] swaack] dip swoncat swaack pop");
def_unswons_body = text_to_expression("uncons swap");
def_while_body = text_to_expression("swap nulco dupdipd concat loop");
def_x_body = text_to_expression("dup i");
@ -427,7 +425,6 @@ void def_run(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) {
void def_second(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_second_body, expression); }
void def_shift(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_shift_body, expression); }
void def_shunt(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_shunt_body, expression); }
void def_select(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_select_body, expression); }
void def_size(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_size_body, expression); }
void def_small(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_small_body, expression); }
void def_spiral_next(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_spiral_next_body, expression); }

View File

@ -97,7 +97,6 @@ void def_run(JoyListPtr stack, JoyListPtr expression);
void def_second(JoyListPtr stack, JoyListPtr expression);
void def_shift(JoyListPtr stack, JoyListPtr expression);
void def_shunt(JoyListPtr stack, JoyListPtr expression);
void def_select(JoyListPtr stack, JoyListPtr expression);
void def_size(JoyListPtr stack, JoyListPtr expression);
void def_small(JoyListPtr stack, JoyListPtr expression);
void def_spiral_next(JoyListPtr stack, JoyListPtr expression);

View File

@ -24,7 +24,7 @@ binary unary popd
ccccons ccons ccons
ccons cons cons
choice [pop] [popd] branch
clear enstacken pop
clear [] swaack pop
cleave fork popdd
clop cleave popdd
cmp [[>] swap] dipd [ifte] ccons [=] swons ifte
@ -42,7 +42,7 @@ dupdd [dup] dipd
dupd [dup] dip
dupdipd dup dipd
dupdip dupd dip
enstacken [] swaack
enstacken stack [clear] dip
first uncons pop
first_two uncons first
flatten <{} [concat] step
@ -99,14 +99,12 @@ run <{} infra
second rest first
shift uncons [swons] dip
shunt [swons] step
select [first] [second] branch
size [pop ++] step_zero
small empty? [rest null] [pop true] branch
small dup null [rest null] [pop true] branch
spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte
split_at [drop] [take] clop
split_list [take reverse] [drop] clop
sqr dup mul
stack enstacken dup cons swaack pop
stackd [stack] dip
step_zero 0 roll> step
stuncons stack uncons
@ -124,7 +122,7 @@ unary nullary popd
uncons [first] dupdip rest
unit [] cons
unquoted [i] dip
unstack [enstacken] dip swoncat swaack pop
unstack [[] swaack] dip swoncat swaack pop
unswons uncons swap
while swap nulco dupdipd concat loop
x dup i

View File

@ -36,7 +36,7 @@
#line 13 "KEYWORDS.txt"
struct dict_entry;
#include <string.h>
/* maximum key range = 422, duplicates = 0 */
/* maximum key range = 365, duplicates = 0 */
#ifdef __GNUC__
__inline
@ -50,32 +50,32 @@ keyword_hash (register const char *str, register size_t len)
{
static const unsigned short asso_values[] =
{
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 20, 423, 423, 423, 65, 423, 423,
423, 423, 55, 80, 423, 135, 423, 15, 25, 10,
5, 25, 423, 423, 423, 423, 423, 423, 423, 423,
140, 90, 35, 50, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 0, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 5, 423, 423, 100, 423, 85, 95, 15,
5, 60, 45, 125, 0, 0, 423, 115, 60, 115,
0, 0, 0, 150, 75, 0, 40, 15, 25, 115,
10, 95, 10, 5, 423, 0, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423, 423, 423, 423, 423,
423, 423, 423, 423, 423, 423
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 50, 366, 366, 366, 95, 366, 366,
366, 366, 50, 45, 366, 85, 366, 20, 95, 85,
35, 50, 366, 366, 366, 366, 366, 366, 366, 366,
75, 115, 15, 55, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 15, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 80, 366, 366, 75, 366, 105, 70, 15,
5, 30, 35, 115, 20, 0, 366, 95, 65, 85,
0, 0, 0, 110, 55, 0, 40, 15, 30, 45,
10, 105, 10, 30, 366, 0, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366
};
register unsigned int hval = len;
@ -99,11 +99,11 @@ in_word_set (register const char *str, register size_t len)
{
enum
{
TOTAL_KEYWORDS = 189,
TOTAL_KEYWORDS = 188,
MIN_WORD_LENGTH = 1,
MAX_WORD_LENGTH = 17,
MIN_HASH_VALUE = 1,
MAX_HASH_VALUE = 422
MAX_HASH_VALUE = 365
};
static const struct dict_entry wordlist[] =
@ -131,7 +131,7 @@ in_word_set (register const char *str, register size_t len)
{"popopd", def_popopd},
#line 124 "KEYWORDS.txt"
{"popopdd", def_popopdd},
#line 194 "KEYWORDS.txt"
#line 193 "KEYWORDS.txt"
{"zip", def_zip},
#line 83 "KEYWORDS.txt"
{"dipd", def_dipd},
@ -145,9 +145,9 @@ in_word_set (register const char *str, register size_t len)
#line 38 "KEYWORDS.txt"
{"cons", cons},
{""},
#line 173 "KEYWORDS.txt"
#line 172 "KEYWORDS.txt"
{"x", def_x},
#line 171 "KEYWORDS.txt"
#line 170 "KEYWORDS.txt"
{"unswons", def_unswons},
#line 41 "KEYWORDS.txt"
{"dup", dup},
@ -156,426 +156,404 @@ in_word_set (register const char *str, register size_t len)
{""},
#line 93 "KEYWORDS.txt"
{"dupdip", def_dupdip},
#line 191 "KEYWORDS.txt"
{"/\\", def_SOLIDUS_REVERSE_SOLIDUS},
{""},
#line 81 "KEYWORDS.txt"
{"codireco", def_codireco},
#line 91 "KEYWORDS.txt"
{"dupd", def_dupd},
#line 90 "KEYWORDS.txt"
{"dupdd", def_dupdd},
#line 30 "KEYWORDS.txt"
{"/", fdiv_q},
#line 16 "KEYWORDS.txt"
{">", def_gt},
#line 92 "KEYWORDS.txt"
{"dupdipd", def_dupdipd},
{""}, {""},
#line 76 "KEYWORDS.txt"
{"ccons", def_ccons},
#line 167 "KEYWORDS.txt"
#line 166 "KEYWORDS.txt"
{"uncons", def_uncons},
#line 192 "KEYWORDS.txt"
{"\\/", def_REVERSE_SOLIDUS_SOLIDUS},
{""}, {""},
#line 196 "KEYWORDS.txt"
{"uncons-two", def_uncons_HYPHEN_MINUS_two},
#line 87 "KEYWORDS.txt"
{"divmod", def_divmod},
{""}, {""}, {""},
#line 144 "KEYWORDS.txt"
{"shift", def_shift},
{""},
#line 51 "KEYWORDS.txt"
{"fn", fn},
#line 44 "KEYWORDS.txt"
{"inscribe", inscribe},
#line 94 "KEYWORDS.txt"
{"enstacken", def_enstacken},
#line 195 "KEYWORDS.txt"
{"uncons-two", def_uncons_HYPHEN_MINUS_two},
#line 30 "KEYWORDS.txt"
{"/", fdiv_q},
{""}, {""},
#line 146 "KEYWORDS.txt"
{"size", def_size},
{""},
#line 156 "KEYWORDS.txt"
#line 87 "KEYWORDS.txt"
{"divmod", def_divmod},
#line 141 "KEYWORDS.txt"
{">>", def_GREATER_THAN_SIGN_GREATER_THAN_SIGN},
{""},
#line 155 "KEYWORDS.txt"
{"succ", def_succ},
#line 164 "KEYWORDS.txt"
{"third", def_third},
#line 149 "KEYWORDS.txt"
#line 159 "KEYWORDS.txt"
{"swons", def_swons},
#line 148 "KEYWORDS.txt"
{"spiral_next", def_spiral_next},
#line 75 "KEYWORDS.txt"
{"ccccons", def_ccccons},
{""},
#line 82 "KEYWORDS.txt"
{"dinfrirst", def_dinfrirst},
{""}, {""}, {""},
#line 31 "KEYWORDS.txt"
{"div", fdiv_q},
#line 168 "KEYWORDS.txt"
{"unit", def_unit},
#line 145 "KEYWORDS.txt"
{"shunt", def_shunt},
#line 39 "KEYWORDS.txt"
{"concat", concat},
{""},
#line 155 "KEYWORDS.txt"
{"stuncons", def_stuncons},
#line 45 "KEYWORDS.txt"
{"loop", loop},
{""},
#line 98 "KEYWORDS.txt"
{"fourth", def_fourth},
{""},
#line 44 "KEYWORDS.txt"
{"inscribe", inscribe},
#line 94 "KEYWORDS.txt"
{"enstacken", def_enstacken},
{""},
#line 16 "KEYWORDS.txt"
{">", def_gt},
{""}, {""},
#line 147 "KEYWORDS.txt"
{"size", def_size},
{""}, {""}, {""}, {""},
#line 79 "KEYWORDS.txt"
{"clop", def_clop},
#line 113 "KEYWORDS.txt"
{"nulco", def_nulco},
#line 77 "KEYWORDS.txt"
{"choice", def_choice},
{""},
#line 112 "KEYWORDS.txt"
{"not", def_not},
#line 89 "KEYWORDS.txt"
{"drop", def_drop},
{""},
#line 143 "KEYWORDS.txt"
{"second", def_second},
{""}, {""},
#line 70 "KEYWORDS.txt"
{"appN", def_appN},
#line 167 "KEYWORDS.txt"
{"unit", def_unit},
{""},
#line 107 "KEYWORDS.txt"
{"infrst", def_infrst},
#line 39 "KEYWORDS.txt"
{"concat", concat},
#line 88 "KEYWORDS.txt"
{"down_to_zero", def_down_to_zero},
#line 154 "KEYWORDS.txt"
{"stuncons", def_stuncons},
#line 89 "KEYWORDS.txt"
{"drop", def_drop},
#line 144 "KEYWORDS.txt"
{"shift", def_shift},
{""}, {""},
#line 31 "KEYWORDS.txt"
{"div", fdiv_q},
#line 45 "KEYWORDS.txt"
{"loop", loop},
#line 163 "KEYWORDS.txt"
{"third", def_third},
#line 77 "KEYWORDS.txt"
{"choice", def_choice},
#line 116 "KEYWORDS.txt"
{"of", def_of},
#line 142 "KEYWORDS.txt"
{"run", def_run},
#line 68 "KEYWORDS.txt"
{"app2", def_app2},
{""}, {""}, {""},
#line 66 "KEYWORDS.txt"
{"and", def_and},
#line 67 "KEYWORDS.txt"
{"app1", def_app1},
{""},
#line 58 "KEYWORDS.txt"
{"?", def_QUESTION_MARK},
{""},
#line 27 "KEYWORDS.txt"
{"add", add},
#line 174 "KEYWORDS.txt"
#line 173 "KEYWORDS.txt"
{"step", def_step},
{""},
#line 32 "KEYWORDS.txt"
{"lshift", lshift},
#line 141 "KEYWORDS.txt"
{">>", def_GREATER_THAN_SIGN_GREATER_THAN_SIGN},
#line 150 "KEYWORDS.txt"
{"split_at", def_split_at},
#line 154 "KEYWORDS.txt"
{"step_zero", def_step_zero},
#line 151 "KEYWORDS.txt"
{"split_list", def_split_list},
#line 24 "KEYWORDS.txt"
{"*", mul},
#line 98 "KEYWORDS.txt"
{"fourth", def_fourth},
{""}, {""},
#line 69 "KEYWORDS.txt"
{"app3", def_app3},
#line 189 "KEYWORDS.txt"
{"_isnt_two_bools", def__isnt_two_bools},
#line 195 "KEYWORDS.txt"
{"uncons-pair", def_uncons_HYPHEN_MINUS_pair},
#line 153 "KEYWORDS.txt"
{"step_zero", def_step_zero},
#line 145 "KEYWORDS.txt"
{"shunt", def_shunt},
#line 107 "KEYWORDS.txt"
{"infrst", def_infrst},
{""},
#line 202 "KEYWORDS.txt"
{"min", def_min},
{""},
#line 160 "KEYWORDS.txt"
{"swons", def_swons},
#line 33 "KEYWORDS.txt"
{"rshift", rshift},
#line 130 "KEYWORDS.txt"
{"product", def_product},
#line 112 "KEYWORDS.txt"
{"not", def_not},
#line 79 "KEYWORDS.txt"
{"clop", def_clop},
#line 113 "KEYWORDS.txt"
{"nulco", def_nulco},
{""}, {""},
#line 201 "KEYWORDS.txt"
{"min-of-two", def_min_HYPHEN_MINUS_of_HYPHEN_MINUS_two},
{"min", def_min},
{""},
#line 188 "KEYWORDS.txt"
{"_isnt_two_bools", def__isnt_two_bools},
#line 26 "KEYWORDS.txt"
{"+", add},
#line 158 "KEYWORDS.txt"
{"swoncat", def_swoncat},
#line 128 "KEYWORDS.txt"
{"pow", def_pow},
#line 129 "KEYWORDS.txt"
{"pred", def_pred},
#line 200 "KEYWORDS.txt"
{"min-of-two", def_min_HYPHEN_MINUS_of_HYPHEN_MINUS_two},
#line 194 "KEYWORDS.txt"
{"uncons-pair", def_uncons_HYPHEN_MINUS_pair},
#line 110 "KEYWORDS.txt"
{"modulus", def_modulus},
#line 23 "KEYWORDS.txt"
{"mod", fdiv_r},
#line 95 "KEYWORDS.txt"
{"first_two", def_first_two},
{""},
#line 22 "KEYWORDS.txt"
{"%", fdiv_r},
#line 88 "KEYWORDS.txt"
{"down_to_zero", def_down_to_zero},
#line 171 "KEYWORDS.txt"
{"while", def_while},
#line 24 "KEYWORDS.txt"
{"*", mul},
#line 130 "KEYWORDS.txt"
{"product", def_product},
#line 37 "KEYWORDS.txt"
{"cmp", cmp_joyfunc},
#line 120 "KEYWORDS.txt"
{"pick", def_pick},
#line 106 "KEYWORDS.txt"
{"infra", def_infra},
#line 153 "KEYWORDS.txt"
{"stackd", def_stackd},
#line 170 "KEYWORDS.txt"
{"unstack", def_unstack},
{""},
#line 115 "KEYWORDS.txt"
{"null", def_null},
{""},
#line 139 "KEYWORDS.txt"
{"rollup", def_rollup},
#line 54 "KEYWORDS.txt"
{"lt", def_lt},
#line 136 "KEYWORDS.txt"
{"rolldown", def_rolldown},
#line 129 "KEYWORDS.txt"
{"pred", def_pred},
#line 134 "KEYWORDS.txt"
{"reco", def_reco},
{""}, {""},
#line 161 "KEYWORDS.txt"
{"tailrec", def_tailrec},
#line 19 "KEYWORDS.txt"
{"<>", def_neq},
#line 62 "KEYWORDS.txt"
{"<{}", def_LESS_THAN_SIGN_LEFT_CURLY_BRACKET_RIGHT_CURLY_BRACKET},
#line 104 "KEYWORDS.txt"
{"ifte", def_ifte},
#line 193 "KEYWORDS.txt"
{"_isnt_list", def__isnt_list},
{""},
#line 58 "KEYWORDS.txt"
{"?", def_QUESTION_MARK},
#line 117 "KEYWORDS.txt"
{"or", def_or},
#line 99 "KEYWORDS.txt"
{"gcd", def_gcd},
#line 134 "KEYWORDS.txt"
{"reco", def_reco},
{""},
#line 176 "KEYWORDS.txt"
{"_step1", def__step1},
#line 180 "KEYWORDS.txt"
{"_times1", def__times1},
{""},
#line 34 "KEYWORDS.txt"
{"bool", truthy},
#line 178 "KEYWORDS.txt"
{"times", def_times},
#line 26 "KEYWORDS.txt"
{"+", add},
#line 159 "KEYWORDS.txt"
{"swoncat", def_swoncat},
#line 149 "KEYWORDS.txt"
{"split_at", def_split_at},
#line 120 "KEYWORDS.txt"
{"pick", def_pick},
#line 150 "KEYWORDS.txt"
{"split_list", def_split_list},
{""},
#line 169 "KEYWORDS.txt"
{"unstack", def_unstack},
#line 66 "KEYWORDS.txt"
{"and", def_and},
#line 118 "KEYWORDS.txt"
{"over", def_over},
#line 42 "KEYWORDS.txt"
{"first", first},
#line 146 "KEYWORDS.txt"
{"select", def_select},
#line 71 "KEYWORDS.txt"
{"at", def_at},
{""}, {""},
#line 188 "KEYWORDS.txt"
{"_isnt_bool", def__isnt_bool},
#line 175 "KEYWORDS.txt"
{"_step0", def__step0},
#line 179 "KEYWORDS.txt"
{"_times0", def__times0},
#line 133 "KEYWORDS.txt"
{"range_to_zero", def_range_to_zero},
#line 197 "KEYWORDS.txt"
{"quote-two", def_quote_HYPHEN_MINUS_two},
#line 138 "KEYWORDS.txt"
{"roll>", def_roll_GREATER_THAN_SIGN},
#line 131 "KEYWORDS.txt"
{"quoted", def_quoted},
#line 114 "KEYWORDS.txt"
{"nullary", def_nullary},
#line 169 "KEYWORDS.txt"
{"unquoted", def_unquoted},
#line 47 "KEYWORDS.txt"
{"rest", rest},
#line 172 "KEYWORDS.txt"
{"while", def_while},
#line 15 "KEYWORDS.txt"
{"=", def_eq},
{""},
#line 33 "KEYWORDS.txt"
{"rshift", rshift},
#line 191 "KEYWORDS.txt"
{"\\/", def_REVERSE_SOLIDUS_SOLIDUS},
#line 27 "KEYWORDS.txt"
{"add", add},
#line 70 "KEYWORDS.txt"
{"appN", def_appN},
#line 192 "KEYWORDS.txt"
{"_isnt_list", def__isnt_list},
#line 139 "KEYWORDS.txt"
{"rollup", def_rollup},
#line 56 "KEYWORDS.txt"
{"le", def_le},
#line 64 "KEYWORDS.txt"
{"abs", def_abs},
{""}, {""},
#line 136 "KEYWORDS.txt"
{"rolldown", def_rolldown},
#line 47 "KEYWORDS.txt"
{"rest", rest},
#line 177 "KEYWORDS.txt"
{"_stept", def__stept},
#line 181 "KEYWORDS.txt"
{"_timest", def__timest},
{""},
#line 165 "KEYWORDS.txt"
{"tuck", def_tuck},
{""},
{"times", def_times},
#line 32 "KEYWORDS.txt"
{"lshift", lshift},
{""}, {""},
#line 196 "KEYWORDS.txt"
{"quote-two", def_quote_HYPHEN_MINUS_two},
#line 42 "KEYWORDS.txt"
{"first", first},
#line 131 "KEYWORDS.txt"
{"quoted", def_quoted},
#line 60 "KEYWORDS.txt"
{"++", def_PLUS_SIGN_PLUS_SIGN},
#line 168 "KEYWORDS.txt"
{"unquoted", def_unquoted},
#line 34 "KEYWORDS.txt"
{"bool", truthy},
#line 138 "KEYWORDS.txt"
{"roll>", def_roll_GREATER_THAN_SIGN},
#line 73 "KEYWORDS.txt"
{"b", def_b},
#line 203 "KEYWORDS.txt"
#line 202 "KEYWORDS.txt"
{"on-non-empty-list", def_on_HYPHEN_MINUS_non_HYPHEN_MINUS_empty_HYPHEN_MINUS_list},
{""}, {""}, {""},
#line 74 "KEYWORDS.txt"
{"binary", def_binary},
#line 96 "KEYWORDS.txt"
{"flatten", def_flatten},
{""}, {""},
#line 166 "KEYWORDS.txt"
{"unary", def_unary},
#line 99 "KEYWORDS.txt"
{"gcd", def_gcd},
#line 68 "KEYWORDS.txt"
{"app2", def_app2},
#line 106 "KEYWORDS.txt"
{"infra", def_infra},
#line 78 "KEYWORDS.txt"
{"cleave", def_cleave},
#line 18 "KEYWORDS.txt"
{"!=", def_neq},
#line 182 "KEYWORDS.txt"
{"map", def_map},
#line 54 "KEYWORDS.txt"
{"lt", def_lt},
{""},
#line 115 "KEYWORDS.txt"
{"null", def_null},
#line 187 "KEYWORDS.txt"
{"_isnt_bool", def__isnt_bool},
#line 17 "KEYWORDS.txt"
{"<", def_lt},
#line 135 "KEYWORDS.txt"
{"reverse", def_reverse},
{""},
#line 50 "KEYWORDS.txt"
{"swap", swap},
{""},
#line 100 "KEYWORDS.txt"
{"genrec", def_genrec},
#line 53 "KEYWORDS.txt"
{"gt", def_gt},
#line 152 "KEYWORDS.txt"
{"stackd", def_stackd},
{""},
#line 29 "KEYWORDS.txt"
{"sub", sub},
{""},
#line 158 "KEYWORDS.txt"
#line 69 "KEYWORDS.txt"
{"app3", def_app3},
#line 157 "KEYWORDS.txt"
{"swapd", def_swapd},
#line 176 "KEYWORDS.txt"
{"_stept", def__stept},
#line 180 "KEYWORDS.txt"
{"_timest", def__timest},
{""}, {""}, {""},
#line 100 "KEYWORDS.txt"
{"genrec", def_genrec},
#line 160 "KEYWORDS.txt"
{"tailrec", def_tailrec},
{""},
#line 19 "KEYWORDS.txt"
{"<>", def_neq},
{""}, {""},
#line 164 "KEYWORDS.txt"
{"tuck", def_tuck},
#line 36 "KEYWORDS.txt"
{"clear", clear},
{""},
#line 21 "KEYWORDS.txt"
{">=", def_ge},
#line 28 "KEYWORDS.txt"
{"-", sub},
#line 121 "KEYWORDS.txt"
{"pm", def_pm},
#line 133 "KEYWORDS.txt"
{"range_to_zero", def_range_to_zero},
{""}, {""},
#line 199 "KEYWORDS.txt"
{"max-of-two", def_max_HYPHEN_MINUS_of_HYPHEN_MINUS_two},
#line 197 "KEYWORDS.txt"
{"empty?", def_empty_QUESTION_MARK},
#line 57 "KEYWORDS.txt"
{"ge", def_ge},
#line 64 "KEYWORDS.txt"
{"abs", def_abs},
{""}, {""},
#line 200 "KEYWORDS.txt"
{"max", def_max},
#line 74 "KEYWORDS.txt"
{"binary", def_binary},
#line 190 "KEYWORDS.txt"
{"_\\/_", def___REVERSE_SOLIDUS_SOLIDUS__},
{"/\\", def_SOLIDUS_REVERSE_SOLIDUS},
{""},
#line 63 "KEYWORDS.txt"
{"<<{}", def_LESS_THAN_SIGN_LESS_THAN_SIGN_LEFT_CURLY_BRACKET_RIGHT_CURLY_BRACKET},
#line 140 "KEYWORDS.txt"
{"rrest", def_rrest},
{""},
#line 71 "KEYWORDS.txt"
{"at", def_at},
#line 156 "KEYWORDS.txt"
{"sum", def_sum},
#line 97 "KEYWORDS.txt"
{"fork", def_fork},
{""},
#line 22 "KEYWORDS.txt"
{"%", fdiv_r},
#line 114 "KEYWORDS.txt"
{"nullary", def_nullary},
#line 181 "KEYWORDS.txt"
{"map", def_map},
#line 67 "KEYWORDS.txt"
{"app1", def_app1},
#line 132 "KEYWORDS.txt"
{"range", def_range},
{""},
#line 135 "KEYWORDS.txt"
{"reverse", def_reverse},
{""}, {""}, {""},
#line 198 "KEYWORDS.txt"
{"empty?", def_empty_QUESTION_MARK},
#line 121 "KEYWORDS.txt"
{"pm", def_pm},
#line 128 "KEYWORDS.txt"
{"pow", def_pow},
{""}, {""}, {""},
#line 72 "KEYWORDS.txt"
{"average", def_average},
{""},
#line 97 "KEYWORDS.txt"
{"fork", def_fork},
{""}, {""},
#line 60 "KEYWORDS.txt"
{"++", def_PLUS_SIGN_PLUS_SIGN},
{""}, {""},
#line 48 "KEYWORDS.txt"
{"stack", stack},
{""},
#line 57 "KEYWORDS.txt"
{"ge", def_ge},
#line 157 "KEYWORDS.txt"
{"sum", def_sum},
{""}, {""}, {""}, {""},
#line 25 "KEYWORDS.txt"
{"mul", mul},
{""},
#line 140 "KEYWORDS.txt"
{"rrest", def_rrest},
{""}, {""}, {""}, {""}, {""},
#line 35 "KEYWORDS.txt"
{"branch", branch},
{""}, {""}, {""},
#line 148 "KEYWORDS.txt"
{"small", def_small},
{""}, {""}, {""}, {""}, {""},
#line 28 "KEYWORDS.txt"
{"-", sub},
{""}, {""}, {""}, {""}, {""},
#line 163 "KEYWORDS.txt"
{"ternary", def_ternary},
#line 53 "KEYWORDS.txt"
{"gt", def_gt},
{""}, {""},
#line 137 "KEYWORDS.txt"
{"roll<", def_roll_LESS_THAN_SIGN},
#line 17 "KEYWORDS.txt"
{"<", def_lt},
{""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 63 "KEYWORDS.txt"
{"<<{}", def_LESS_THAN_SIGN_LESS_THAN_SIGN_LEFT_CURLY_BRACKET_RIGHT_CURLY_BRACKET},
#line 102 "KEYWORDS.txt"
{"grabN", def_grabN},
{""},
#line 72 "KEYWORDS.txt"
{"average", def_average},
{""}, {""}, {""},
#line 175 "KEYWORDS.txt"
{"_step1", def__step1},
#line 179 "KEYWORDS.txt"
{"_times1", def__times1},
{""}, {""},
#line 198 "KEYWORDS.txt"
{"max-of-two", def_max_HYPHEN_MINUS_of_HYPHEN_MINUS_two},
{""},
#line 96 "KEYWORDS.txt"
{"flatten", def_flatten},
#line 199 "KEYWORDS.txt"
{"max", def_max},
{""}, {""},
#line 174 "KEYWORDS.txt"
{"_step0", def__step0},
#line 178 "KEYWORDS.txt"
{"_times0", def__times0},
{""}, {""}, {""}, {""},
#line 59 "KEYWORDS.txt"
{"!-", def_EXCLAMATION_MARK_HYPHEN_MINUS},
{""}, {""}, {""},
#line 65 "KEYWORDS.txt"
{"anamorphism", def_anamorphism},
{""}, {""}, {""}, {""}, {""}, {""},
#line 152 "KEYWORDS.txt"
#line 151 "KEYWORDS.txt"
{"sqr", def_sqr},
#line 162 "KEYWORDS.txt"
{"take", def_take},
{""}, {""}, {""}, {""}, {""},
#line 187 "KEYWORDS.txt"
{"_map2", def__map2},
{""}, {""}, {""},
#line 108 "KEYWORDS.txt"
{"<<", def_LESS_THAN_SIGN_LESS_THAN_SIGN},
{""}, {""},
#line 111 "KEYWORDS.txt"
{"neg", def_neg},
#line 165 "KEYWORDS.txt"
{"unary", def_unary},
#line 15 "KEYWORDS.txt"
{"=", def_eq},
{""},
#line 186 "KEYWORDS.txt"
{"_map1", def__map1},
{""}, {""},
#line 119 "KEYWORDS.txt"
{"pam", def_pam},
{""}, {""},
#line 25 "KEYWORDS.txt"
{"mul", mul},
{""}, {""}, {""},
#line 162 "KEYWORDS.txt"
{"ternary", def_ternary},
{""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 48 "KEYWORDS.txt"
{"stack", stack},
{""},
#line 21 "KEYWORDS.txt"
{">=", def_ge},
{""}, {""}, {""},
#line 49 "KEYWORDS.txt"
{"swaack", swaack},
#line 20 "KEYWORDS.txt"
{"<=", def_le},
{""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 185 "KEYWORDS.txt"
{"_map0", def__map0},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 101 "KEYWORDS.txt"
{"getitem", def_getitem},
{""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 183 "KEYWORDS.txt"
{"_map?", def__map_QUESTION_MARK},
{""}, {""}, {""}, {""}, {""}, {""},
#line 52 "KEYWORDS.txt"
{"eq", def_eq},
#line 55 "KEYWORDS.txt"
{"neq", def_neq},
#line 189 "KEYWORDS.txt"
{"_\\/_", def___REVERSE_SOLIDUS_SOLIDUS__},
{""},
#line 184 "KEYWORDS.txt"
{"_mape", def__mape},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 103 "KEYWORDS.txt"
{"grba", def_grba},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""},
#line 109 "KEYWORDS.txt"
{"make_generator", def_make_generator},
{""}, {""},
#line 35 "KEYWORDS.txt"
{"branch", branch},
#line 61 "KEYWORDS.txt"
{"--", def_HYPHEN_MINUS_HYPHEN_MINUS},
{""}, {""},
#line 147 "KEYWORDS.txt"
{"small", def_small},
{""}, {""},
#line 111 "KEYWORDS.txt"
{"neg", def_neg},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""},
#line 161 "KEYWORDS.txt"
{"take", def_take},
{""}, {""},
#line 101 "KEYWORDS.txt"
{"getitem", def_getitem},
#line 119 "KEYWORDS.txt"
{"pam", def_pam},
{""}, {""}, {""},
#line 18 "KEYWORDS.txt"
{"!=", def_neq},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""},
#line 102 "KEYWORDS.txt"
{"grabN", def_grabN},
{""}, {""}, {""}, {""},
#line 183 "KEYWORDS.txt"
{"_mape", def__mape},
{""}, {""}, {""}, {""},
#line 186 "KEYWORDS.txt"
{"_map2", def__map2},
#line 65 "KEYWORDS.txt"
{"anamorphism", def_anamorphism},
#line 20 "KEYWORDS.txt"
{"<=", def_le},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 182 "KEYWORDS.txt"
{"_map?", def__map_QUESTION_MARK},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""}, {""},
#line 108 "KEYWORDS.txt"
{"<<", def_LESS_THAN_SIGN_LESS_THAN_SIGN}
#line 103 "KEYWORDS.txt"
{"grba", def_grba},
{""}, {""}, {""}, {""},
#line 109 "KEYWORDS.txt"
{"make_generator", def_make_generator},
#line 185 "KEYWORDS.txt"
{"_map1", def__map1},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 184 "KEYWORDS.txt"
{"_map0", def__map0}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)

View File

@ -349,21 +349,22 @@ def text_to_expression(text):
:rtype: stack
:raises ParseError: if the parse fails.
'''
lists = []
stack = ()
frame = []
stack = []
for tok in reversed(text.replace('[', ' [ ').replace(']', ' ] ').split()):
for tok in text.replace('[', ' [ ').replace(']', ' ] ').split():
if tok == '[':
if not lists:
raise ParseError('Unclosed bracket.')
thing, stack = stack, lists.pop()
elif tok == ']':
lists.append(stack)
stack = ()
stack.append(frame)
frame = []
continue
if tok == ']':
thing = list_to_stack(frame)
try:
frame = stack.pop()
except IndexError:
raise ParseError('Extra closing bracket.') from None
elif tok == _T:
thing = True
elif tok == _F:
@ -374,12 +375,12 @@ def text_to_expression(text):
except ValueError:
thing = Symbol(tok)
stack = thing, stack
frame.append(thing)
if lists:
raise ParseError('Extra closing bracket.')
if stack:
raise ParseError('Unclosed bracket.')
return stack
return list_to_stack(frame)
'''

View File

@ -24,7 +24,7 @@ binary unary popd
ccccons ccons ccons
ccons cons cons
choice [pop] [popd] branch
clear enstacken pop
clear [] swaack pop
cleave fork popdd
clop cleave popdd
cmp [[>] swap] dipd [ifte] ccons [=] swons ifte
@ -42,7 +42,7 @@ dupdd [dup] dipd
dupd [dup] dip
dupdipd dup dipd
dupdip dupd dip
enstacken [] swaack
enstacken stack [clear] dip
first uncons pop
first_two uncons first
flatten <{} [concat] step
@ -99,14 +99,12 @@ run <{} infra
second rest first
shift uncons [swons] dip
shunt [swons] step
select [first] [second] branch
size [pop ++] step_zero
small empty? [rest null] [pop true] branch
small dup null [rest null] [pop true] branch
spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte
split_at [drop] [take] clop
split_list [take reverse] [drop] clop
sqr dup mul
stack enstacken dup cons swaack pop
stackd [stack] dip
step_zero 0 roll> step
stuncons stack uncons
@ -124,7 +122,7 @@ unary nullary popd
uncons [first] dupdip rest
unit [] cons
unquoted [i] dip
unstack [enstacken] dip swoncat swaack pop
unstack [[] swaack] dip swoncat swaack pop
unswons uncons swap
while swap nulco dupdipd concat loop
x dup i

View File

@ -1,62 +0,0 @@
(import srfi-1)
(import srfi-12)
(import matchable)
; Importing srfi-67 did not actually make available symbol-compare. Boo!
(define (symbol<? a b) (string<? (symbol->string a) (symbol->string b)))
; a BTree is a four-tuple of (name value left right) | ()
(define (btree-get key btree)
(match btree
(() (abort "Key not found."))
((k value left right)
(if (eq? key k)
value
(btree-get key (if (symbol<? key k) left right))))
(_ (abort "Not a BTree."))))
(define (btree-insert key value btree)
(match btree
(() (list key value '() '()))
((k v left right)
(if (eq? key k)
(list k value left right)
(if (symbol<? key k)
(list k v (btree-insert key value left) right)
(list k v left (btree-insert key value right)))))
(_ (abort "Not a BTree."))))
(set! T '())
(set! T (btree-insert 'larry 23 T))
(set! T (btree-insert 'barry 18 T))
(set! T (btree-insert 'carry 99 T))
(display T)
(newline)
(define (balance el)
(if (null-list? el)
el
(balance0 el (halve (length el)))))
(define (balance0 el midpoint)
(receive (prefix suffix) (split-at el midpoint)
(cons
(first suffix)
(append
(balance prefix)
(balance (cdr suffix))))))
(define (halve n) (quotient n 2))
(set! T (iota 23))
;(define (btree-sorted-list items)
; (btree-sorted-list0 items (length items)))
;(define (btree-sorted-list items len)
; ())

View File

@ -1 +1 @@
(define (defs) (list "eq [false] [true] [false] cmp" "gt [true] [false] [false] cmp" "lt [false] [false] [true] cmp" "neq [true] [false] [true] cmp" "le [false] [true] [true] cmp" "ge [true] [true] [false] cmp" "? dup bool" "!- 0 >=" "++ 1 +" "-- 1 -" "<{} [] swap" "<<{} [] rollup" "abs dup 0 < [] [neg] branch" "anamorphism [pop []] swap [dip swons] genrec" "and nulco [nullary [false]] dip branch" "app1 grba infrst" "app2 [grba swap grba swap] dip [infrst] cons ii" "app3 3 appN" "appN [grabN] codi map reverse disenstacken" "at drop first" "average [sum] [size] cleave /" "b [i] dip i" "binary unary popd" "ccccons ccons ccons" "ccons cons cons" "choice [pop] [popd] branch" "clear [] swaack pop" "cleave fork popdd" "clop cleave popdd" "cmp [[>] swap] dipd [ifte] ccons [=] swons ifte" "codi cons dip" "codireco codi reco" "dinfrirst dip infrst" "dipd [dip] codi" "dipdd [dip] cons dipd" "dipddd [dipd] cons dipd" "disenstacken swaack pop" "divmod [/] [%] clop" "down_to_zero [0 >] [dup --] while" "drop [rest] times" "dupdd [dup] dipd" "dupd [dup] dip" "dupdipd dup dipd" "dupdip dupd dip" "enstacken stack [clear] dip" "first uncons pop" "first_two uncons first" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "getitem [rest] times first" "grabN <{} [cons] times" "grba [stack popd] dip" "ifte [nullary] dipd swap branch" "ii [dip] dupdip i" "infra swons swaack [i] dip swaack" "infrst infra first" "<< lshift" "lshift [2 *] times" "make_generator [codireco] ccons" "mod %" "modulus %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null _isnt_list bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "pick getitem" "pm [+] [-] clop" "popdd [pop] dipd" "popd [pop] dip" "popopdd [popop] dipd" "popopd [popop] dip" "popopop pop popop" "popop pop pop" "pow 1 roll> swap [*] cons times" "pred --" "product 1 swap [*] step" "quoted [unit] dip" "range [0 <=] [-- dup] anamorphism" "range_to_zero unit [down_to_zero] infra" "reco rest cons" "rest uncons popd" "reverse <{} shunt" "rolldown roll<" "roll< swapd swap" "roll> swap swapd" "rollup roll>" "rrest rest rest" ">> rshift" "rshift [2 /] times" "run <{} infra" "second rest first" "shift uncons [swons] dip" "shunt [swons] step" "select [first] [second] branch" "size [pop ++] step_zero" "small empty? [rest null] [pop true] branch" "spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte" "split_at [drop] [take] clop" "split_list [take reverse] [drop] clop" "sqr dup mul" "stackd [stack] dip" "step_zero 0 roll> step" "stuncons stack uncons" "succ --" "sum [+] step_zero" "swapd [swap] dip" "swoncat swap concat" "swons swap cons" "tailrec [i] genrec" "take <<{} [shift] times pop" "ternary binary popd" "third rest second" "tuck dup swapd" "unary nullary popd" "uncons [first] dupdip rest" "unit [] cons" "unquoted [i] dip" "unstack [[] swaack] dip swoncat swaack pop" "unswons uncons swap" "while swap nulco dupdipd concat loop" "x dup i" "step [_step0] x" "_step0 _step1 [popopop] [_stept] branch" "_step1 [?] dipd roll<" "_stept [uncons] dipd [dupdipd] dip x" "times [_times0] x" "_times0 _times1 [popopop] [_timest] branch" "_times1 [dup 0 >] dipd roll<" "_timest [[--] dip dupdipd] dip x" "map [_map0] cons [[] [_map?] [_mape]] dip tailrec" "_map? pop bool not" "_mape popd reverse" "_map0 [_map1] dipd _map2" "_map1 stackd shift" "_map2 [infrst] cons dipd roll< swons" "_isnt_bool [false] [true] branch" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "_isnt_list [] swoncat" "zip [null] [pop] [uncons-pair] [i cons] genrec" "uncons-pair uncons-two [quote-two] dipd" "uncons-two [uncons] ii swapd" "quote-two unit cons" "empty? dup null" "max-of-two [>] [pop] [popd] ifte" "max [uncons [max-of-two] step] on-non-empty-list" "min-of-two [<] [pop] [popd] ifte" "min [uncons [min-of-two] step] on-non-empty-list" "on-non-empty-list [empty?] dip [first] branch"))
(define (defs) (list "eq [false] [true] [false] cmp" "gt [true] [false] [false] cmp" "lt [false] [false] [true] cmp" "neq [true] [false] [true] cmp" "le [false] [true] [true] cmp" "ge [true] [true] [false] cmp" "? dup bool" "!- 0 >=" "++ 1 +" "-- 1 -" "<{} [] swap" "<<{} [] rollup" "abs dup 0 < [] [neg] branch" "anamorphism [pop []] swap [dip swons] genrec" "and nulco [nullary [false]] dip branch" "app1 grba infrst" "app2 [grba swap grba swap] dip [infrst] cons ii" "app3 3 appN" "appN [grabN] codi map reverse disenstacken" "at drop first" "average [sum] [size] cleave /" "b [i] dip i" "binary unary popd" "ccccons ccons ccons" "ccons cons cons" "choice [pop] [popd] branch" "clear [] swaack pop" "cleave fork popdd" "clop cleave popdd" "cmp [[>] swap] dipd [ifte] ccons [=] swons ifte" "codi cons dip" "codireco codi reco" "dinfrirst dip infrst" "dipd [dip] codi" "dipdd [dip] cons dipd" "dipddd [dipd] cons dipd" "disenstacken swaack pop" "divmod [/] [%] clop" "down_to_zero [0 >] [dup --] while" "drop [rest] times" "dupdd [dup] dipd" "dupd [dup] dip" "dupdipd dup dipd" "dupdip dupd dip" "enstacken stack [clear] dip" "first uncons pop" "first_two uncons first" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "getitem [rest] times first" "grabN <{} [cons] times" "grba [stack popd] dip" "ifte [nullary] dipd swap branch" "ii [dip] dupdip i" "infra swons swaack [i] dip swaack" "infrst infra first" "<< lshift" "lshift [2 *] times" "make_generator [codireco] ccons" "mod %" "modulus %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null _isnt_list bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "pick getitem" "pm [+] [-] clop" "popdd [pop] dipd" "popd [pop] dip" "popopdd [popop] dipd" "popopd [popop] dip" "popopop pop popop" "popop pop pop" "pow 1 roll> swap [*] cons times" "pred --" "product 1 swap [*] step" "quoted [unit] dip" "range [0 <=] [-- dup] anamorphism" "range_to_zero unit [down_to_zero] infra" "reco rest cons" "rest uncons popd" "reverse <{} shunt" "rolldown roll<" "roll< swapd swap" "roll> swap swapd" "rollup roll>" "rrest rest rest" ">> rshift" "rshift [2 /] times" "run <{} infra" "second rest first" "shift uncons [swons] dip" "shunt [swons] step" "size [pop ++] step_zero" "small dup null [rest null] [pop true] branch" "spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte" "split_at [drop] [take] clop" "split_list [take reverse] [drop] clop" "sqr dup mul" "stackd [stack] dip" "step_zero 0 roll> step" "stuncons stack uncons" "succ --" "sum [+] step_zero" "swapd [swap] dip" "swoncat swap concat" "swons swap cons" "tailrec [i] genrec" "take <<{} [shift] times pop" "ternary binary popd" "third rest second" "tuck dup swapd" "unary nullary popd" "uncons [first] dupdip rest" "unit [] cons" "unquoted [i] dip" "unstack [[] swaack] dip swoncat swaack pop" "unswons uncons swap" "while swap nulco dupdipd concat loop" "x dup i" "step [_step0] x" "_step0 _step1 [popopop] [_stept] branch" "_step1 [?] dipd roll<" "_stept [uncons] dipd [dupdipd] dip x" "times [_times0] x" "_times0 _times1 [popopop] [_timest] branch" "_times1 [dup 0 >] dipd roll<" "_timest [[--] dip dupdipd] dip x" "map [_map0] cons [[] [_map?] [_mape]] dip tailrec" "_map? pop bool not" "_mape popd reverse" "_map0 [_map1] dipd _map2" "_map1 stackd shift" "_map2 [infrst] cons dipd roll< swons" "_isnt_bool [false] [true] branch" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "_isnt_list [] swoncat" "zip [null] [pop] [uncons-pair] [i cons] genrec" "uncons-pair uncons-two [quote-two] dipd" "uncons-two [uncons] ii swapd" "quote-two unit cons" "empty? dup null" "max-of-two [>] [pop] [popd] ifte" "max empty? [uncons [max-of-two] step] [] branch"))

View File

@ -26,10 +26,7 @@
(import (chicken io))
(import (chicken string))
(import srfi-1)
(import srfi-12)
(import srfi-69)
(import matchable)
;(load "defs.scm") ; csc -prologue defs.scm joy.scm
(cond-expand
@ -49,105 +46,73 @@
;(joy-trace stack expression)
(if (null? expression)
(values stack dict)
(if (symbol? (car expression))
(if (string? (car expression))
(receive (s e d)
(joy-eval (car expression) stack (cdr expression) dict)
(joy s e d))
(joy (cons (car expression) stack) (cdr expression) dict))))
(define (joy-eval symbol stack expression dict)
(case symbol
((+ add) (values (joy-math-func + stack) expression dict))
((- sub) (values (joy-math-func - stack) expression dict))
((* mul) (values (joy-math-func * stack) expression dict))
((/ div) (values (joy-math-func quotient stack) expression dict)) ; but for negative divisor, no!?
((% mod) (values (joy-math-func modulo stack) expression dict))
(define (is-it? name) (string=? symbol name))
(cond
((is-it? "+") ((joy-func +) stack expression dict))
((is-it? "-") ((joy-func -) stack expression dict))
((is-it? "*") ((joy-func *) stack expression dict))
((is-it? "/") ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!?
((is-it? "%") ((joy-func modulo) stack expression dict))
((< lt) (values (joy-math-func < stack) expression dict))
((> gt) (values (joy-math-func > stack) expression dict))
((<= le) (values (joy-math-func <= stack) expression dict))
((>= ge) (values (joy-math-func >= stack) expression dict))
((= eq) (values (joy-math-func = stack) expression dict))
((<> != neq) (values (joy-math-func not-equal stack) expression dict))
((is-it? "add") ((joy-func +) stack expression dict))
((is-it? "sub") ((joy-func -) stack expression dict))
((is-it? "mul") ((joy-func *) stack expression dict))
((is-it? "div") ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!?
((is-it? "mod") ((joy-func modulo) stack expression dict))
((bool) (values (joy-bool stack) expression dict))
((is-it? "<") ((joy-func <) stack expression dict))
((is-it? ">") ((joy-func >) stack expression dict))
((is-it? "<=") ((joy-func <=) stack expression dict))
((is-it? ">=") ((joy-func >=) stack expression dict))
((is-it? "=") ((joy-func =) stack expression dict))
((is-it? "<>") ((joy-func not-equal) stack expression dict))
((is-it? "!=") ((joy-func not-equal) stack expression dict))
((dup) (values (joy-dup stack) expression dict))
((pop) (values (joy-pop stack) expression dict))
((stack) (values (cons stack stack) expression dict))
((swaack) (values (joy-swaack stack) expression dict))
((swap) (values (joy-swap stack) expression dict))
((is-it? "bool") (joy-bool stack expression dict))
((concat) (values (joy-concat stack) expression dict))
((cons) (values (joy-cons stack) expression dict))
((first) (values (joy-first stack) expression dict))
((rest) (values (joy-rest stack) expression dict))
((is-it? "dup") (values (cons (car stack) stack) expression dict))
((is-it? "pop") (values (cdr stack) expression dict))
((is-it? "stack") (values (cons stack stack) expression dict))
((is-it? "swaack") (values (cons (cdr stack) (car stack)) expression dict))
((is-it? "swap") (values (cons (cadr stack) (cons (car stack) (cddr stack))) expression dict))
((i) (joy-i stack expression dict))
((dip) (joy-dip stack expression dict))
((branch) (joy-branch stack expression dict))
((loop) (joy-loop stack expression dict))
((is-it? "concat") ((joy-func append) stack expression dict))
((is-it? "cons") ((joy-func cons) stack expression dict))
((is-it? "first") (values (cons (caar stack) (cdr stack)) expression dict))
((is-it? "rest") (values (cons (cdar stack) (cdr stack)) expression dict))
((inscribe) (joy-inscribe stack expression dict))
((is-it? "i") (joy-i stack expression dict))
((is-it? "dip") (joy-dip stack expression dict))
((is-it? "branch") (joy-branch stack expression dict))
((is-it? "loop") (joy-loop stack expression dict))
(else (if (hash-table-exists? dict symbol)
(values stack (append (hash-table-ref dict symbol) expression) dict)
(abort (conc "Unknown word: " symbol))))))
((hash-table-exists? dict symbol)
(values stack (append (hash-table-ref dict symbol) expression) dict))
(else (error (conc "Unknown word: " symbol)))))
(define (not-equal a b) (not (= a b)))
(define (joy-func op)
(lambda (stack expression dict)
(values (cons (op (cadr stack) (car stack)) (cddr stack)) expression dict)))
; ██████╗ ██████╗ ██████╗ ███████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗
;██╔════╝██╔═══██╗██╔══██╗██╔════╝ ██║ ██║██╔═══██╗██╔══██╗██╔══██╗██╔════╝
;██║ ██║ ██║██████╔╝█████╗ ██║ █╗ ██║██║ ██║██████╔╝██║ ██║███████╗
;██║ ██║ ██║██╔══██╗██╔══╝ ██║███╗██║██║ ██║██╔══██╗██║ ██║╚════██║
;╚██████╗╚██████╔╝██║ ██║███████╗ ╚███╔███╔╝╚██████╔╝██║ ██║██████╔╝███████║
; ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝
;Core Words
(define (joy-bool stack0)
(receive (term stack) (pop-any stack0)
(cons (joy-bool-term term) stack)))
(define (joy-bool stack expression dict)
(values (cons (joy-bool-term (car stack)) (cdr stack)) expression dict))
(define (joy-bool-term term)
(cond ((boolean? term) term)
((number? term) (not-equal 0 term))
((list? term) (not (null? term)))
(else #t)))
(define (joy-dup stack)
(receive (term _) (pop-any stack) (cons term stack)))
(define (joy-pop stack0)
(receive (_ stack) (pop-any stack0) stack))
(define (joy-swaack stack0)
(receive (el stack) (pop-list stack0) (cons stack el)))
(define (joy-swap stack0)
(receive (a stack1) (pop-any stack0)
(receive (b stack) (pop-any stack1)
(cons b (cons a stack)))))
(define (joy-concat stack0)
(receive (a stack1) (pop-list stack0)
(receive (b stack) (pop-list stack1)
(cons (append b a) stack))))
(define (joy-cons stack0)
(receive (a stack1) (pop-list stack0)
(receive (b stack) (pop-any stack1)
(cons (cons b a) stack))))
(define (joy-rest stack0)
(receive (el stack) (pop-list stack0)
(if (null-list? el)
(abort "Cannot take rest of empty list.")
(cons (cdr el) stack))))
(define (joy-first stack0)
(receive (el stack) (pop-list stack0)
(if (null-list? el)
(abort "Cannot take first of empty list.")
(cons (car el) stack))))
(cond ((boolean? term) term)
((number? term) (not-equal 0 term))
((list? term) (not (null? term)))
(else #t)))
; ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗███╗ ██╗ █████╗ ████████╗ ██████╗ ██████╗ ███████╗
@ -158,29 +123,28 @@
; ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
;Combinators
(define (joy-i stack0 expression dict)
(receive (expr stack) (pop-list stack0)
(values stack (append expr expression) dict)))
(define (joy-i stack expression dict)
(values (cdr stack) (append (car stack) expression) dict))
(define (joy-dip stack0 expression dict)
(receive (expr stack1) (pop-list stack0)
(receive (x stack) (pop-any stack1)
(values stack (append expr (cons x expression)) dict))))
(define (joy-dip stack expression dict)
(values (cddr stack)
(append (car stack) (cons (cadr stack) expression))
dict))
(define (joy-branch stack0 expression dict)
(receive (true_body stack1) (pop-list stack0)
(receive (false_body stack2) (pop-list stack1)
(receive (flag stack) (pop-bool stack2)
(values stack (append (if flag true_body false_body) expression) dict)))))
(define (joy-branch stack expression dict)
(let ((flag (caddr stack))
(false_body (cadr stack))
(true_body (car stack)))
(values (cdddr stack)
(append (if flag true_body false_body) expression)
dict)))
(define (joy-loop stack0 expression dict)
(receive (body stack1) (pop-list stack0)
(receive (flag stack) (pop-bool stack1)
(values stack
(if flag
(append body (cons body (cons 'loop expression)))
expression)
dict))))
(define (joy-loop stack expression dict)
(let ((flag (cadr stack))
(body (car stack)))
(values (cddr stack)
(if flag (append body (cons body (cons "loop" expression))) expression)
dict)))
;██████╗ █████╗ ██████╗ ███████╗███████╗██████╗
@ -191,39 +155,49 @@
;╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝
;Parser
(define (text->expression text) (parse (tokenize text)))
(define (string-replace str from to)
(string-intersperse (string-split str from #t) to))
(define (tokenize str) ; Let's do the simple trick.
(string-split (string-replace (string-replace str "]" " ] ") "[" " [ ")))
(define (parse tokens)
(if (null? tokens) '()
(receive (term rest_of_tokens)
(one-token-lookahead (car tokens) (cdr tokens))
(cons term (parse rest_of_tokens)))))
(define (one-token-lookahead token tokens)
(match token
("]" (abort "Extra closing bracket."))
("[" (expect-right-bracket tokens))
(_ (values (tokenator token) tokens))))
(define (expect-right-bracket tokens0)
(if (null? tokens0) (abort "Missing closing bracket.")
(receive (token tokens) (car+cdr tokens0)
(match token
("]" (values '() tokens))
("[" (receive (sub_list rest) (expect-right-bracket tokens)
(receive (el rrest) (expect-right-bracket rest)
(values (cons sub_list el) rrest))))
(_ (receive (el rest) (expect-right-bracket tokens)
(values (cons (tokenator token) el) rest)))))))
(define (tokenize str)
(string-split
(string-replace (string-replace str "]" " ] ") "[" " [ ")))
(define (tokenator token)
(cond ((string->number token) (string->number token))
((string=? token "true") #t)
((string=? token "false") #f)
(else (string->symbol token))))
(else token)))
(define (expect-right-bracket tokens acc)
(if (null? tokens)
(error "Missing closing bracket.")
(expect-right-bracket-lookahead (car tokens) (cdr tokens) acc)))
(define (expect-right-bracket-lookahead token tokens acc)
(cond ((string=? token "]") (values acc tokens))
((string=? token "[")
(receive (sub_list rest) (expect-right-bracket tokens '())
(receive (el rrest) (expect-right-bracket rest acc)
(values (cons sub_list el) rrest))))
(else
(receive (el rest) (expect-right-bracket tokens acc)
(values (cons (tokenator token) el) rest)))))
(define (one-token-lookahead token tokens)
(cond ((string=? token "]") (error "Extra closing bracket."))
((string=? token "[") (expect-right-bracket tokens '()))
(else (values (tokenator token) tokens))))
(define (parse0 tokens acc)
(if (null? tokens)
acc
(receive (term rest_of_tokens)
(one-token-lookahead (car tokens) (cdr tokens))
(cons term (parse0 rest_of_tokens acc)))))
(define (parse tokens) (parse0 tokens '()))
(define (text->expression text) (parse (tokenize text)))
;██████╗ ██████╗ ██╗███╗ ██╗████████╗███████╗██████╗
@ -238,7 +212,7 @@
(cond ((boolean? term) (if term "true" "false"))
((number? term) (->string term))
((list? term) (conc "[" (joy-expression->string term) "]"))
(else (symbol->string term))))
(else term)))
(define (joy-expression->string expr)
(string-intersperse (map joy-term->string expr) " "))
@ -253,61 +227,16 @@
;Definitions
(define (initialize)
(load-defs! (make-hash-table equal? symbol-hash)))
(load-defs (make-hash-table string=? string-hash)))
(define (load-defs! dict)
(for-each (lambda (def) (add-def! def dict)) (defs))
; defs is defined in defs.scm
(define (load-defs dict)
(for-each (lambda (def) (add-def def dict)) (defs)) ;defs is defined in defs.scm
dict)
(define (add-def! def dict)
(define (add-def def dict)
(let ((def_list (text->expression def)))
(hash-table-set! dict (car def_list) (cdr def_list))))
(define (joy-inscribe stack0 expression dict0)
(receive (def stack) (pop-list stack0)
(if (null-list? def) (abort "Empty definition.")
(receive (name body) (car+cdr def)
(if (not (symbol? name)) (abort "Def name isn't symbol.")
(let ((dict (hash-table-copy dict0)))
(hash-table-set! dict name body)
(values stack expression dict)))))))
;██╗ ██╗████████╗██╗██╗ ███████╗
;██║ ██║╚══██╔══╝██║██║ ██╔════╝
;██║ ██║ ██║ ██║██║ ███████╗
;██║ ██║ ██║ ██║██║ ╚════██║
;╚██████╔╝ ██║ ██║███████╗███████║
; ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝
; Utils
(define (not-equal a b) (not (= a b)))
(define (joy-math-func op stack0)
(receive (a stack1) (pop-int stack0)
(receive (b stack) (pop-int stack1)
(cons (op b a) stack))))
(define (pop-any stack)
(if (null-list? stack)
(abort "Not enough values on Stack")
(car+cdr stack)))
(define (pop-kind stack predicate message)
(receive (term rest) (pop-any stack)
(if (predicate term) (values term rest) (abort message))))
(define (pop-list stack) (pop-kind stack list? "Not a list."))
(define (pop-int stack) (pop-kind stack number? "Not an integer."))
(define (pop-bool stack) (pop-kind stack boolean? "Not a Boolean value."))
(define (string-replace str from to)
(string-intersperse (string-split str from #t) to))
(define (joy-trace stack expression)
(print (conc (joy-expression->string (reverse stack)) " . " (joy-expression->string expression))))
;██████╗ ███████╗██████╗ ██╗
;██╔══██╗██╔════╝██╔══██╗██║
@ -319,20 +248,30 @@
(define (prompt) (display "joy? ") (read-line))
(define (main-loop stack0 dict0)
(define DICTIONARY (initialize))
(define STACK '())
(define (doit text)
(receive (stack dict) (joy STACK (text->expression text) DICTIONARY)
(set! DICTIONARY dict)
(set! STACK stack)
(joy-expression->string (reverse stack))))
(define (main-loop)
(let ((text (prompt)))
(if (eof-object? text) (print)
(receive (stack dict)
(handle-exceptions exn
(begin (display exn) (newline) (values stack0 dict0))
(joy stack0 (text->expression text) dict0))
(print (joy-expression->string (reverse stack)))
(main-loop stack dict)))))
(main-loop '() (initialize))
(if (not (string=? text ""))
((print (doit text)) (main-loop))
(else))))
;(display (text->expression "5 [] cons [4] concat first"))
(define (joy-trace stack expression)
(print (conc (joy-expression->string (reverse stack)) " . " (joy-expression->string expression))))
(main-loop)
;(display (doit "5 [] cons [4] concat first"))
;(display (doit "5 down_to_zero"))
;(display (doit "1 2 true [4 5 false] loop <"))
;(newline)