Interpreter Project
Extension 1: Quasiquotation and Syntax Checking: quasiquote, unquote

Extension 1 may be completed at any stage of the final project.
Final project due Monday, May 8 at noon

Notes about extensions

The extensions are intended to serve three purposes; they will:

  1. Give you a much more detailed understanding of the material.
  2. Make your interpreter more complete.
  3. Provide you with a chance to earn some extra credit.
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.

Finally, since these extensions are considered "advanced" features, you will receive far less guidance in completing them then 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

Since you have completed Part 2, your interpreter can already evaluate quoted expressions. In this extension, you will implement quasiquote and unquote. You may want to read the Help Desk for further information on these special forms.

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 Scheme:

> (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
3
Be sure you try other combinations to make sure you understand how quasiquote and unquote work.
Implementing a simple syntax checker

To implement a simple syntax checker, you will write two new functions, (tagged-list-length-n? exp tag n) and (tagged-list-min-length-n? exp tag n):

By replacing your calls to tagged-list? with calls to tagged-list-length-n? or tagged-list-min-length-n?, your interpreter will be able to catch many simple syntax errors.

Remember that as you complete future parts of the interpreter, you will want to continue to use these length-verifying tagged-list? variants instead of the original tagged-list? procedure.