1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-22 11:17:40 +00:00

Add with-vars

This helps for temporarily setting vars in a safe
manner that is guaranteed not to leave vars in a bad state
(assuming that a fiber does not emit debug or use signal and
 is never resumed).
This commit is contained in:
Calvin Rose
2019-10-31 21:58:43 -05:00
parent 25a9804d91
commit 6ceaf9d28d
3 changed files with 27 additions and 1 deletions

View File

@@ -184,4 +184,10 @@
(assert (= (string '()) (string [])) "empty bracket tuple literal")
# with-vars
(var abc 123)
(assert (= 356 (with-vars [abc 456] (- abc 100))) "with-vars 1")
(assert-error "with-vars 2" (with-vars [abc 456] (error :oops)))
(assert (= abc 123) "with-vars 3")
(end-suite)