(*Assn99 - Coding Style Template for 15-212*) (*Name: Uland Y. Wong*) (*Andrew ID: UYW*) (*Section: C*) (*coding_standard.sml - file implementing the coding standard*) (*make sure you name your files EXACTLY the same as our templates and use the exact interfaces provided by our function stubs or you will receive 0 points.*) (*--Multi Line Comments -- indent after the first line and continue indentation until the last line of text*) (*--Make sure your code does not extend above 80 columns---------------------*) (*if-else statements*) if true then TextIO.print "true" else TextIO.print "false" (*let statements*) (*use if helper functions/values are used only by a single clause of the function calling function*) fun letFunc [] = [] | letFunc (a::b) = let (*comments above intermediate values*) val sum = Real.abs a val idx = Int.toString 5 in sum::(letFunc b) end (*local statements*) (*use if a helper function is common to all clauses of the calling function*) local (*helper function comments*) fun dosomething () = "a" in fun localFunc 0 = dosomething() | localFunc 1 = dosomething() | localFunc n = dosomething() end (*case statements*) (*use to deconstruct data types or to simplify complex if-else statements*) (case xList of [] => "nil" | [1,2,3] => "123" | [1,2,n] => "12-list" | [_,_,_] => "generic list of length 3" | (a::b) => "generic list" | _ => "wild card match" ) (*Some problems with current student code*) (*Do not overuse type annotations. Your code should work without them. If it does not, something is wrong.*) fun ridiculous (x:int) (y:int) : int = (x:int) + (y:int) : int (*Avoid excessive parentheses*) fun thisIsNotLisp (((a),(b))) = ((a) * (b)) val h = {a = 1, b = 2, c = 3} (*do not put comments here*) (*put spaces between infix operations and after commas*) val _ = TextIO.print ("I"^"can't"^"read"^"your"^"code") (*if your function has a lot of intermediate variables or a lot of pattern matches, use somewhat descriptive names for them*) fun hardToUnderstand (a::b::c) (f as (v::x::y)) = (b::x::c) @ [a] @ y @ f (*Make Sure your Proofs are Structured like the following*) (* 1.2) Proof: class 15-212 = "tough as nails" Method: Prove by Induction on the size of 15-212 lecture Base Case [x] = "got an f in 15-212" -the base case is satisfied Inductive Hypothesis Assume that a class of size n finds 15-212 tough as nails Inductive Step pain ("15-212","me") = "the" = "world" = "hates" by IH = "me" QED *) (*Dont let us catch you using any of the following unless specifically stated in the homework handout. -while loops -ref and bang -arrays -callcc -streams -anything else that's not purely functional *)