week9 tweak
authorJim Pryor <profjim@jimpryor.net>
Sun, 21 Nov 2010 19:27:56 +0000 (14:27 -0500)
committerJim Pryor <profjim@jimpryor.net>
Sun, 21 Nov 2010 19:27:56 +0000 (14:27 -0500)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
week9.mdwn

index dbabb6d..145833d 100644 (file)
@@ -224,7 +224,19 @@ Notice in these fragments that once we return from inside the call to `factory`,
 
 ##Referential opacity##
 
-In addition to order-sensitivity, when you're dealing with mutable variables you also give up a property that computer scientists call "referential transparency." It's not obvious whether they mean exactly the same by that as philosophers and linguists do, or only something approximately the same. What they do mean is a kind of substitution principle, illustrated here:
+In addition to order-sensitivity, when you're dealing with mutable variables you also give up a property that computer scientists call "referential transparency." It's not obvious whether they mean exactly the same by that as philosophers and linguists do, or only something approximately the same.
+
+The core idea to referential transparency is that when the same value is supplied to a context, the whole should always evaluate the same way. Mutation makes it possible to violate this. Consider:
+
+       let ycell = ref 1
+               in let f x = x + !ycell
+                       in let first = f 1      (* first is assigned the value 2 *)
+                               in ycell := 2; let second = f 1 (* second is assigned the value 3 *)
+                                       in first = second;; (* not true! *)
+
+Notice that the two invocations of `f 1` yield different results, even though the same value is being supplied as an argument to the same function.
+
+Computer scientists also associate referential transparency with a kind of substitution principle, illustrated here:
 
        let x = 1
                in (x, x)
@@ -249,6 +261,8 @@ Notice, however, that when mutable variables are present, the same substitution
        (* then creates a *new* ref 1 cell and returns *its* contents *)
 
 
+
+
 ##How to implement explicit-style mutable variables##
 
 We'll think about how to implement explicit-style mutation first. We suppose that we add some new syntactic forms to a language, let's call them `newref`, `deref`, and `setref`. And now we want to expand the semantics for the language so as to interpret these new forms.