]> gitweb.factorcode.org Git - factor.git/commitdiff
environment: adding a combinator to set and unset and os-env.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 22 Apr 2014 14:40:39 +0000 (07:40 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 22 Apr 2014 14:40:39 +0000 (07:40 -0700)
basis/environment/environment-tests.factor
basis/environment/environment.factor

index 524cf89ccf3811b41e2875f70d99dab824540edd..a34d1db45245af1f9edc78a0507cd5ce71ba9c39 100644 (file)
@@ -35,3 +35,9 @@ os unix? [
 
 ! Issue #794, setting something to ``f`` is a memory protection fault on mac
 [ ] [ f "dummy-env-variable-for-factor-test" set-os-env ] unit-test
+
+{ f "value" f } [
+    "factor-test-key" os-env
+    "value" "factor-test-key" [ "factor-test-key" os-env ] with-os-env
+    "factor-test-key" os-env
+] unit-test
index 121751e07d8d48e5f7b18a519573ab1edc462e30..79c83733a3bfd59713952748ef1c772eb514864e 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: assocs combinators init kernel sequences splitting
-system vocabs vocabs.loader ;
+USING: assocs combinators continuations init kernel sequences
+splitting system vocabs vocabs.loader ;
 IN: environment
 
 HOOK: os-env os ( key -- value )
@@ -25,6 +25,10 @@ HOOK: set-os-envs-pointer os ( malloc -- )
 : set-os-envs ( assoc -- )
     [ "=" glue ] { } assoc>map (set-os-envs) ;
 
+: with-os-env ( value key quot -- )
+    over [ [ [ set-os-env ] 2curry ] [ compose ] bi* ] dip
+    [ os-env ] keep [ set-os-env ] 2curry [ ] cleanup ; inline
+
 {
     { [ os unix? ] [ "environment.unix" require ] }
     { [ os windows? ] [ "environment.windows" require ] }