From f3bbc30c8a2dfdddd777455e5ac3f8b1f29b15e0 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 30 May 2017 19:53:22 -0500 Subject: [PATCH] namespaces: Way better implementation of with-variable-on. --- core/namespaces/namespaces-tests.factor | 4 ++++ core/namespaces/namespaces.factor | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/namespaces/namespaces-tests.factor b/core/namespaces/namespaces-tests.factor index 48f3b1cf12..7ef7502fc5 100644 --- a/core/namespaces/namespaces-tests.factor +++ b/core/namespaces/namespaces-tests.factor @@ -38,3 +38,7 @@ SYMBOL: toggle-test { t } [ [ test-initialize get-global ] { at* set-at } inlined? ] unit-test { t } [ [ test-initialize set-global ] { at* set-at } inlined? ] unit-test + +SYMBOL: bool-test +{ t } [ bool-test [ bool-test get ] with-variable-on ] unit-test +{ f } [ bool-test [ bool-test get ] with-variable-off ] unit-test diff --git a/core/namespaces/namespaces.factor b/core/namespaces/namespaces.factor index 2ab8c9a2e7..dd6765af2a 100644 --- a/core/namespaces/namespaces.factor +++ b/core/namespaces/namespaces.factor @@ -67,6 +67,6 @@ PRIVATE> : with-variables ( ns quot -- ) swap >n call ndrop ; inline : with-scope ( quot -- ) 5 swap with-variables ; inline : with-variable ( value key quot -- ) [ associate ] dip with-variables ; inline -: with-variable-on ( key quot -- ) [ t swap associate ] dip with-variables ; inline -: with-variable-off ( key quot -- ) [ f swap associate ] dip with-variables ; inline +: with-variable-on ( key quot -- ) [ t ] 2dip with-variable ; inline +: with-variable-off ( key quot -- ) [ f ] 2dip with-variable ; inline : with-global ( quot -- ) [ global ] dip with-variables ; inline