CS 2010 Homework 3   - Due September 9

Setup

There is no setup for this assignment.

Assignment

Exercise 3.1, Lions

The relevant properties of a lion are, in order

  1. The number of teeth it has
  2. The name of the person it most recently ate (maybe 'no-one)

Here is a data definition and structure definition:

; A lion is
;   (make-lion num sym)
(define-struct lion (teeth ate))

Implement the function more-scary-lion, which takes a lion and produces a lion with two additional teeth (but the same stomach contents).

Exercise 3.2, and Tigers

Design a representation for tigers, where the relevant properties of a tiger are

  1. The number of stripes it has
  2. The length of its claws in centimeters
  3. The name of the person it most recently ate (maybe 'no-one)

Use tiger as the name of your structure, and put the fields in the above order.

Implement the function more-scary-tiger, which takes a tiger and produces a tiger (with the same fur pattern and stomach contents) whose claws are one centimeter longer.

Exercise 3.3, and Bears

Design a representation for bears, where the relevant properties of a bear are

  1. Its fur color, as a symbol
  2. The name of the person it most recently ate (maybe 'no-one)

Use bear as the name of your structure, and put the fields in the above order.

Implement the function more-scary-bear, which takes a bear and produces a bear (with the same fur color) that hasn't eaten recently.

Exercise 3.4, Oh My!

Define the data type oz-animal, which is a lion, tiger, or bear.

Implement the function more-scary-oz-animal, which takes an oz-animal and produces a scarier animal (as above).

Exercise 3.5, Erp

Define the function feed-oz-animal that takes two arguments: an oz-animal and a sym for a person's name. The result should be an oz-animal that just ate the person whose name is given.

Exercise 3.6, Rescue

Define the function rescue-from-animal that takes an oz-animal and returns an oz-animal that hasn't recently eaten anyone.

Hint: the answer should be especially short, and it should use the name 'no-one.

Exercise 3.7, Oz Scenes

An Oz scene consists of one person and one oz-animal. It is represented as an oz-scene:

; An oz-scene is
;  (make-oz-scene sym oz-animal)
(define-struct oz-scene (person animal))

Implement the function more-scary-scene, which takes an oz-scene and produces one with a scarier animal and the same person.

Exercise 3.8, A Wizard of Oz

An Oz scene moves the next scene as follows:

Implement the function next-scene, which takes an oz-scene and returns the next oz-scene according to the rules above.

Don't forget to break up the problem into smaller pieces. For example, you might find am animal-ate function useful (that takes an animal and returns the person that the animal recently ate).


Last update: Wednesday, September 3rd, 2003
mflatt@cs.utah.edu