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.
Before writing any code, unlock the tests to verify your understanding of the question:
$ python ok -q 05 -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ 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
Congratulations! You have now finished part 1 of this project.