CS 61A Lecture Notes Week 5 Topic: Hierarchical data/Scheme interpreter Reading: Midterm 1 is this week. • Example: A Calculator Program Later in the course we’ll be studying several variants of a Scheme interpreter written in Scheme. As a Frst, small step in that direction, here is an interactive calculator that accepts arithmetic expressions in Scheme notation, but without variables, without the ability to deFne procedures, and with no data types other than numbers. Here’s how it works: STk> (load "~cs61a/lib/calc.scm") STk> (calc) calc: (+ 2 3) 5 calc: (+ (* 2 3) (* 4 5)) 26 calc: foo Error: calc: bad expression: foo The last example shows that there are no variables in this language. The entire program consists of three procedures in 30 lines of code. You should Fnd it easy to understand. And yet these three procedures exactly parallel the core procedures in a real Scheme interpreter: 1. The read-eval-print loop: interact with the user.
This is the end of the preview. Sign up
access the rest of the document.
This note was uploaded on 02/17/2010 for the course COMPUTER S 26275 taught by Professor Harvey,b during the Spring '10 term at Berkeley.