When you load the code for this problem set, the entire TOOL interpreter code (attached) will be loaded into Scheme. However, in order to do the programming assignment, you will need to modify only a tiny bit of the interpreter. This code has been separated out in the file ps10-mod.scm, so you can edit it conveniently. (You may also need to define some auxiliary procedures.)
To start the TOOL interpreter, type (initialize-tool). This initializes the global environment and starts the read-eval-print loop. To evaluate a TOOL expression, type the expression after the prompt, followed by CTRL-x CTRL-e.
In order to keep the TOOL interpreter simple, we have not provided any mechanism for handling errors. Any error (such as an unbound variable) will bounce you back into Scheme's error handler. To get back to TOOL, quit out of the error and restart the driver loop by typing (driver-loop). If you make an error that requires reinitializing the environment, you can rerun initialize-tool, but this will make you lose any new classes, generic functions, or methods you have defined.
(define-method - ((x <number>)) (- 0 x)) (define-generic-function square) (define-method square ((x <object>)) (* x x))
Check the 6.001 discussion forum for computer-ex-01
Look here
for information about the forum.
| |
Check the 6.001 discussion forum for computer-ex-02
Look here
for information about the forum.
| |
(define-generic-function 4-legged?)before we could evaluate
(define-method 4-legged? ((thing <object>)) 'Who-knows?)If we hadn't done this, the second expression would have given the error that 4-legged? is undefined. Modify the TOOL interpreter so that, if the user attempts to define a method for a generic function that does not yet exist, TOOL will first automatically define the generic function. One thing to consider: In which environment should the name of the generic function be bound: the global environment, the environment of the evaluation? some other environment? There is no ``right answer'' to this question-- you are the language designer. But whatever choice you make, write a brief paragraph justifying your choice. In particular, include an example of a program for which the choice of environment matters, i.e., where the program would have a different behavior (or perhaps give an error) if the choice were different. (Hint: The only procedure you should need to modify for this exercise is eval-define-method.) Turn in, along with your design justification, your modified code together with a brief interaction showing that the modified interpreter works as intended.)
Check the 6.001 discussion forum for computer-ex-03
Look here
for information about the forum.
| |
Check the 6.001 discussion forum for computer-ex-04
Look here
for information about the forum.
| |
Check the 6.001 discussion forum for computer-ex-05
Look here
for information about the forum.
| |