Problem 10 (100pts): bind lambda
!
Currently, your Scheme interpreter is able to bind symbols to user-defined procedures in the following manner:
scm> (define f (lambda (x) (* x 2)))
f
However, we'd like to be able to use the shorthand form of defining named procedures:
scm> (define (f x) (* x 2))
f
Modify the do_define_form
function in scheme_forms.py
so that it correctly handles define (...) ...)
expressions (spec).
Make sure that it can handle multi-expression bodies. For example,
scm> (define (g y) (print y) (+ y 1))
g
scm> (g 3)
3
4
Your implementation should do the following:
- Using the given variables
signature
andexpressions
, find the defined function's name (symbol), formals, and body. - Create a
LambdaProcedure
instance using the formals and body. Hint: You can use what you've done in Problem 8 and calldo_lambda_form
on the appropriate arguments. - Bind the symbol to this new
LambdaProcedure
instance.
Before writing any code, unlock the tests to verify your understanding of the question:
$ python ok -q 10 -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ python ok -q 10