[PLT logo] TeachScheme! 2002

July/August, 2002

Details for Wednesday afternoon




  Let's go back to the zoo.  We have animals, but now need lists of
  animals.

  A list-of-animal is
    - empty, or
    - (cons animal list-of-animal)

  An animal is 
    - a boa, or
    - a dillo

  [Some asked about whether should have a case in list-of-animal for
  each animal -- talked about limiting cases that we need to change
  when add animals -- demo this later in lecture]

  ;; animal-weights : list-of-animal -> list-of-number
  ;; produce list of weights of all animals

  This introduces helper function for animals (weight).  Wrote first
  without motivating how this derives from data, then showed it later.

  Add an animal :

  (define-struct tiger (name sells weight))
  (make-tiger 'Tony 'cereal 150)

  show how this affects data definitions and animal-weights.  Only
  change is in helper function weight.  Drove home point about two
  data definitions, two functions.

  PVD 2002: Our teachers got confused between "helper functions"
  arising from having two data definitions and helper functions that
  we write to separate out a new computation.  Be aware, point out the
  difference when appropriate, and try not to use the term "helper
  functions" for the data definition templates.  The important
  distinction is that one kind of function we know about (the
  possibility of) just when writing the template, without paying heed
  to behavior; the second kind arises *only* when we get deep into the
  actual implementation.

  ;; thin-animals : list-of-animal -> list-of-animal
  ;; produce list of animals that satisfy the too-thin? program from Tues.

  ;; lookup-food : symbol list-of-animal -> symbol or false
  ;; returns food of boa with given name in list or false if name not found

  [PVD 2002: lookup is tricky because the cons case needs a cond that
  checks something on the first animal in the list.  The teachers seem
  to want to push all work on the first into the animal data
  definition, including the cond that determines whether you've found
  the right animal.  That makes this a good example, but expect some
  confusion here]

  -----------------------------------------------------------------

  Structures in Lists: celestial bodies

  [PVD 2002 recommends dropping in favor of lookup-food on animals.
  This is a great example for demoing pictures in DrScheme, but a bit
  too hard for first celbody function.  Problem is that template
  suggests to do all processing of celbody in one helper, but
  find-photo needs a cond on celbodies in the list-of-celbody
  function.  This really confused people.  Ideally do a simpler first
  function that easily matches template (perhaps weight-on-all, which
  takes a weight on earth and a database and returns list of weights
  on each planet), then do this one -- takes too much time though.

  Moved pictures in structs to inventory problem]


[Point] LAB

Generated on: Saturday, July 20th, 2002