(* * rev-examples.sml * Dave Kauchak * * Some example sml functions playing with * function variants for reversing lists * *) (* version 1.0 of reverse *) fun rev [] = [] | rev (x::xs) = (rev xs) @ [x]; (* * our interval function from before for * testing rev with large lists *) fun interval m n = if n <= m then [] else m::(interval (m+1) n); fun revAux (acc, []) = acc | revAux (acc, x::xs) = revAux (x::acc, xs); fun rev2 lst = revAux ([], lst); (* version 2.0 that uses an auxiliary function *) fun rev2 lst = let fun revAux (u,[]) = u | revAux (u,x::xs) = revAux (x::u,xs); in revAux ([],lst) end;