Recitation 1

Handouts: General info, Recitation signup sheet, Problem Set 0

Today's Idea: What an interpreter is

I explained administrative stuff, especially the collaboration policy and how you must attend tutorials. I recommended that you go to the lab even if you work mostly on your own computer so that you can meet other students and get advice from LAs.

I explained the difference between the computation model most of you are used to and the one we'll use in this course:
Compilation Model: compiler translates source file to executable; when executable is run, it reads inputs, changes state, writes outputs.
Interpretation Model: you give interpreter an expression; it evaluates it and gives you back a value.

I showed you MIT Scheme, our standard environment, and Dr Scheme, an environment developed at Rice.
To illustrate evaluation, we entered a collection of expressions into a Scheme interpreter:

• (+ 1 2)
• (* 3 5)
• (/ 2 3)  <-- Dr Scheme evaluated this differently
• (* (+ 1 2) 5)
• (> 4 3)
• (< 4 3)
• +
• (3)
• (if true 1 2)
• (if false 1 2)
• (if (> 4 3) 1 2)
• (if (> 4 3) + *)
• ((if (> 4 3) + *) 2 3)

•

We noticed that procedures are values just like numbers, and that parens are special -- they don't have the usual meaning of "grouping".

Then I explained how define "installs" values into the interpreter that later be referenced by name, and we played with this notion:

• (define x 2)
• (+ x 3)
• (+ y 4)
• (define y 5)

• (+ x y)

We saw how to install procedure values:

• (define (f a) (+ a 2))
• (f 3)
• (define a 5)
• (f 3)
• (define (g a) (+ a b))
• (g 3)
• (define b 4)
• (g 3)

•

You then wrote a procedure that computed the area of a disk with inner radius i and outer radius o. I showed you how to organize into in a modular way:

(define pi 3.14)
(define (sq x) (* x x))
(define (area r) (* pi (sq r)))
(define (disk-area inner outer)
(- (area outer) (area inner))
)

Daniel Jackson
September 8, 1999