33-Little-Scheme-Basics

33-Little-Scheme-Basics - CS106X Autumn 2010 Handout 33...

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

View Full Document Right Arrow Icon
CS106X Handout 33 Autumn 2010 November 17 th , 2010 Little Schemer Basics Your final assignment is going out as Handout 34, and that assignment challenges you to extend a working expression evaluator that speaks a small subset of the Scheme language. The point of the assignment is to give you practice with programming languages and inheritance, but we don’t need to learn the full Scheme language in order to do that. Instead, we’ll focus on a core subset of the language—a subset small enough to learn in a day or two—and in the process see how phenomenally powerful such a small language can be. We’re calling our language Little Scheme , and the interpreter you’re building is being dubbed the little-schemer . Getting Started little-schemer , like virtually all Scheme environments, operates much like the expression evaluator I demoed in lecture, in that you type in expressions, hit return, and expect the expression’s evaluation to be published as the response. You interact with the little environment by typing something in and then allowing little-schemer to read what you typed, evaluate it, and publish a result. Sometimes, what you type is so trivial that the result is precisely what you typed in. little-schemer 1> 14 14 little-schemer 2> 4/5 4/5 little-schemer 3> 1803/2404 3/4 little-schemer 4> "CS106X" "CS106X" little-schemer 5> "Stanford University" "Stanford University" little-schemer 6> true true little-schemer 7> false false You’re shouldn’t be impressed yet, but there really is an intellectually compelling explanation for what just happened: Everything you type in has to evaluate to a single value. When the expressions we type in are constants, little-schemer spits them right back at you. Constants (be they integer, fraction, string, or Boolean) evaluate to themselves. In general, you’ll get the interpreter to do some work for you. By typing out more elaborate expressions involving a function call, Scheme evaluates the call and eventually prints its evaluation.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 little-schemer 1> (add 1 2 3 4 5 6 7 8 9 10) 55 little-schemer 2> (multiply 1 2 3 4 5) 120 little-schemer 3> (subtract 100 17) 83 little-schemer 4> (add) 0 little-schemer 5> (multiply) 1 little-schemer 6> (add 32 (multiply 9/5 100)) 212 little-schemer 7> (add 32 (multiply 9/5 (subtract 0 40))) -40 Each of the seven examples above invoked some core mathematical built-in. All function names are required to be purely alphanumeric, which is why you see names like add and multiply instead of the more traditional + and * . We don’t support divide or the ability to type in negative fraction constants, because we’re trying to keep the core as small as possible to just illustrate how an interpreted language like little- scheme works. What
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2011 for the course CS 106X taught by Professor Cain,g during the Fall '08 term at Stanford.

Page1 / 10

33-Little-Scheme-Basics - CS106X Autumn 2010 Handout 33...

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