add initialize word to namespaces. foo global [ [ bar ] unless* ] curry => foo [ bar ] initialize
parent
b75f6f88da
commit
1708d10c9a
|
@ -1,6 +1,6 @@
|
||||||
USING: help.markup help.syntax kernel kernel.private
|
USING: help.markup help.syntax kernel kernel.private
|
||||||
sequences words namespaces.private quotations vectors
|
sequences words namespaces.private quotations vectors
|
||||||
math.parser math ;
|
math.parser math words.symbol ;
|
||||||
IN: namespaces
|
IN: namespaces
|
||||||
|
|
||||||
ARTICLE: "namespaces-combinators" "Namespace combinators"
|
ARTICLE: "namespaces-combinators" "Namespace combinators"
|
||||||
|
@ -20,7 +20,8 @@ ARTICLE: "namespaces-global" "Global variables"
|
||||||
{ $subsection namespace }
|
{ $subsection namespace }
|
||||||
{ $subsection global }
|
{ $subsection global }
|
||||||
{ $subsection get-global }
|
{ $subsection get-global }
|
||||||
{ $subsection set-global } ;
|
{ $subsection set-global }
|
||||||
|
{ $subsection initialize } ;
|
||||||
|
|
||||||
ARTICLE: "namespaces.private" "Namespace implementation details"
|
ARTICLE: "namespaces.private" "Namespace implementation details"
|
||||||
"The namestack holds namespaces."
|
"The namestack holds namespaces."
|
||||||
|
@ -159,3 +160,7 @@ HELP: ndrop
|
||||||
HELP: init-namespaces
|
HELP: init-namespaces
|
||||||
{ $description "Resets the name stack to its initial state, holding a single copy of the global namespace." }
|
{ $description "Resets the name stack to its initial state, holding a single copy of the global namespace." }
|
||||||
$low-level-note ;
|
$low-level-note ;
|
||||||
|
|
||||||
|
HELP: initialize
|
||||||
|
{ $values { "variable" symbol } { "quot" quotation } }
|
||||||
|
{ $description "If " { $snippet "variable" } " does not have a value in the global namespace, calls " { $snippet "quot" } " and assigns the result to " { $snippet "variable" } " in the global namespace." } ;
|
||||||
|
|
|
@ -12,3 +12,14 @@ H{ } clone "test-namespace" set
|
||||||
[ f ]
|
[ f ]
|
||||||
[ H{ } clone [ f "some-global" set "some-global" get ] bind ]
|
[ H{ } clone [ f "some-global" set "some-global" get ] bind ]
|
||||||
unit-test
|
unit-test
|
||||||
|
|
||||||
|
SYMBOL: test-initialize
|
||||||
|
test-initialize [ 1 ] initialize
|
||||||
|
test-initialize [ 2 ] initialize
|
||||||
|
|
||||||
|
[ 1 ] [ test-initialize get-global ] unit-test
|
||||||
|
|
||||||
|
f test-initialize set-global
|
||||||
|
test-initialize [ 5 ] initialize
|
||||||
|
|
||||||
|
[ 5 ] [ test-initialize get-global ] unit-test
|
||||||
|
|
|
@ -38,3 +38,6 @@ PRIVATE>
|
||||||
|
|
||||||
: with-variable ( value key quot -- )
|
: with-variable ( value key quot -- )
|
||||||
[ associate >n ] dip call ndrop ; inline
|
[ associate >n ] dip call ndrop ; inline
|
||||||
|
|
||||||
|
: initialize ( variable quot -- )
|
||||||
|
[ global ] [ [ unless* ] curry ] bi* change-at ;
|
||||||
|
|
Loading…
Reference in New Issue