[skill 21.1] Consider the following two SML functions:
fun f1(nil,v) = nil
| f1(h::t,v) = if v=h then f1(t,v) else h::f1(t,v);
fun f2(a,0) = a
| f2(h::t,n) = f2(t,n-1)
| f2(nil,n) = nil;
Clearly describe what function f1 does
Give the type that will be inferred for f1 by the SML compiler
Clearly describe what function f2 does
Give that type that will be inferred for f2 by the SML compiler
try {
... /* Try block */
}
catch (E1 e) { ... /* Catch block */ }
finally {... /* Finally block */ }
print("After try"); /* print does not throw any exceptions */
For each of the following cases, indicate what code will be executed, in what order, and what exceptions, if any, will be thrown, and in what order. A block "terminates normally" if it does not throw any exceptions and does not execute a "return" statement.
All the blocks (if executed) will terminate normally.
The try block throws an exception of type E1, the catch block (if executed) will throw an exception of type E2, and the finally block (if executed) will terminate normally.
The try block executes a "return" statement, the catch block and finally blocks (if executed) terminate normally.
The try block terminates normally, the catch block (if executed) will throw an exception of type E2, and the finally block (if executed) will throw an exception of type E3.