val biscuits = 3 + 4 * 5 div 7;
val together = fn(a, b, c) => a ^ b ^ c;
fun vegetable x = if x = "tomato" then "fruity!" else case x of "broccoli" => "yummy!" | "snap peas" => "okay" | "lettuce" => "useless" | _ => "try it";
When making a list, use the :: operator.
When making a list, use the bracket comma notation (e.g. [1,2,...])
val gorrillas = 20; val peach = #"b"; val donkeys = {legs=4, toes=29}; val gorrillas = #legs(donkeys);
val dogs = "beagle"::"pomeranian"::"terrier"::nil; val mammals = "dolphins"::"cats"::nil; val cuteAnimals = (hd(mammals),dogs);
val a = { dog = "Fido", colors = ["red", "blue", "yellow"], random = (334, 3.2, "hi"), pi = 3.14 }; val (b, b'::b'') = ( tl(#colors (a)), [6.3,7.0,8.3] ); val c = ( #2 ( #random (a) ), #pi(a) :: b'');
fun happy nil = "no turkeys!" | happy (a::b) = b;
fun happy nil = "no turkeys!" | happy (a::b::c) = Int.toString (a+b) ^ " baby turkeys";What happens if you try to run
happy [3]
? Why? How could you fix this?
val x = 4; val y = 3; val z = 2; let val x = 1; val y = x + x; val z = y * z; in x + y + z end; (* A: What is the value of this let expression?*) val a = 10; val b = let val a = 2; val b = a + a; in a * b end + a; (* B: What is the value of this let expression? What is its value after summing it with a as shown here?*) val atLast = x + y + z + a + b; (* C: What is the value of atLast? *)