X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=coroutines_and_aborts.mdwn;h=8cca9e3f5aa209c683f00d8f6c20c3dc7a202691;hp=31da08f3be0b30be30b51083ae02aedf96d2ee44;hb=4d77188b080ae01ca1a58559481c5a2cfff7cbe2;hpb=78a718d2b2196d45cbfaa92baa445e4d64e4ad4b 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.