(*trace*) (* A trace facility is imbedded into the remove function *) fun int_to_char i = chr(i+48); (* Given an integer i, 0<=i<=9, convert it to a character *) fun int_to_chars n = if n<10 then int_to_char n else let val r = n mod 10 in int_to_chars (n div 10) ^ int_to_char r end; fun liststring x = let fun ls [] = "]" |ls (n::nil) = (int_to_chars n) ^ "]" |ls (n::x) = (int_to_chars n) ^ "," ^ ls x in "[" ^ ls x end; fun remove (e:int) [] = [] |remove (e:int) (a::x) = (print ("remove " ^ (int_to_chars e) ^ " " ^ (liststring (a::x)) ^ "\n"); if e=a then remove e x else a::remove e x); (* remove 4 [1,2,3,5,6]; remove 4 [1,2,3,4,5,6,4,7,8]; *) (***** Counting recursive calls *****) val count = ref 0; fun member e [] = false |member e (a::x) = (count := !count + 1; e=a orelse member e x); (* alternatively ....... *) fun find e x = (count := !count + 1; if x = [] then false else e = (hd x) orelse find e (tl x));