From: Jim Pryor Date: Wed, 1 Dec 2010 05:13:15 +0000 (-0500) Subject: coroutines tweak X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=76d2b904ae8af78f5d69fd1580f7f2a2cbfe6095;hp=78a718d2b2196d45cbfaa92baa445e4d64e4ad4b coroutines tweak Signed-off-by: Jim Pryor --- diff --git a/coroutines_and_aborts.mdwn b/coroutines_and_aborts.mdwn index 31da08f3..8cca9e3f 100644 --- a/coroutines_and_aborts.mdwn +++ b/coroutines_and_aborts.mdwn @@ -583,7 +583,8 @@ When working with continuations, it's easiest in the first place to write them o let foo x = try begin (if x = 1 then 10 - else abort 20) + 100 + else abort 20 + ) + 100 end in (foo 2) + 1;; @@ -593,11 +594,11 @@ into this: in let snapshot = fun box -> let foo_result = box in (foo_result) + 1000 - in let finish_value = fun start -> - let value = start + 100 + in let continue_normally = fun from_value -> + let value = from_value + 100 in snapshot value in - if x = 1 then finish_value 10 + if x = 1 then continue_normally 10 else snapshot 20;; Code written in the latter form is said to be written in **explicit continuation-passing style** or CPS. Later we'll talk about algorithms that mechanically convert an entire program into CPS.