Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: M ETA C IRCULAR E VALUATOR 17 GEORGE WANG gswang.cs61a@gmail.com Department of Electrical Engineering and Computer Sciences University of California, Berkeley July 20, 2010 Introduction One thing that comes up is that you might think that its best to write an evaluator that is designed to read in a easy language, but also to use a really powerful language that is capable of dealing with complex structures and dealing with symbols. However, it turns out that these two languages can be the same language. Furthermore, we can use Scheme for both of these, since its structure of syntax is simple to parse, and it is great at handling symbols. One important question to address is why its useful to write a Scheme compiler in Scheme, since obviously youd have to have something that reads that in the first place. First of all, theres a good pedagogical reason for doing it. By doing so, you will have a much stronger image of how something like that works, as well as have a good idea of how Scheme itself works. Well be implementing the page of code that is essentially our rules for evaluating environment diagrams. Secondly, it turns out much of Scheme itself is implemented in Scheme. Once you get out of memory management and such, it turns out a lot of STk is actually written in Scheme as well. Thirdly, we will be able to add new features and change fundamentally the way Scheme works for us. Lastly, theres a very very powerful idea, which is called UNIVERSALITY. Universality means we can write one program thats equivalent to all other programs that can ever be written. At the hardware level, this is the idea that made general-purpose computers possible. It used to be that they built a separate machine, from scratch, for every new problem. An intermediate stage was a machine that had a patchboard so you could rewire it, effectively changing it into a different machine for each problem, without having to re- manufacture it. The final step was a single machine that accepted a program as data so that it can do any problem without rewiring. This is the ultimate in data-directed programming. 1 1 First Version: Echo Lets write this first version, that doesnt do anything interesting, except read your input and spit it back out at you. You also cant actually quit out of it... ;cs61a/lectures/mceval/mc-eval-step1.scm (define (input-loop) (display "=61A=> ") (print (mc-eval (read))) (input-loop) (define (mc-eval exp) exp) So this is pretty dumb, but it introduces two things. It has a way of reading input from the user, as well as a procedure that is supposed to evaluate what an expression evaluates into. 2 Second Version: Self-Evaluating, Primitives Lets look at the things that Scheme can handle. We know that there are kind of atoms (self-evaluating and symbols) as well as lists (special forms and procedure calls). In this second version, lets just try to build a basic calculator. In other words, in terms of self-evaluating things, well say that for numbers, their valuebasic calculator....
View Full Document

This note was uploaded on 08/14/2010 for the course EECS 61A taught by Professor Harvey during the Summer '08 term at University of California, Berkeley.

Page1 / 7


This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online