Procedure definitions

Course links

Exercise 1

One foot is equal to 761/2500 meters (exactly). Define a procedure named feet->meters that takes one argument, a real number representing a length measured in feet, and returns the number that represents the same length as measured in meters. Use this procedure to determine the number of meters in one mile (5280 feet).

Exercise 2

The price of admission to see a first-run movie at the Bijou Theatre is seven dollars for an adult, four for a child. Define a procedure named gross-receipts that takes two arguments, the number of adults and the number of children admitted, and returns the total amount that they paid for admission, in dollars. For instance, if the audience included exactly 112 adults and six children, the procedure should return the sum of 112 times seven and four times six, which is 808:

> (gross-receipts 112 6)
808

Use your procedure to determine the total admission for eighty-two adults and 146 children.

Exercise 3

In a figure-skating competition, judges have observed the competitors' performances and awarded three separate scores to each competitor: one for accuracy, one for style, and one for the difficulty of the chosen routine. Each score is in the range from 0 to 10. The rules of the competition specify that a competitor's three scores are to be combined into a weighted average, in which accuracy counts three times as much as difficulty and style counts twice as much as difficulty. The overall result should be a single number in the range from 0 to 10.

Write a comment in which you describe the nature and purpose of a procedure that takes three arguments -- a competitor's accuracy, style, and difficulty scores -- and returns their weighted average. Then define the procedure that you have described. Next, test your procedure, looking for cases in which the weighted average is computed incorrectly. (If you find any, make corrections in your definition.) Finally, save the procedure and documentation in an appropriately named file.

Exercise 4

Call each of the ``primitive'' Scheme predicates listed in the reading twice -- once with an argument that ensures that the value of the procedure call is #t, once with an argument that makes the value #f.

Exercise 5

In the reading, I said that not is a procedure in Scheme. What predicate could you call to verify this?

Exercise 6

The symbol not is the name of the procedure discussed in the preceding exercise, but the symbol itself, considered as a datum, is not a procedure. Does Scheme agree with this classification? How could one ask Scheme whether the symbol not is a procedure?

Exercise 7

Define a predicate bigger? that takes two real numbers as arguments and returns #t if the absolute value of the first is greater than the absolute value of the second, #f if it is not. Call your procedure twice -- once with arguments that ensure that the value of the procedure call is #t, once with arguments that make the value #f.

I am indebted to Professor Ben Gum for his contributions to the development of this lab.