Spring 2002, CSE 428: Quiz 8.3 - 4 April 2002
Please write your Name, Student ID, and Section at the top of the
page. By default, this quiz will be return in section 1
(afternoon section). If you want to get it back in the
morning section, please write "return in section 2" at the top.
- [Points 2]
Which of the following best describes a trait specific to functional
programming languages? Pick only one answer.
- They make extensive use of state and side-effects.
- They have garbage collectors.
- They have strong typing.
- They are organized around the mathematical notion of function and
function application.
- [Points 3]
The following code describes a function in SML.
fun g nil = 0
| g ((x,y)::k) = x * y + (g k);
What function is computed by g?
- The function that takes a list of pairs of numbers and returns the
sum of the product of the pairs.
- The function takes a list and always returns 0.
- It does not define a function since it causes a type error.
- It does not define a function since it causes a match exception error.
- [Points 3]
What is the value computed for the following expression? 19
let val x = 15
in let val x = 2
in x * x
end
+ x
end;
- [Points 2]
What happens when SML is given the following code?
fun f 0 = 0
| f n = f(n - 1) - 1;
- Gives a type error.
- Defines a function which when applied to an integer, returns the
squares that integer.
- Defines a function which when applied to a non-negative
integer n, returns the negative of n.
- Defines a function that loops forever when applied to 1.
There was a typo in this last question: the word "negative" was not
in the third choice, even though this was the only correct answer.
Every one will get an automatic 2 points for this question
independently of their answer.