extra/central implements the "central" pattern

db4
Matthew Willis 2009-06-15 17:09:20 +09:00
parent 75276855ae
commit 16ba9fbd80
5 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1 @@
Matthew Willis

View File

@ -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."
} ;

View File

@ -0,0 +1,7 @@
USING: central tools.test ;
IN: scratchpad
CENTRAL: test-central
[ 3 ] [ 3 [ test-central ] with-test-central ] unit-test

View File

@ -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 ;

1
extra/central/tags.txt Normal file
View File

@ -0,0 +1 @@
extensions