(* OCaml compatibility *) let print_string (s: string) = System.Console.Write s let print_newline () = System.Console.WriteLine "" let string_of_float f = sprintf "%f" f (* /OCaml compatibility *) exception Unimplemented (* should not be raised after the assignment is done *) exception AlreadyDone (* for the small-step interpreter *) (*** part a ***) type move = Home (* | students: add more cases *) let makePoly sides len = raise Unimplemented let scale scalingFactor logoProgram = raise Unimplemented (*** part b ***) let interpLarge (movelist : move list) : (float*float) list = let rec loop movelist x y dir acc = match movelist with [] -> raise Unimplemented | Home::tl -> raise Unimplemented (* | students: add more cases *) in List.rev (loop movelist 0.0 0.0 0.0 [(0.0,0.0)]) (*** part c ***) let interpSmall (movelist : move list) : (float*float) list = let interpSmallStep movelist x y dir : move list * float * float * float = match movelist with | [] -> raise Unimplemented | Home::tl -> raise Unimplemented (* | students: add more cases! *) in let rec loop movelist x y dir acc = raise Unimplemented in List.rev (loop movelist 0.0 0.0 0.0 [(0.0,0.0)]) (*** part d ***) (* modify this comment *) (*** part e ***) let interpTrans movelist : float->float->float-> (float * float) list * float= let rec last lst = (* provided helper function -- useful in compose *) match lst with [] -> None | x::[] -> Some x | x::tl -> last tl in let compose f1 f2 = raise Unimplemented (* suggested helper function *) in match movelist with [] -> raise Unimplemented | Home::tl -> raise Unimplemented (* | students: add more cases *) (*** possibly helpful testing code ***) (* you do not have to use this "testing" code, but you might find it useful *) (* no need to change more than example_logo_prog *) let example_logo_prog = raise Unimplemented let ansL = interpLarge example_logo_prog let ansS = interpSmall example_logo_prog let ansT = (0.0,0.0)::(fst ((interpTrans example_logo_prog) 0.0 0.0 0.0)) let rec pr lst = match lst with [] -> () | (x,y)::tl -> print_string("(" + (string_of_float x) + "," + (string_of_float y) + ")"); pr tl let _ = pr ansL; print_newline (); pr ansS; print_newline (); pr ansT; print_newline ();