extra/central implements the "central" pattern
parent
75276855ae
commit
16ba9fbd80
|
@ -0,0 +1 @@
|
|||
Matthew Willis
|
|
@ -0,0 +1,10 @@
|
|||
USING: central help.markup help.syntax ;
|
||||
|
||||
HELP: CENTRAL:
|
||||
{ $description
|
||||
"This parsing word defines a pair of words useful for "
|
||||
"implementing the \"central\" pattern: " { $snippet "symbol" } " and "
|
||||
{ $snippet "with-symbol" } ". This is a middle ground between excessive "
|
||||
"stack manipulation and full-out locals, meant to solve the case where "
|
||||
"one object is operated on by several related words."
|
||||
} ;
|
|
@ -0,0 +1,7 @@
|
|||
USING: central tools.test ;
|
||||
|
||||
IN: scratchpad
|
||||
|
||||
CENTRAL: test-central
|
||||
|
||||
[ 3 ] [ 3 [ test-central ] with-test-central ] unit-test
|
|
@ -0,0 +1,16 @@
|
|||
USING: kernel lexer namespaces parser sequences words ;
|
||||
|
||||
IN: central
|
||||
|
||||
: define-central-getter ( word -- )
|
||||
dup [ get ] curry (( -- obj )) define-declared ;
|
||||
|
||||
: define-central-setter ( word with-word -- )
|
||||
[ with-variable ] with (( object quot -- )) define-declared ;
|
||||
|
||||
: define-central ( word-name -- )
|
||||
[ create-in dup define-central-getter ] keep
|
||||
"with-" prepend create-in [ define-central-setter ] keep
|
||||
make-inline ;
|
||||
|
||||
SYNTAX: CENTRAL: ( -- ) scan define-central ;
|
|
@ -0,0 +1 @@
|
|||
extensions
|
Loading…
Reference in New Issue