I am having trouble with some tricky-looking lambda expressions in Scheme, and I would like to see how they are being evaluated by the interpreter.
I would like the Scheme interpreter to print all the evaluation steps, as seen in SICP Section 1.1.5, "The Substitution Model for Procedure Application".
I am looking for a solution using any Scheme interpreter. I have already tried Racket's tracing, but it only traces procedure calls, not every expression.
Motivating example
Given the definition of Church numerals from SICP Exercise 2.6:
(define zero (lambda (f) (lambda (x) x)))
(define (add-1 n)
(lambda (f) (lambda (x) (f ((n f) x)))))
and the task:
Define
oneandtwodirectly (not in terms ofzeroandadd-1).
I wish to check my definitions of one and two against the results of evaluating (add-1 zero) and (add-1 (add-1 zero)).
This is what I would like the Scheme interpreter to print out:
> (add-1 zero)
(add-1 (lambda (f) (lambda (x) x)))
(lambda (f) (lambda (x) (f (((lambda (f) (lambda (x) x)) f) x))))
(lambda (f) (lambda (x) (f ((lambda (x) x) x))))
(lambda (f) (lambda (x) (f x)))
>