Problem 5 (150pts): 'quote
In Scheme, you can quote expressions in two ways: with the quote
special form (spec) or with the symbol '
. The reader converts '...
into (quote ...)
, so that your interpreter only needs to evaluate the (quote ...)
syntax. The quote
special form returns its operand expression without evaluating it:
scm> (quote hello)
hello
scm> '(cons 1 2) ; Equivalent to (quote (cons 1 2))
(cons 1 2)
Implement the do_quote_form
function in scheme_forms.py
so that it simply returns the unevaluated operand of the (quote ...)
expression.
Use Ok to unlock and test your code:
python ok -q 05 -u
python ok -q 05
After completing this function, you should be able to evaluate quoted expressions. Try out some of the following in your interpreter!
scm> (quote a)
a
scm> (quote (1 2))
(1 2)
scm> (quote (1 (2 three (4 5))))
(1 (2 three (4 5)))
scm> (car (quote (a b)))
a
scm> 'hello
hello
scm> '(1 2)
(1 2)
scm> '(1 (2 three (4 5)))
(1 (2 three (4 5)))
scm> (car '(a b))
a
scm> (eval (cons 'car '('(1 2))))
1
scm> (eval (define tau 6.28))
6.28
scm> (eval 'tau)
6.28
scm> tau
6.28
Congradulations! You now finish part 1 of this project.