
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Programming Languages; Subject: Computer Science; University: University of Texas - San Antonio; Term: Spring 2008;
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Translate the following tail recursive function in ML to an equivalent implementation using loops.
fun sum(input, res) = let val p_input=ref input; val p_res=ref res in while not (null (!p_input)) do (p_res := hd(!p_input) + (!p_res); p_input:=tl(!p_input)); !p_res end;
fun foo(x,y,z) = let val p_x = ref x; val p_y = ref y; val p_z=ref z in while not ((!p_x)=(!p_y)) do if ((!p_x) < (!p_y)) then p_x := (!p_x) + (!p_z) else if ((!p_y) < (!p_x)) then let val tmp=(!p_x) in p_x:=(!p_y); p_y:=tmp; p_z := (!p_z)-1 end else (); !p_y end;