Problem 6 (150pts): begin
Change the eval_all
function in scheme_eval_apply.py
(which is called from do_begin_form
in scheme_forms.py
) to complete the implementation of the begin
special form (spec).
A begin
expression is evaluated by evaluating all sub-expressions in order.
The value of the begin
expression is the value of the final sub-expression.
scm> (begin (+ 2 3) (+ 5 6))
11
scm> (define x (begin (display 3) (newline) (+ 2 3)))
3
x
scm> (+ x 3)
8
scm> (begin (print 3) '(+ 2 3))
3
(+ 2 3)
If eval_all
is passed an empty list of expressions (nil
), then it should return the Python value None
, which represents the Scheme value undefined
.
Before writing any code, unlock the tests to verify your understanding of the question:
$ python ok -q 06 -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ python ok -q 06