Reading — step 1 of 5
Read
~1 min readEvaluator
Eval: Numbers & Symbols
The evaluator is the core. Take an AST node, return its value.
python
The evaluation rules:
- Numbers: return themselves.
- Symbols: look up in environment.
- Lists (calls): first eval the operator (a function), then args, then call.
Special forms (don't eval all args):
if: only evaluate the chosen branchdefine: bind a symbol; don't evaluate the symbol itselfquote: return the unevaluated expressionlambda: create a function
Most operators are JUST functions in the environment. +, *, <, print — all pre-defined functions. The interpreter dispatches automatically.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…