-
Notifications
You must be signed in to change notification settings - Fork 4
ensure
TurtleKitty edited this page Jan 29, 2016
·
3 revisions
This is the only global operator that affects both the user continuation and the error continuation. It is akin to unwind-protect or finally { } in other languages. It ensures that the given thunk executes whether the body expressions return normally or throw an error. Resuming an error in a guard handler defined outside the ensure could lead to inconsistency, so it's best to nest guards inside ensures, rather than the other way around.
No continuation can be captured across an ensure. It behaves like gate in this respect.
(def x 1)
(ensure
(proc () (set! x 3))
(seq
(set! x 5)
(+ 2 x))) -> 7
x -> 3