# Joy Interpreter — Thun 0.4.1 documentation

# Joy Interpreter

## `joy.joy`

This module implements an interpreter for 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(s) written in C.

exception joy.joy.UnknownSymbolError

joy.joy.interp(stack=(), dictionary=None)

  Simple REPL with no extra output, suitable for use in scripts.

joy.joy.joy(stack, expression, dictionary, viewer=None)

  Evaluate a Joy expression on a stack.

  This function iterates through a sequence of terms which are either literals (strings, numbers, sequences of terms) or function symbols. Literals are put onto the stack and functions are looked up in the dictionary and executed.

  > The viewer is a function that is called with the stack and expression on every iteration, its return value is ignored.

  > param stack stack

  >   The stack.

  > param stack expression

  >   The expression to evaluate.

  > param dict dictionary

  >   A `dict` mapping names to Joy functions.

  > param function viewer

  >   Optional viewer function.

  > rtype

  >   (stack, (), dictionary)

joy.joy.repl(stack=(), dictionary=None)

  Read-Evaluate-Print Loop

  Accept input and run it on the stack, loop.

  Parameters

    - stack (stack) – The stack.

    - dictionary (dict) – A `dict` mapping names to Joy functions.

  Return type

    stack

joy.joy.run(text, stack, dictionary, viewer=None)

  Return the stack resulting from running the Joy code text on the stack.

  Parameters

    - text (str) – Joy code.

    - stack (stack) – The stack.

    - dictionary (dict) – A `dict` mapping names to Joy functions.

    - viewer (function) – Optional viewer function.

  Return type

    (stack, (), dictionary)