Kind of expression | Examples | How to evaluate |
---|---|---|
Value | 17, true, 'arugula | You have the value already. |
Placeholder | pi, + | Get its defined value. |
Function application | Evaluate the subexpressions
|
|
Special form |
|
various, but not shocking |
Note that the first part, about placeholders, explains why we see the test output as we do, when we write (times-served empty) = 0. Note that a slightly nicer way to write your test cases could be: (= (times-served empty) 0). (What would print out?)
Note anything familiar? The rules of evaluation are recursive. If you wanted, you could make your own data definitions to represent (your versions of) numbers, placeholders, function-call, and define; then you could use the design recipe, and write a scheme evaluator -- the core of drscheme -- yourself! (After seeing mutually-recursive data structures next week, this is a reasonable week-4 scheme homework (book exercises 14.4.1 -- 4 and 17.7.1 -- 4). Elegance speaks for itself!
Note: Over the rest of the semester, we will learn (just) three more special forms. (The formal definition of the corresponding part of C++ or Java requires about dense 30 pages, instead of 1. Those specifications have also been found to contain inconsistencies and errors, which have taken a long time to get revised.)
For evil souls: Add in
(define + -)
, or (define cons rest)
,
at the beginning of your friend's program!