(* comment *)
(* SYNTAX
this is variable binding
val is a keyword
x is a variable name
= is used as a keyword here
34 is an expression
; is used as a keyword here (different meanings in different places)
*)
val x = 34;
(* static environment: x --> int
dynanmic environment: x --> 34
*)
val y = 17;
(* static environment: x --> int, y --> int
dynamic environment: x --> 34, y --> 17
*)
(* e1 + e2 *)
val z = (x + y) + (y + 2);
(* static environment: x --> int, y --> int, z --> int
dynamic environment: x --> 34, y --> 17, z --> 70
*)
val q = z + 1;
val abs_of_z = if z < 0 then 0 - z else z;
(* static environment: x --> int, y --> int, z --> int, q --> int, abs_of_z --> int
dynamic environment: x --> 34, y --> 17, z --> 70, q--> 71, abs_of_z --> 70
*)
(* conditional expressions
SYNTAX: if e1 then e2 else e3 where e1, e2, and e3 are expressions
TYPE-CHECKING RULES:
* e1 has to have type bool
* e2 has to have some type t
* e3 has to have some type t
* the overall type is t
EVALUATION RULES:
* evaluate e1 to some value v1 (it will have type bool)
* if v1 is true, then evaluate e2 -- and that's our answer!
* if v1 is false, then evaluate e3 -- and that's our answer!
*)
(* less-than expressions
SYNTAX: e1 < e2 where e1 and e2 are expressions
TYPE-CHECKING:
* e1 has to have type int
* e2 has to have type int
* the overall type is bool
EVALUATION RULES:
* evaluate e1 to a value v1 (it will be a number)
* evaluate e2 to a value v2 (it will be a number)
* result is true if v1 is less than v2 else false
*)