Unformatted text preview: subset language and evaluate it. That’s the job of calc-eval . (We use the names calc-eval and calc-apply in this program because STk has primitive procedures called eval and apply , and we don’t want to step on those names. The STk procedures have jobs exactly analogous to the ones in calc , though; every interpreter for any Lisp-family language has some form of eval and apply .) Once we get the value from eval , what do we want to do with it? We want to show it to the user by printing it to the display. That’s the job of print . So now you understand why it’s a “read-eval-print” loop! Read an expression, evaluate it, and print its value. Finally, the procedure ends with a recursive call to itself, so it loops forever; this is the “loop” part of the REPL. Notice that read and print are not functional programming; read returns a different value each time it’s called, and print changes something in the world instead of just returning a value. The body of the REPL has more than one expression; Scheme evaluates the expressions in order, and returns the value of the last...
View Full 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.
- Spring '10