Practice: Functions on Atomic Data

by Matthias Felleisen

If you aren't quite sure about functions and atomic data or you just want to practice, design the following functions:
  1. sales-tax, which consumes a price (number) and computes the MA sales tax.
  2. total, which consumes a price (number) and computes what the item really costs once the sales tax is added
  3. distance, which computes how far a car has driven from the given number of hours. Originally the car was 10 miles from downtown Boston; it drives at 55 miles per hour, on a straight line away from Boston.
  4. dist, which adds the squares of the given two numbers and takes the root.
  5. ave, which computes the average of three numbers.
  6. good-width, which determines whether a given string is longer than (or equal) to some give number.
  7. ekwal?, which determines whether a given string is equal to some give symbol.
  8. mensch, which determines how many of two given Booleans are true; hints: this requires cond and you should definitely twice about copying and modifying code.
  9. yes/no->boolean, which consumes "yes" and "no" answers (probably via an interaction with a person) and translates those into appropriate Booleans.
  10. boolean->yes/no, which consumes a Boolean and translate it into "yes" or "no" answers.
"Design" means you do follow the design recipe.

You should be able to design those functions in 30 minutes. If you aren't, make up more exercises along those lines and practice. These kind of things must be at your finger tips by now. If you need such exercises and you can't make them, see the TAs during their office hours and ask them for suggestions.