Paradigms_of_Programming (4)
Paradigms_of_Programming (4)
OOPs! Side-effects
Sameness and Change
1 / 19
set!
OOPs! Side-effects
Sameness and Change
1 / 19
set!
OOPs! Side-effects
Sameness and Change
2 / 19
set!
OOPs! Side-effects
Sameness and Change
2 / 19
set!
OOPs! Side-effects
Sameness and Change
2 / 19
set!
OOPs! Side-effects
Sameness and Change
3 / 19
set!
OOPs! Side-effects
Sameness and Change
3 / 19
set!
OOPs! Side-effects
Sameness and Change
4 / 19
set!
OOPs! Side-effects
Sameness and Change
4 / 19
set!
OOPs! Side-effects
Sameness and Change
This was the only instance in the past several lectures, where we
encountered a procedure that had explored the idea that “running a
procedure with the same operands could produce different results”.
5 / 19
set!
OOPs! Side-effects
Sameness and Change
This was the only instance in the past several lectures, where we
encountered a procedure that had explored the idea that “running a
procedure with the same operands could produce different results”.
5 / 19
set!
OOPs! Side-effects
Sameness and Change
6 / 19
set!
OOPs! Side-effects
Sameness and Change
7 / 19
set!
OOPs! Side-effects
Sameness and Change
Examples
1. modifying a non-local variable,
2. modifying a static local variable (like in case of let),
3. modifying a mutable argument passed by reference,
4. performing I/O or calling other functions with side-effects.
9 / 19
set!
OOPs! Side-effects
Sameness and Change
However using set! one can create situations where different order
of evaluation for an expression can produce different results.
10 / 19
set!
OOPs! Side-effects
Sameness and Change
11 / 19
set!
OOPs! Side-effects
Sameness and Change
12 / 19
set!
OOPs! Side-effects
Sameness and Change
13 / 19
set!
OOPs! Side-effects
Sameness and Change
14 / 19
set!
OOPs! Side-effects
Sameness and Change
After adding set! to the language, we gain the ability to figure out
whether a and b are two entities or not, as changing one entity did
not change the other entity.
15 / 19
set!
OOPs! Side-effects
Sameness and Change
But how can we tell if a single object has “changed” other than by
observing the “same” object twice and seeing whether some
property of the object differs from one observation to the next?
Thus,
we cannot determine sameness (of two objects) without observing
the effects of change and
we cannot determine “change” (of a single object) without some a
priori notion of “sameness,”
16 / 19
set!
OOPs! Side-effects
Sameness and Change
17 / 19
set!
OOPs! Side-effects
Sameness and Change
19 / 19