diff --git a/CHANGELOG.md b/CHANGELOG.md index 6613d4c2..98204705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add `with-env` - Add *module-make-env* dynamic binding - Add buffer/format-at - Add long form command line options for readable CLI usage diff --git a/src/boot/boot.janet b/src/boot/boot.janet index c465dfcb..71672fa1 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1423,6 +1423,11 @@ ~(setdyn ,(bindings i) ,(bindings (+ i 1))))) ~(,resume (,fiber/new (fn [] ,;dyn-forms ,;body) :p))) +(defmacro with-env + `Run a block of code with a given environment table` + [env & body] + ~(,resume (,fiber/new (fn [] ,;body) : ,env))) + (defmacro with-vars ``Evaluates `body` with each var in `vars` temporarily bound. Similar signature to `let`, but each binding must be a var.`` diff --git a/test/suite-boot.janet b/test/suite-boot.janet index 89fb0076..b412c52d 100644 --- a/test/suite-boot.janet +++ b/test/suite-boot.janet @@ -976,4 +976,7 @@ (assert (= () '() (macex '())) "macex ()") (assert (= '[] (macex '[])) "macex []") +(assert (= :a (with-env @{:b :a} (dyn :b))) "with-env dyn") +(assert-error "unknown symbol +" (with-env @{} (eval '(+ 1 2)))) + (end-suite)