Problem 4: Scheme Def (100 pts)

Note: You are supposed to finish this problem after Wednesday's lecture about Macros.

Implement def, which simulates a python def statement, allowing you to write code like (def f(x y) (+ x y)).

The above expression should create a function with parameters x and y, and body (+ x y), then bind it to the name f in the current frame.

Note:

  1. the previous is equivalent to (def f (x y) (+ x y)).
  2. body stands for a single expression. Expressions like (def f (x y) (print x) (print y) is outside the scope of this problem, you don't need to care about it.

Hint: We strongly suggest doing the WWSD questions on macros first as understanding the rules of macro evaluation is key in writing macros.

(define-macro (def func args body)
  ''YOUR-CODE-HERE
)

;;; Tests
; scm> (def f(x y) (+ x y))
; f
; scm> (f 1 2)
; 3