Starting from:

$30

Homework 4: Scheme warming up

CSE 461: Programming Languages Concepts

Homework 4: Scheme warming up

Submission: you should submit via Canvas a DrRacket file with Scheme
code in. Please clearly mark your answers using comments so that we can
tell the correspondence between your code and questions.
1. (0 points) Go through a brief tutorial about the DrRacket programming environment at http://docs.racket-lang.org/drracket/index.
html. Be sure to change the language to R5RS.
2. (3 points) Code the Ackermann function in DrRacket, which is defined
as follows:
A(m, n) =



n + 1 if m = 0
A(m − 1, 1) if m > 0 and n = 0
A(m − 1, A(m, n − 1)) if m > 0 and n > 0
To check your result, use DrRacket to compute the result of A(3, 5),
which should be 253. You only need to submit your Scheme code for
the Ackermann function.
3. (3 points) John McCarthy is a famous computer scientist who designed
LISP. He once proposed a function called the McCarthy 91 function,
defined as follows:
Mac(n) = (
n − 10 if n > 100
Mac(Mac(n + 11)) if n ≤ 100
Write this function in Scheme. Try calling the function with a few
numbers less than 100 and see what the results are.
4. (3 points) Some credit-card companies pay back a small portion of the
charges a customer makes over a year. One company returns
(a) 0.5% for the first $1000 of charges,
1
(b) 0.75% for the next $1000 (that is, the portion between $1000 and
$2000),
(c) 1.0% for the next $1500 (that is, the portion between $2000 and
$3500),
(d) and 1.5% for everything above $3500.
Thus, a customer who charges $400 a year receives $2, which is 0.5% *
400, and one who charges $1,400 a year receives $8, which is 5 = 0.5%
* 1000 for the first $1000 and 0.75% * 400 = 3 for the next $400.
Define the function payback, which consumes a charge amount and
computes the corresponding pay-back amount.
2

More products