environment: adding a combinator to set and unset and os-env.

db4
John Benediktsson 2014-04-22 07:40:39 -07:00
parent 6be25de125
commit 15ab7fe82a
2 changed files with 12 additions and 2 deletions

View 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

View 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 ] }