tweaks
[lambda.git] / topics / week13_coroutines_exceptions_and_aborts.mdwn
index a9d8bc2..a0b8d0d 100644 (file)
@@ -212,17 +212,26 @@ Here we call `foo bar 0`, and `foo` in turn calls `bar 0`, and `bar` raises the
 
 OK, now this exception-handling apparatus does exemplify the second execution pattern we want to focus on. But it may bring it into clearer focus if we **simplify the pattern** even more. Imagine we could write code like this instead:
 
-    # let foo x =
-        try begin
-            (if x = 1 then 10
-            else abort 20
-            ) + 100
-        end
-        ;;
+    let foo x =
+      try begin
+          (if x = 1 then 10
+          else abort 20
+          ) + 100
+      end
 
 then if we called `foo 1`, we'd get the result `110`. If we called `foo 2`, on the other hand, we'd get `20` (note, not `120`). This exemplifies the same interesting "jump out of this part of the code" behavior that the `try ... raise ... with ...` code does, but without the details of matching which exception was raised, and handling the exception to produce a new result.
 
-Many programming languages have this simplified exceution pattern, either instead of or alongside a `try ... with ...`-like pattern. In Lua and many other languages, `abort` is instead called `return`. In Lua, the preceding example would be written:
+> If we had to write that using `try...with...`, it'd look something like this:
+
+>     exception Abort of int;; (* declare a new type of exception that can carry an int parameter *)
+>     let foo x =
+>       try
+>         (if x = 1 then 10
+>         else raise (Abort 20)
+>         ) + 100
+>       with Abort n -> n
+
+Many programming languages have this simplified execution pattern, either instead of or alongside a `try ... with ...`-like pattern. In Lua and many other languages, `abort` is instead called `return`. In Lua, the preceding example would be written:
 
     > function foo(x)
         local value