ss@arovane % sml ~ Standard ML of New Jersey v110.52 [built: Fri Jan 21 16:42:10 2005] - (* 3.1.1 *) - fun cube(x:real) = x*x*x; val cube = fn : real -> real - cube(3.0); val it = 27.0 : real - fun smallest((l:int,m:int,n:int)) = = if l < m then = Interrupt - fun smallest((l:int,m,n)) = = if m < n then = if l < m then l = else m = else = if l < n then l else n; val smallest = fn : int * int * int -> int - smallest(3,7,4); val it = 3 : int - fun thirdElementOfList(L) = hd(tl(tl(L))); val thirdElementOfList = fn : 'a list -> 'a - thirdElementOfList([3,5,7]); val it = 7 : int - thirdElementOfList([1,2,3,4,5,6,7,8,9]); val it = 3 : int - fun reverse((x,y,z)) = (z,y,x); val reverse = fn : 'a * 'b * 'c -> 'c * 'b * 'a - fun thirdChar(s:string) = hd(tl(tl(explode(s)))); val thirdChar = fn : string -> char - thirdChar("test string."); val it = #"s" : char - thirdChar("ABCDEF"); val it = #"C" : char - fun cycle1(L) = tl(L)@[hd(L)]; val cycle1 = fn : 'a list -> 'a list - cycle1([1,2,3,4,5]); val it = [2,3,4,5,1] : int list - (* 3.1.2 *) - fun slpair(l:int,m,n) = = if l int * int - slpair(2,3,4); val it = (2,4) : int * int - slpair(1,10,100); val it = (1,100) : int * int - fun round10th(x:real) = (round(x) div 10) * 10; val round10th = fn : real -> int - round10th(24.56); val it = 20 : int - round10th(25.12); val it = 20 : int - round(25.12); val it = 25 : int - 25.12/10.0; val it = 2.512 : real - fun del2nd(L) = hd(L)::tl(tl(L)); val del2nd = fn : 'a list -> 'a list - del2nd([1,2]); val it = [1] : int list - del2nd(explode("abcDEF")); val it = [#"a",#"c",#"D",#"E",#"F"] : char list - (* 3.1.3 *) - val a = 2; fun f(b) = a*b; val b = 3; fun g(a) = a+b; val a = 2 : int val f = fn : int -> int val b = 3 : int val g = fn : int -> int - f(4); f(4) + b; g(5); g(5) + a; f(g(6)); g(f(7)); (* 8, 11, 8, 10, 18, 17 *) val it = 8 : int val it = 11 : int val it = 8 : int val it = 10 : int val it = 18 : int val it = 17 : int -