DOC PREVIEW
MIT 6 001 - The Meta-Circular Evaluator

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Spring Semester, 2005 Project 5 - The Meta-Circular Evaluator • Issued Monday, April 25th. • To Be Completed By: Friday, May 6th, 6:00 pm • Code to load for this project: o Links to the system code files meval.scm, syntax.scm, and environment.scm are provided from the Projects link on the course web page. You should begin working on the assignment once you receive it. It is to your advantage to get work done early, rather than waiting until the night before it is due. You should also read over and think through each part of the assignment (as well as any project code) before you sit down at the computer. It is generally much more efficient to test, debug, and run a program that you have thought about beforehand, rather than doing the planning "online." Diving into program development without a clear idea of what you plan to do generally ensures that the assignments will take much longer than necessary. The purpose of this project is to familiarize you with evaluators. There is a fair amount to read and understand; we recommend that you first skim through the project to familiarize yourself with the format, before tackling problems. Word to the wise: This project doesn't require a lot of actual programming. It does require understanding a body of code, however, and thus it will require careful preparation. You will be working with evaluators such as those described in chapter 4 of the text book, and variations on those evaluators. If you don't have a good understanding of how the evaluator is structured, it is very easy to become confused between the programs that the evaluator is interpreting, and the procedures that implement the evaluator itself. For this project, therefore, we suggest that you do some careful preparation. Once you've done this, your work in the lab should be fairly straightforward. Understanding the evaluator Load the code (meval.scm, then syntax.scm, finally environment.scm) for this project. These files contain a version of the meta-circular evaluator described inlecture and in the textbook. Because this evaluator is built on top of the underlying Scheme evaluator, we have called the procedure that executes evaluation m-eval (with associated m-apply) to distinguish it from the normal eval. You should look through these files to get a sense for how they implement a version of the evaluator discussed in lecture (especially the procedure m-eval). You will be both adding code to the evaluator, and using the evaluator. Be careful, because it is easy to get confused. Here are some things to keep in mind: When adding code to be used as part of meval.scm, you are writing in Scheme, and can use any and all of the procedures of Scheme. Changes you make to the evaluator are changes in defining the behavior you want your new evaluator to have. After loading the evaluator (i.e., loading the file meval.scm and any additions or modifications you make), you start it by typing (driver-loop). In order to help you avoid confusion, we've arranged that each driver loop will print prompts on input and output to identify which evaluator you are typing at. For example, ;;; M-Eval input: (+ 3 4) ;;; M-Eval value: 7 shows an interaction with the m-eval evaluator. To evaluate an expression, you type the expression and press ctrl-x ctrl-e. Don't use M-z to evaluate the expression; the presence of the prompt confuses the M-z mechanism. Also notice that if you have started up the evaluator in a *scheme* buffer, you may go to any other buffer, write definitions or expressions and evaluate them from that buffer. This will cause the expressions to be evaluated in the new evaluator. On the other hand, if you have not started up the evaluator, evaluating expressions from a buffer will cause them to be evaluated in the normal Scheme evaluator. The evaluator with which you are working does not include an error system. If you hit an error you will bounce back into ordinary Scheme. You can restart the driver-loop by running the procedure driver-loop. Note that the driver loop does not re-initialize the environment, so any definitions you have made should still be available if you have to re-run driver-loop. In case you do want a clean environment, you should evaluate (refresh-global-environment) while in normal Scheme. It is instructive to run the interpreter while tracing m-eval. (You will also probably need to do this while debugging your code for this assignment.)Since environments are, in general, complex circular list structures, we have set Scheme's printer so that it will not go into an infinite loop when asked to print a circular list. (See the descriptions of *unparser-list-depth-limit* and *unparser-list-breadth-limit* in the Scheme reference manual.) You will notice that when you have run driver-loop, the mode line (bar at the bottom of edwin with the buffer name, along with (Scheme: listen)) will display (Scheme Meval: listen) instead. This indicates that meval will be receiving anything you C-x C-e, instead of (regular) MITScheme. In order to give you further warning when you accidentally send things to Meval instead of MITScheme, the *warn-meval-define* variable controls whether Meval will print out warnings if the define you're evaluating is binding a variable that is also bound in MITScheme. Computer Exercise 1: Exploring Meval. Load the code files into your Scheme environment. To begin using the Scheme interpreter defined by this file, evaluate (driver-loop). Notice how it now gives you a new prompt, in order to alert you to the fact that you are now "talking" to this new interpreter. Try evaluating some simple expressions in this interpreter. Note that this interpreter has no debugging mechanism -- that is, if you hit an error, you will be thrown into the debugger for the underlying Scheme. This can be valuable in helping you to debug your code for the new interpreter, but you will need to restart the interpreter. You may quickly notice that some of the primitive procedures about which Scheme normally knows are missing in m-eval. These include some simple arithmetic procedures (such as *) and procedures such as cadr, cddr, newline. Extend your evaluator by adding these new primitive procedures (and any others that you think might be useful). Check through the code to figure out where this is done. In order


View Full Document

MIT 6 001 - The Meta-Circular Evaluator

Documents in this Course
Quiz 1

Quiz 1

6 pages

Databases

Databases

12 pages

rec20

rec20

2 pages

Quiz II

Quiz II

15 pages

Streams

Streams

5 pages

Load more
Download The Meta-Circular Evaluator
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The Meta-Circular Evaluator and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The Meta-Circular Evaluator 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?