Add unwind-protect macro to (std sugar)
ober
9357b8394717b5e43dc89e8413a9e27bb4b30dfc
--- a/lib/std/sugar.sls +++ b/lib/std/sugar.sls @@ -5,6 +5,7 @@ (export try catch finally while until + unwind-protect hash-literal hash-eq-literal let-hash defrule defrules @@ -86,4 +87,13 @@ (unless expr (error 'assert! message 'expr))])) + ;; unwind-protect — like Java's try/finally, guarantee cleanup runs + (define-syntax unwind-protect + (syntax-rules () + [(_ body cleanup ...) + (dynamic-wind + (lambda () (void)) + (lambda () body) + (lambda () cleanup ...))])) + ) ;; end library