In this part we will take care of the necessities needed to actually start writing the first parts of an evaluator. Nothing complicated happens in this part but this will setup the groundwork for the later parts. Let’s get started then!
An expression of the form X @ Y
is equivalent to the expression
Z = X, Z = Y
.
Why is this valuable? We can use it in matches to make the code more readabe:
Here the Bar
/Baz
/Qux
are aliases to what’s on the other side of
the @
operator.
The goal of this part is to implement these two predicates:
eval(lisp_val::in, lisp_val::out) is semidet
such that the output
value is
lisp_string
the input valuelisp_number
the input valuelisp_boolean
the input valuelisp_list([atom("quote"), X])
is X.eval
should be in a module named eval
.
read_expr(list(char)::in, lisp_val::out) is semidet
which for now
should just use with parser.top_level_expression
where the Rest
is an empty list
The main
predicate should use read_expr
and either output “Cannot
read expression.”, “Cannot eval expression.” or show
the eval
-ed
output.
The full source code for this part can be found here.
The implementation for this part of the tutorial is nothing to write home about - very simple and easy to understand.
Let’s start with the eval
module:
Like I said - nothing complicated - just remember how the @
operator
works. Now for the main
module:
Again, nothing tricky. This was way to easy - so in the next installment we’ll introduce a couple of new concepts, see you soon!