Add a toggle word to namespaces and update docs, tests, and usages. Document with-global too.
parent
b43c069b81
commit
53c6d08b54
|
@ -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
|
||||
|
||||
|
|
|
@ -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 ;
|
||||
|
||||
|
|
|
@ -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." }
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue