Skip to main content

Guest-language types and execution limits

What this concept is​

A guest language has its own types and execution rules even when implemented in Python. Here boolean and integer values are distinct: exact type checks reject True as an arithmetic operand. Expression fuel counts visited AST nodes across the whole evaluation.

Why it matters here​

Python regards bool as an int subclass. Using isinstance(value, int) would accidentally accept a value the guest contract forbids. Similarly, a recursive Python evaluator does not automatically supply proper tail calls just because the interpreted program is tail recursive.

Concrete example​

('add', ('lit', 1), ('lit', 2)) visits three expressions. Fuel 2 fails and fuel 3 returns 3. ('add', ('lit', True), ('lit', 2)) raises integer required. For self-application, a small shared budget eventually raises fuel exhausted; giving every recursive call a new budget defeats that limit.

Common confusion / misconception​

Fuel is not a wall-clock timeout or memory limit. One huge integer addition can be expensive; malformed or hostile host objects are outside the trusted tuple contract. Host recursion can fail before large fuel runs out. This evaluator is not a sandbox and makes no proper-tail-recursion guarantee.

How to use it​

Separate syntax preconditions, language errors and host limitations in the README. Keep one machine budget across nested calls. Use small trusted ASTs. When discussing production rules engines, separately analyze input validation, isolation, memory accounting, deadlines and capability exposure.

Check yourself​

Why is disabling Python eval insufficient to prove safety? Why does one fuel unit not mean constant CPU time? What changes if closures can mutate shared state? Answer using a concrete operation or retained object.

Mini drill or application​

Add tests for zero fuel, the exact three-node boundary, boolean arithmetic and a divergent expression with fuel 40. Propose an explicit-stack evaluator and describe which host limit it removes and which resource limits remain.

Read this only if stuck​

Review explicit-control evaluation in SICP chapter 5. Implementing a trampoline is optional; explaining the current recursion limitation is required.