From: jim Date: Fri, 1 May 2015 11:22:52 +0000 (-0400) Subject: continue_foo_normally -> continue_foo_snapshot X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=3ae0629e58380d86982e7d03201dcf949103064f;hp=433a843541557eff89de3d22086427c60552072b continue_foo_normally -> continue_foo_snapshot --- diff --git a/topics/week13_coroutines_exceptions_and_aborts.mdwn b/topics/week13_coroutines_exceptions_and_aborts.mdwn index de7e8c00..a820bde6 100644 --- a/topics/week13_coroutines_exceptions_and_aborts.mdwn +++ b/topics/week13_coroutines_exceptions_and_aborts.mdwn @@ -345,11 +345,11 @@ We can get that by some further rearranging of the code: in let outer_snapshot = fun box -> let foo_result = box in (foo_result) + 1000 - in let continue_foo_normally = fun from_value -> + in let continue_foo_snapshot = fun from_value -> let value = from_value + 100 in outer_snapshot value in (* start of foo_applied_to_x *) - if x = 1 then continue_foo_normally 10 + if x = 1 then continue_foo_snapshot 10 else outer_snapshot 20;; And this is indeed what is happening, at a fundamental level, when you use an expression like `abort 20`. Here is the original code for comparison: @@ -404,11 +404,11 @@ into this: in let outer_snapshot = fun box -> let foo_result = box in (foo_result) + 1000 - in let continue_foo_normally = fun from_value -> + in let continue_foo_snapshot = fun from_value -> let value = from_value + 100 in outer_snapshot value in (* start of foo_applied_to_x *) - if x = 1 then continue_foo_normally 10 + if x = 1 then continue_foo_snapshot 10 else outer_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. @@ -442,10 +442,10 @@ There are also different kinds of "syntactic sugar" we can use to hide the conti let outer_snapshot = fun box -> let foo_result = box in (foo_result) + 1000 - in let continue_foo_normally = fun from_value -> + in let continue_foo_snapshot = fun from_value -> let value = from_value + 100 in outer_snapshot value - in if x = 1 then continue_foo_normally 10 + in if x = 1 then continue_foo_snapshot 10 else outer_snapshot 20;; # let test_shift x =