Commit 95befce2 by Pietro Abate

### [r2004-07-11 00:24:29 by beppe] A page of exercises

```Original author: beppe
Date: 2004-07-11 00:24:29+00:00```
parent 531994a4
 Exercises

You can cut and paste the code on this page and test it on the online interpreter.

Write a function that implements //t without using references types and xtransform

1. Give a non tail-recursive version
2. Give a tail-recursive version

Write a non recursive function of type Int -> Latin1 which given a non-negative number produces all its digits in the order.

The function is given below nearly completely programmed. Define the patterns that allows to produce the result.

%%RESULT%% ;; ]]>

Example:

Note here that the recursive function f is wrapped by a second anonymous function so that it does not expose the recursion variable.

(k&[Any*]) ;t] -> f( accu@[h], k@t) | [ <_>(k&[Any*]) ;t] -> f( accu, k@t) | [ h&T ;t] -> f( accu@[h], t) | [ _ ;t] -> f( accu, t) | [] -> accu in f ([], e);; ]]>

Note that this implementation may generate empty branch warnings in particular

• for the first branch if T&<_>(k&[Any*]) is Empty
• for the second branch if <_>(k&[Any*]) is smaller than T&<_>(k&[Any*])
• for the first branch if t is smaller than <_>(k&[Any*])
s0 @ s1 @ s2 @ s3 @ s4 @ s5 @ s6 @ s7 @ s8 @ s9 | _ -> raise "Invalid argument for sortAlg." ;; ]]>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!