Skip to content

Playground

Test a prediction

Use this page after reading the natural-number chapter. Change one condition at a time, and write down the definition, representation, method, expected trace, and expected result before running the cell.

Before running

For 2 + 1, how often will the base and recursive branches run? Which trace line appears first, and why?

Experiment · Natural-number addition Not run
⌘ / Ctrl + Enter
Output
Compare the rule order with your prediction.
Check the prediction

The recursive branch calls the base case before it can return. Because @log records a message after the wrapped call returns, the base line appears first, the recursive line second, and 3 is printed last.

Try changing only right from 1 to 2. One more successor on the right adds one recursive call and one recursive trace line. The base case still runs once.

Reading failures

An exception is also part of the implementation's contract. Try a negative argument to natural_number, a zero denominator to rational, or an interval that does not isolate one root. Locate the matching validation branch before interpreting the error.