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.

joy.joy.joy(stack, expression, dictionary, viewer=None)[source]

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 disctionary and executed.

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

Parameters:
  • stack (stack) – The stack.
  • expression (stack) – The expression to evaluate.
  • dictionary (dict) – A dict mapping names to Joy functions.
  • viewer (function) – Optional viewer function.
Return type:

(stack, (), dictionary)

joy.joy.repl(stack=(), dictionary=None)[source]

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)[source]

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)