From e0aeeda0bf130965c25fdf2171e26d755729b6d8 Mon Sep 17 00:00:00 2001 From: jim Date: Thu, 30 Apr 2015 13:34:47 -0400 Subject: [PATCH] tweaks --- topics/week13_native_continuation_operators.mdwn | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/topics/week13_native_continuation_operators.mdwn b/topics/week13_native_continuation_operators.mdwn index 6f7a0eb8..366e3c1f 100644 --- a/topics/week13_native_continuation_operators.mdwn +++ b/topics/week13_native_continuation_operators.mdwn @@ -145,6 +145,8 @@ only returns `1`. It is possible to duplicate the behavior of `let/cc` using `re (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.
100 + let/cc k (10 + k 1)
- 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.
let p = let/cc k (1,k) 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:
+    
let p = let/cc k (1,k) in
     let y = snd p (2, ident) in
     (fst p, y)
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:
let p = (2, ident) in
     let y = snd p (2, ident) in
     (fst p, y)
-- 2.11.0