Tracing Joy Execution


Pretty printing support, e.g.:

Joy? [23 18 * 99 +] trace
       • 23 18 mul 99 add
    23 • 18 mul 99 add
 23 18 • mul 99 add
   414 • 99 add
414 99 • add
   513 • 

513 <-top


On each line the stack is printed with the top to the left, then a bullet symbol,``•``, to represent the current locus of processing, then the pending expression to the right.

class joy.utils.pretty_print.TracePrinter[source]

This is what does the formatting. You instantiate it and pass the viewer() method to the function, then print it to see the trace.


Return a list of strings, one for each entry in the history, prefixed with enough spaces to align all the interpreter dots.

This method is called internally by the __str__() method.

Return type


viewer(stack, expression)[source]

Record the current stack and expression in the TracePrinter’s history. Pass this method as the viewer argument to the function.

  • quote (stack) – A stack.

  • expression (stack) – A stack.

joy.utils.pretty_print.trace(stack, expression, dictionary)[source]

Evaluate a Joy expression on a stack and print a trace.

This function is just like the i combinator but it also prints a trace of the evaluation

  • stack (stack) – The stack.

  • expression (stack) – The expression to evaluate.

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

Return type

(stack, (), dictionary)