• R/O
  • HTTP
  • SSH

Thun: Repository summary

Interpreter and library.

Recent Commits RSS

Rev. Time Author Message
109cdda 2022-10-18 09:51:12 Simon Forman simpler Readline support would be nice.
ec5036b 2022-10-16 12:04:27 Simon Forman This and that.
74f936e 2022-10-16 03:05:17 Simon Forman Cleanup and refactoring. Bug when subtracting identical ...
062b01d 2022-10-16 01:52:58 Simon Forman That seems to work: addition and subtraction.
c130026 2022-10-15 13:01:18 Simon Forman Mostly done with addition and subtraction.
0b4b79f 2022-10-15 12:36:50 Simon Forman Not quite as smooth as I'd hoped.
6ade65e 2022-10-15 09:52:31 Simon Forman Subtraction seems to work now.
9ba9d05 2022-10-14 15:10:41 Simon Forman Progress.
8bedb77 2022-10-12 03:37:38 Simon Forman Adding like-sign bigints in Joy.
e7f4a02 2022-10-11 14:28:50 Simon Forman Misc stuff.


Name Rev. Time Author Message
simpler 109cdda 2022-10-18 09:51:12 Simon Forman Readline support would be n...
master a2cf184 2022-09-12 01:33:50 Simon Forman minor cleanup



A Dialect of Joy.


Joy is a programming language created by Manfred von Thun that is easy to
use and understand and has many other nice properties.  This project
implements interpreters for a dialect 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.

The best source (no pun intended) for learning about Joy is the
information made available at the website of La Trobe University (see the
references section below for the URL) 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.

Directory structure

     |-- LICENSE - GPLv3
     |-- README - this file
     |-- archive
     |   |-- Joy-Programming.zip
     |   `-- README
     |-- docs
     |   |-- notebooks - Jupyter Notebooks and supporting modules
     |   |-- reference - Docs for each function.
     |   |-- sphinx_docs - Generate https://joypy.osdn.io/ site.
     |   `-- README - Table of Contents
     `-- implementations
         |-- Nim - interpreter
         |-- Prolog - interpreter
         |            type inference
         |            work-in-progress compiler
         |-- Python - interpreter
         |-- Rust - work-in-progress interpreter
         `-- defs.txt - common Joy definitions for all interpreters


Jupyter Notebooks

The docs/notebooks dir contains Jupyter notebooks, ... TODO

Sphinx Docs

Some of the documentation is in the form of ReST files in
docs/sphinx_docs dir.

Building the Docs

Building the documentation is a little tricky at the moment.  It involves
a makefile that uses nbconvert to generate ReST files from some of the
notebooks, copies those to the sphinx source dir, then builds the HTML
output using sphinx.

Get the dependencies for (re)building the docs:

    pip install Thun[build-docs]
    make docs

Basics of Joy

Joy is stack-based.  There is a main stack that holds data items:
integers, floats, strings, functions, and sequences or quotes which hold
data items themselves.

    23 1.8 'a string' "another" dup [21 18 /] [1 [2 [3]]]

A Joy expression is just a sequence (a.k.a. "list") of items.  Sequences
intended as programs are called "quoted programs".  Evaluation proceeds
by iterating through the terms in the expression, putting all literals
onto the main stack and executing functions as they are encountered.
Functions receive the current stack and return the next stack.

Literals and Simple Functions

    joy? 1 2 3
          . 1 2 3
        1 . 2 3
      1 2 . 3
    1 2 3 . 

    1 2 3 <-top

    joy? + +
    1 2 3 . + +
      1 5 . +
        6 . 

    6 <-top

    joy? 7 *
      6 . 7 *
    6 7 . *
     42 . 

    42 <-top



The main loop is very simple as most of the action happens through what
are called "combinators": functions which accept quoted programs on the
stack and run them in various ways.  These combinators factor specific
patterns that provide the effect of control-flow in other languages (such
as ifte which is like if..then..else..)  Combinators receive the current
expession in addition to the stack and return the next expression.  They
work by changing the pending expression the interpreter is about to
execute.  The combinators could work by making recursive calls to the
interpreter and all intermediate state would be held in the call stack of
the implementation language, in this joy implementation they work instead
by changing the pending expression and intermediate state is put there.

    joy? 23 [0 >] [dup --] while


    -> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23


§.4.4 Definitions and More Elaborate Functions

§.4.5 Programming and Metaprogramming

§.4.6 Refactoring

§.6 References & Further Reading

Wikipedia entry for Joy:

Homepage at La Trobe University:



Stack based - literals (as functions) - functions - combinators -
Refactoring and making new definitions - traces and comparing
performance - metaprogramming as programming, even the lowly integer
range function can be expressed in two phases: building a specialized
program and then executing it with a combinator - ?Partial evaluation?
- ?memoized dynamic dependency graphs? - algebra


Copyright © 2014-2022 Simon Forman

This file is part of Thun

Thun is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any
later version.

Thun is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more

You should have received a copy of the GNU General Public License along
with Thun.  If not see <http://www.gnu.org/licenses/>.

Show on old repository browser