X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=week9.mdwn;h=2e80250ead666ebf3da6a14583f085013ba5140f;hp=913e4bf75d91269a951092ed48e2540f8a35922d;hb=c3527b5c0340237490f677e875a006bbf7219360;hpb=279ca93246cad2d4ad11ac33887df3bb9cc97759 diff --git a/week9.mdwn b/week9.mdwn index 913e4bf7..2e80250e 100644 --- a/week9.mdwn +++ b/week9.mdwn @@ -100,7 +100,13 @@ Scheme is similar. There are various sorts of reference cells available in Schem (set-box! ycell 3) (+ x (unbox ycell))) -(C has explicit-style mutable variables, too, which it calls *pointers*. But simple variables in C are already mutable, in the implicit style.) +C has explicit-style mutable variables, too, which it calls *pointers*. But simple variables in C are already mutable, in the implicit style. Scheme also has both styles of mutation. In addition to the explicit boxes, Scheme also lets you mutate unboxed variables: + + (begin + (define x 1) + (set! x 2) + x) + ; evaluates to 2 When dealing with explicit-style mutation, there's a difference between the types and values of `ycell` and `!ycell` (or in Scheme, `(unbox ycell)`). The former has the type `int ref`: the variable `ycell` is assigned a reference cell that contains an `int`. The latter has the type `int`, and has whatever value is now stored in the relevant reference cell. In an implicit-style framework though, we only have the resources to refer to the contents of the relevant reference cell. `y` in fragment [G] or the C snippet above has the type `int`, and only ever evaluates to `int` values.