Interpreter Project
Extension 3: Miscellaneous items and define-macro

You will need to complete quasiquote and unquote from Extension 1 in order to complete define-macro
Final project due Monday, May 8 at noon


Reminder: 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 define-macro

Implementing macros can be quite difficult. You may wish to pursue other Extensions before attempting this one. You should play around with macros in DrScheme for a bit to see if you can figure out what is going on with them. Here are a few of the most basic things you need to know about macros:

  1. Macro definitions are always of the form:
    (define-macro macro-name
      (lambda (arg0 arg1 ...)
          expression0
          expression1
          ...))
    
  2. Each expression in the macro is evaluated in order, but in a "clean" environment that has the definitions of the primitives, but no other bindings.
  3. The final evaluated expression in the macro is returned as the result of the macro substitution, and this result is then evaluated in the current environment.
  4. You will need to complete quasiquote and unquote from Extension 1 if you plan on testing this fully.
Once you've got macros working, test them out by running the code we wrote for streams.


Miscellany

If you can't get any of the other major Extension pieces to work properly, you can try some smaller things for partial-extra-credit:

  1. Allow functions to take arbitrary numbers of arguments. For example:
    ; Allows the function to take 1 or more arguments
    (define f 
      (lambda (first . list-of-optional-arguments)
         '...))
    
    
    or
    ; Allows the function to take 0 or more arguments
    (define f   
      (lambda list-of-optional-arguments 
         '...))
    
  2. Allow users to define procedures using the shortcut notation used in the textbook. For example, the following two statements are identical in Scheme:
    (define f (lambda (n) (+ n 1)))
    
    (define (f n) (+ n 1))
    
  3. If you have another interesting idea, come talk to me about it. It's possible your idea is too hard (threads, for example), and I'd like to make sure you don't waste your time unless you really want to.