\ 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
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
drop
?end-rule
process-escape? get [
- escaped? [ not ] change
+ escaped? toggle
position [ + ] change
] [ drop ] if ;
dec
change
change-global
+ toggle
} ;
ARTICLE: "namespaces-global" "Global variables"
get-global
set-global
initialize
+ with-global
} ;
ARTICLE: "namespaces.private" "Namespace implementation details"
{ $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." }
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
+
: 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