CSC 533: Organization of Programming Languages
HW5: Scheme Programming
For this assignment, you are to define the following Scheme functions. For
simplicity, place all of your function definitions in a single file named
hw5.scm. Be sure to comment each function as to its behavior.
- Define functions for converting temperatures from Fahrenheit to Celsius,
and vice versa. For example, (fahr->celsius 212) should evaluate to
100, while (celsius->fahr 0) should evaluate to 32. The formula for
converting from Fahrenheit to Celsius is:
tempInCelsius = (5/9) * (tempInFahrehneit - 32)
- Define a function named wind-chill that takes two inputs, a
temperature (in degrees Fahrenheit) and a wind-speed (in miles per hour), and
returns the corresponding wind-chill factor. The formula for computing the
wind chill is:
| wind-chill =
|| if wind <= 3
| 35.74 + 0.6215*temp + (0.4275*temp - 35.75)*
For example, (wind-chill 38 2) should evaluate to 38 since a
wind-speed of only 2 miles per hour has no effect on the temperature of
38 degrees Fahrenheit. Note: the return value for this
function should be inexact.
- Define a function named num-occur that takes two inputs, an atom
and a list, and returns a count of the number of times the atom appears in the
list. For example, (num-occur 'x '(z x e x)) should evaluate to 2.
- Define a function named remove that takes two inputs, an atom
and a list, and returns the list with each occurrence of the atom removed.
For example, (remove 'x '(z x e x)) should evaluate to (z
- Define a function named subst that takes three inputs, two atoms
and a list, and returns the list with each occurrence of the second atom
replaced by the first. For example, (subst 'a 'x '(z x e x)) should
evaluate to (z a e a).
- Define a function named prime? that takes one input, a positive
integer, and returns #t if that number is prime, else #f.
For example, (prime? 6) should evaluate to #f, while
(prime? 7) should evaluate to #t. Your function should only
utilize tail-recursion (perhaps a help function will be required).