]> gitweb.factorcode.org Git - factor.git/commitdiff
extra/central implements the "central" pattern
authorMatthew Willis <matthew.willis@mac.com>
Mon, 15 Jun 2009 08:09:20 +0000 (17:09 +0900)
committerMatthew Willis <matthew.willis@mac.com>
Mon, 15 Jun 2009 08:09:20 +0000 (17:09 +0900)
extra/central/authors.txt [new file with mode: 0644]
extra/central/central-docs.factor [new file with mode: 0644]
extra/central/central-tests.factor [new file with mode: 0644]
extra/central/central.factor [new file with mode: 0644]
extra/central/tags.txt [new file with mode: 0644]

diff --git a/extra/central/authors.txt b/extra/central/authors.txt
new file mode 100644 (file)
index 0000000..5645cd9
--- /dev/null
@@ -0,0 +1 @@
+Matthew Willis
diff --git a/extra/central/central-docs.factor b/extra/central/central-docs.factor
new file mode 100644 (file)
index 0000000..f6a0ba5
--- /dev/null
@@ -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."
+} ;
\ No newline at end of file
diff --git a/extra/central/central-tests.factor b/extra/central/central-tests.factor
new file mode 100644 (file)
index 0000000..576a1fa
--- /dev/null
@@ -0,0 +1,7 @@
+USING: central tools.test ;
+
+IN: scratchpad
+
+CENTRAL: test-central
+
+[ 3 ] [ 3 [ test-central ] with-test-central ] unit-test
\ No newline at end of file
diff --git a/extra/central/central.factor b/extra/central/central.factor
new file mode 100644 (file)
index 0000000..df100f2
--- /dev/null
@@ -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 ;
\ No newline at end of file
diff --git a/extra/central/tags.txt b/extra/central/tags.txt
new file mode 100644 (file)
index 0000000..f427429
--- /dev/null
@@ -0,0 +1 @@
+extensions