File call-with-environment-variables/call-with-environment-variables.wiki artifact c4f0264957 part of check-in 445f1a1231
== call-with-environment-variables
Set up and take down environment vars [toc:] === {{call-with-environment-variables}} <procedure>(call-with-environment-variables variables thunk) → unspecified</procedure> Sets up environment variable via dynamic-wind which are taken down after thunk. ; {{variables}} : An alist of the form {{'(("var" . "value") ...)}} ; {{thunk}} : The thunk to execute with a modified environment <enscript highlight="scheme">(define (call-with-environment-variables variables thunk) (let ((pre-existing-variables (map (lambda (var-value) (let ((var (car var-value))) (cons var (get-environment-variable var)))) variables))) (dynamic-wind (lambda () (void)) (lambda () (use posix) (for-each (lambda (var-value) (setenv (car var-value) (cdr var-value))) variables) (thunk)) (lambda () (for-each (lambda (var-value) (let ((var (car var-value)) (value (cdr var-value))) (if value (setenv var value) (unsetenv var)))) pre-existing-variables))))) </enscript> === About this egg
==== Author
Peter Danenberg] ==== Repository [https://github.com/klutometis/call-with-environment-variables] ==== License BSD ==== Dependencies * [(hahn 0.9.3)] * [setup-helper]
==== Versions ; 0.1] : Initial release ; 0.1.1] : Add the actual code. ; 0.1.2] : Fix versions. ; 0.1.3] : Update docs. ; 0.1.4] : With a note about cock-utils ; 0.1.5] : Docs ; 0.1.6] : Use hahn. ==== Colophon
Documented by hahn].