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 and expressions, 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 call do_lambda_form on the appropriate arguments.
  • Bind the symbol to this new LambdaProcedure instance.

Use Ok to unlock and test your code:

python ok -q 10 -u
python ok -q 10