(* ** Course: Concepts of Programming Languages (BU CAS CS 320) ** Semester: Summer I, 2009 ** Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu) *) // // Assignment three (Due: Monday, June 8, 2009) // // Total points: 180 points // (* ****** ****** *) staload "assignment3.sats" staload _(*anonymous*) = "assignment3_solu.dats" (* ****** ****** *) dynload "assignment3_solu.dats" (* ****** ****** *) val _(*assgn3ex3_test*) = () where { val xs = Emp (): ralist double #define N 10 // one way to print out a ralist fun printlst (xs: ralist double): void = begin try loop (xs) with ~Empty () => () end where { fun loop (xs: ralist double): void = let val (x, xs) = rauncons (xs); val- S f = x in print f; print_newline (); loop (xs) end // end of [loop] } (* end of [val] *) val xs = loop (N-1, Emp ()) where { fun loop (i: int, res: ralist double): ralist double = if i >= 0 then let val x = S (double_of_int i) in loop (i-1, racons (x, res)) end else res // end of [loop] } // end of [val] val () = print "xs=\n" val () = printlst (xs) // another way to print out a ralist fun printlst' (xs: ralist double): void = let fun loop (xs: ralist double, i: int): void = if i < N then let val- S f = ralookup (xs, i) val () = printf ("%i: %f\n", @(i, f)) in loop (xs, i+1) end (* end of [if] *) // end of [loop] in loop (xs, 0) end // end of [val] // val ys = loop (xs, 0) where { fun loop (xs: ralist double, i: int): ralist double = if i < N then let val x = S (double_of_int (N-1-i)); val xs = raupdate (xs, i, x) in loop (xs, i + 1) end else xs (* end of [if] *) // end of [loop] } (* end of [val] *) val () = print "ys=\n" val () = printlst' (ys) } (* end of [assgn3ex3_test] *) (* ****** ****** *) implement main () = () (* ****** ****** *) (* end of [assignment3_test.dats] *)