]> gitweb.factorcode.org Git - factor.git/commitdiff
Add a toggle word to namespaces and update docs, tests, and usages. Document with...
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 29 Oct 2011 08:01:59 +0000 (01:01 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 29 Oct 2011 08:05:38 +0000 (01:05 -0700)
basis/ui/tools/listener/listener.factor
basis/xmode/marker/marker.factor
core/namespaces/namespaces-docs.factor
core/namespaces/namespaces-tests.factor
core/namespaces/namespaces.factor

index 38035b4204e9b6fcb41be5b9040631c2b934c453..15f1c5c05b7ab476aa6e2862910e20d401f67071 100644 (file)
@@ -417,7 +417,7 @@ interactor "completion" f {
 \ com-help H{ { +nullary+ t } } define-command
 
 : com-auto-use ( -- )
-    auto-use? [ not ] change ;
+    auto-use? toggle ;
 
 \ com-auto-use H{ { +nullary+ t } { +listener+ t } } define-command
 
index 4daa0599111ff1f6a89631466bd218709aef5980..f4245e0e65d34d4d39f258f1929558c4d574c85b 100644 (file)
@@ -132,7 +132,7 @@ GENERIC: handle-rule-end ( match-count rule -- )
         find-escape-rule dup [
             dup rule-start-matches? dup [
                 swap handle-rule-start
-                delegate-end-escaped? [ not ] change
+                delegate-end-escaped? toggle
                 t
             ] [
                 2drop f
@@ -162,7 +162,7 @@ M: escape-rule handle-rule-start
     drop
     ?end-rule
     process-escape? get [
-        escaped? [ not ] change
+        escaped? toggle
         position [ + ] change
     ] [ drop ] if ;
 
index 05a72c602583ba669031d83b98100d7c0215d5ac..cebd5ba59ced0e09d47fcc49bc473254f505297d 100644 (file)
@@ -19,6 +19,7 @@ ARTICLE: "namespaces-change" "Changing variable values"
     dec
     change
     change-global
+    toggle
 } ;
 
 ARTICLE: "namespaces-global" "Global variables"
@@ -28,6 +29,7 @@ ARTICLE: "namespaces-global" "Global variables"
     get-global
     set-global
     initialize
+    with-global
 } ;
 
 ARTICLE: "namespaces.private" "Namespace implementation details"
@@ -93,6 +95,18 @@ HELP: change-global
 { $description "Applies the quotation to the old value of the global variable, and assigns the resulting value to the global variable." }
 { $side-effects "variable" } ;
 
+HELP: toggle
+{ $values
+    { "variable" "a variable, by convention a symbol" }    
+}
+{ $description "Changes the boolean value of a variable to its opposite." } ;
+
+HELP: with-global
+{ $values
+    { "quot" quotation }    
+}
+{ $description "Runs the quotation in the global namespace." } ;
+
 HELP: +@
 { $values { "n" "a number" } { "variable" "a variable, by convention a symbol" } }
 { $description "Adds " { $snippet "n" } " to the value of the variable. A variable value of " { $link f } " is interpreted as being zero." }
index a7b1e508807893b6492aa0581f78b34b889be838..1397028f24aad7989bafea5a8e8a93b87d50e538 100644 (file)
@@ -26,3 +26,12 @@ f test-initialize set-global
 test-initialize [ 5 ] initialize
 
 [ 5 ] [ test-initialize get-global ] unit-test
+
+SYMBOL: toggle-test
+[ f ] [ toggle-test get ] unit-test
+[ t ] [ toggle-test [ toggle ] [ get ] bi ] unit-test
+[ f ] [ toggle-test [ toggle ] [ get ] bi ] unit-test
+
+[ t ] [ toggle-test [ on ] [ get ] bi ] unit-test
+[ f ] [ toggle-test [ off ] [ get ] bi ] unit-test
+
index 38c6870cb8b92e417bd64b7f8d6057967dbe2a65..9604be281a18691ff8af31b1b0f26e700103ba4f 100644 (file)
@@ -25,6 +25,7 @@ PRIVATE>
 : set-global ( value variable -- ) global set-at ; inline
 : change ( variable quot -- ) [ [ get ] keep ] dip dip set ; inline
 : change-global ( variable quot -- ) [ global ] dip change-at ; inline
+: toggle ( variable -- ) [ not ] change ; inline
 : +@ ( n variable -- ) [ 0 or + ] change ; inline
 : inc ( variable -- ) 1 swap +@ ; inline
 : dec ( variable -- ) -1 swap +@ ; inline