Interpreter Project

Extension A: quasiquote, unquote

Optional extension.
All parts due: NOON on Sunday, May 11th
Notes about extensions

Extension A, like other extensions which will be provided, serves three purposes. The extensions will...

  1. ...give you a much more detailed understanding of the material.
  2. ...make your interpreter more complete.
  3. ...provide you a chance to earn some extra credit.
It is extremely important to note that you should not be attempting any of the Extensions unless you are completely finished with all previous parts. You will lose far more points for failing to complete required sections of the interpreter than you could possibly gain by completing all of the Extensions.

You may attempt to complete the Extensions at any point during the project. You do not need to attempt them after a specific required portion of the project. In addition, you should not run handin37 separately to hand in an extension: simply hand in the extension along with the whatever section you are handing in.

Finally, since these extensions are considered "advanced" features, you will receive far less guidance in completing them than you will receive for the required portions of the project. This does not mean that you cannot ask questions; rather, I will provide less information to you up front, forcing you to work out details on your own.

Implementing quasiquote and unquote

It is largely up to you to work out the details in this section, and to test it thoroughly. You should find portions of the code here look similar to the work you have already done.

Here are a few brief details about quasiquote and unquote:

  1. The syntax is of quasiquote is (quasiquote expr) which can be abbreviated as `expr.
  2. The syntax is of unquote is (unquote expr) which can be abbreviated as ,expr.
  3. (unquote expr) can only appear inside of a quasiquoted expression.
  4. If the quasiquoted expression contains no unquoted sub-expressions, then (quasiquote expr) is equivalent to (quote expr).
  5. If an (unquote expr) appears in a quasiquoted expression, then (unquote expr) is replaced by the evaluated expression expr.
  6. If a (quasiquote expr) appears in a quasiquoted expression, it is unchanged.

Here are some interactions in Racket:

> (define a 3)
> (define b 4)
> ,a                  ; rule 3 
unquote: not in quasiquote in: (unquote b)
> '(+ a b)
(+ a b)
> `(+ a b)            ; rule 4 
(+ a b)
> `(+ ,a ,b)          ; rule 5 
(+ 3 4)
> `(+ `(+ ,a ,b) ,b)  ; rule 6
(+ `(+ ,a ,b) 4)
> `,`,`,a
Be sure you try other combinations to make sure you understand how quasiquote and unquote work.

Extension A may be completed at any stage of the final project and does not need to be turned in separately.