Variable arity

Course links

Exercise 1

Have DrScheme evaluate each of the calls to slam that was proposed in the reading. Explain the results and make sure that they agree with the predicted results (if not, make appropriate corrections!).

Exercise 2

Develop a procedure named acronym that takes any number of non-null strings as arguments and returns one string consisting of the initial characters of those strings, thus:

> (acronym "Mothers" "Against" "Drunk" "Driving")
"MADD"

Exercise 3

Develop a procedure named call-arity that takes any number of arguments and returns the number of arguments it received (ignoring their values):

> (call-arity 'a #\b "c" '(d))
4
> (call-arity 0.0)
1
> (call-arity)
0

Exercise 4

Define and test a procedure clicker that takes one or more arguments, of which the first must be an exact integer and each of the others must be either the symbol 'up or the symbol 'down. Clicker should start from the given integer, add 1 for each 'up argument, subtract 1 for each 'down argument, and return the result:

> (clicker 17 'up 'up)
19
> (clicker -12 'down 'up 'down 'down 'down)
-15
> (clicker 100)
100

Exercise 5

Develop a procedure called enforce-arity-sum that takes numbers as arguments and returns their sum if it is given exactly two, three, or four arguments, but invokes error if it is given no arguments, one argument, or five or more arguments.

The principal author of this lab is Professor Henry Walker. I am also indebted to Professor Ben Gum for his contributions to its development.