You have now already made a simple language, able to evaluate nested arithmetic expressions. It is time to add the ability to use control structures.
For our language, an if
statement will suffice. The if
takes three arguments. The first one is the predicate p
, which is always evaluated. The second or third argument is then evaluated and returned depending on the value of p
.
Go on, you know what to do.
nosetests tests/test_3_evaluating_complex_expressions.py --stop
Remember that the REPL is a great way to play around with your language while you work on it.
./repl
> (if (> 42 100)
… 'foo
… 'bar)
bar
Go to part 4 where we add environments that'll enable us to work with variables.