* Semantic model: objects, environment, assignment, calls (draw pictures) ** Objects objects, are containers for data (other objects) *state + identity state = bits (for built-ins) or other objects identity, distinct for all objects (an address) created dynamically (on heap) indefinite lifetime (=> garbage collection) may contain other objects (i.e., references to others) *draw picture of a record record[re, im: real] *** Mutable objects state can vary over time e.g., arrays, records, variants allows state changes to be communicated to other parts of program (side-effects, aliasing) specify by abstract values, + object identity *** Immutable objects state cannot vary with time e.g., int, bool, sequence, struct, oneof, procedures identity does not matter, since aliasing cannot be observed specify just abstract values ** Environment (draw picture) maps names to variables (cells that contain refs to objects) does not map names to cells that contain values *** variables cell is changable ref. to an object are not themselves objects *** constants (equates) name is abbreviation for a wholly immutable object or a type washed out at compile time ** Assignment creates an alias, copies reference to object does *not* copy object itself ** Calling mechanism call by value, where value is always a reference to an object (call by sharing) assign value of argument to formals (makes aliases) ---------- % example showing mutation and aliasing addh_something = proc(a: array[int]) % MODIFIES: a % EFFECT: extend a by adding 5 to its high end array[int]$addh(a,5) end addh_something start_up = proc() % EFFECT: prints "3\n4\n5\n" on primary output x,y: array[int] x := array[int]$[1,2,3] y := x % makes x and y aliases stream$putl(po, int$unparse(array[int]$size(y))) array[int]$addh(x,4) % mutates object denoted by x po: stream := stream$primary_output() stream$putl(po, int$unparse(array[int]$size(y))) addh_something(y) stream$putl(po, int$unparse(array[int]$size(x))) end start_up ----------