tweaks
[lambda.git] / topics / week13_native_continuation_operators.mdwn
index 95defac..366e3c1 100644 (file)
@@ -139,12 +139,14 @@ That was all *delimited* continuation operators. There's also the **undelimited
 
 returns `101`, whereas:
 
-    (reset (+ 10 (shift k 1)))
+    (reset (+ 100 (shift k 1)))
 
 only returns `1`. It is possible to duplicate the behavior of `let/cc` using `reset`/`shift`, but you have to structure your code in certain ways to do it. In order to duplicate the behavior of `reset`/`shift` using `let/cc`, you need to also make use of a mutable reference cell. So in that sense delimited continuations are more powerful and undelimited continuations are sort-of a special case.
 
 (In the OCaml code above for using delimited continuations, there is a mutable reference cell `reset_label`, but this is just for convenience. Oleg's library is designed for use with _multiple_ reset blocks having different labels, then when you invoke `shift` you have to specify which labeled reset block you want to potentially skip the rest of. We haven't introduced that complexity into our discussion, so for convenience we worked around it in showing you how to use `reset` and `shift` in OCaml. And the mutable reference cell was only playing the role of enabling us to work around the need to explicitly specify the `reset` block's label.)
 
+You may have noticed in some of our Scheme code we had the preface `(require racket/control)`. You don't need to do anything special (in Racket) to use `call/cc` or `let/cc`, but you do need that preface to be able to use `reset` and `shift` and `abort`.
+
 ## Examples of using these continuation operators ##
 
 Here are some examples of using these different continuation operators. The continuation that gets bound to `k` will be in bold. I'll use an OCaml-ish syntax because that's easiest to read, but these examples don't work as-is in OCaml. The `reset`/`shift` examples need to be massaged into the form displayed above for OCaml; and the `let/cc` examples don't work in OCaml because that's not provided. Alternatively, you could massage all of these into Scheme syntax. You shouldn't find that hard.
@@ -153,13 +155,14 @@ Here are some examples of using these different continuation operators. The cont
     This evaluates to `111`. Nothing exotic happens here.
 
 2.  <pre><b>100 + </b>let/cc k (10 + k 1)</pre>
-    This evaluates to `101`. See also example 11, below.
+    `k` is again bound to `100 + < >`. Note that after invoking `k 1`, the rest of the body of `let/cc k ( ... )` is discarded, so the result is simply `101`. See example 11, below, for contrast with `shift k ( ... )`.
 
-3.  <pre><b>let p = </b>let/cc k (1,k) <b>in
+3.  You aren't restricted to calling a full-strength continuation function only once; nor are you restricted to calling it only inside the `let/cc` block. For example:
+    <pre><b>let p = </b>let/cc k (1,k) <b>in
     let y = snd p (2, ident) in
     (fst p, y)</b></pre>
     In the first line, we bind the continuation function (the bold code) to `k` and then bind the variable `p` to the pair of `1` and that function.
-    In the second line, we extract the continuation function from the pair `p` and apply it to the argument `(2, ident)`. That results in the following code being run:
+    In the second line, we extract the continuation function from the pair `p` and apply it to the argument `(2, ident)`. That results in us discarding the rest of *that* computation and instead executing the following:
     <pre><b>let p = </b>(2, ident) <b>in
     let y = snd p (2, ident) in
     (fst p, y)</b></pre>