Comp 210 Lab 4: Accumulators

Hand Evaluation

Computing a scheme expression is just like computing an algebra expression: you keep simplifying an expression until you reach a value. The only difference is that in scheme, we've augmented our world with booleans and symbols, and we've taken the declaration of functions to a new level. The half-page Law of Scheme, is the full explanation of everything that scheme does.

"Hand-evaluation" just means, following the Law of Scheme by hand, to fully understand what it's doing.

Hand-evaluate the following (admittedly small-minded) expressions:

(define zz 93)

; Use the law for values, placeholders, built-in functions:
(* zz (+ 2 1))

; Use the law for cond:
(cond [(< zz 17) true]
      [true      false])
A few things to note:

Finally, let's practice the one more step of evaluating a function-applicationg for functions you've defined. Hand-evaluate:

;; less17?: number --> boolean
;; Is yy less than 17?
;; A long-winded example using cond, instead of just < !
;;
(define (foo yy)
  (cond [(< yy 17) true]
        [true      false]))

(less17? (* 1 zz))
Note that before less17? ever gets called, the initial * has already been evaluated, and less17? has no idea that the placeholder zz was ever involved in the input.

Another Data Definition

Biologist Gwynn Penn, of the Flightless Avian Research Center of Estonia, is studying penguins in antarctica. She flies over the Larsen ice shelf, counting penguins. (However, due to fog, some days she is grounded at McMurdo base.) She records her data as follows:

;; A datalist is:
;; - empty
;; - (cons [number] [datalist]) ; Number of penguins sighted.
;; - (cons 'fog     [datalist])

We'll write some programs to process her data. We already have the data definition given to us, so we'll follow the remaining steps of the design recipe. As a group:

We'll write the following functions. For each of them, we'll want the remaining steps of the design recipe (what are they?)