notes30 - CS 61A Lecture Notes Week 5 Topic Hierarchical...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
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.
Background image of page 1
This is the end of the preview. Sign up to 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.

Ask a homework question - tutors are online