To deliberate practice TDD (Test-Driven Development) and C#, I was building an interpreter (not a compiler to bytecodes, yet). The project:
It has a class library project, and a test project. There is also a REPL (Read Eval Print Loop) simple console application.
In Lisp, an expressions is composed by a verb and arguments, written in a list enclosed by parenthesis. For example, a list that at evaluation returns the sum of 1, 2 and 3:
(+ 1 2 3)
Here, the plus + sign is a symbol that in Lisp/Clojure refers to a form. A form receives arguments, operates on them, and returns a result. A typical form receives its arguments as evaluated expressions: the expressions are evaluated BEFORE the evaluation of the form:
(+ 1 (- 3 4) 3)
In the above example, the first argument to plus is a constant 1, and the second argument is an expression that is evaluated to –1 before the evaluation of the outer list.
But there are forms that not need evaluated arguments. They receive the arguments without evaluation. They are called special forms. I have implemented:
And I have implemented some (non special) forms as primitives in C#. Most of them could be implemented in Lisp itself, but being so basic that I preferred to implement them directly in C#, using TDD as usual:
Next topics: the Machine implementation, Context, how to use Parser and Lexer, more about expression evaluation, macros, tail recursion, etc.
Angel “Java” Lopez