]> gitweb.factorcode.org Git - factor.git/commitdiff
Starting work on advice vocab
authorJames Cash <james.nvc@gmail.com>
Wed, 5 Nov 2008 14:19:59 +0000 (09:19 -0500)
committerJames Cash <james.nvc@gmail.com>
Thu, 6 Nov 2008 05:20:52 +0000 (00:20 -0500)
extra/advice/advice-docs.factor [new file with mode: 0644]
extra/advice/advice-tests.factor [new file with mode: 0644]
extra/advice/advice.factor [new file with mode: 0644]
extra/advice/authors.txt [new file with mode: 0644]
extra/advice/tags.txt [new file with mode: 0644]

diff --git a/extra/advice/advice-docs.factor b/extra/advice/advice-docs.factor
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/extra/advice/advice-tests.factor b/extra/advice/advice-tests.factor
new file mode 100644 (file)
index 0000000..0d71ef2
--- /dev/null
@@ -0,0 +1,5 @@
+! Copyright (C) 2008 James Cash
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel sequences tools.tests advice ;
+IN: advice.tests
+
diff --git a/extra/advice/advice.factor b/extra/advice/advice.factor
new file mode 100644 (file)
index 0000000..12874be
--- /dev/null
@@ -0,0 +1,29 @@
+! Copyright (C) 2008 James Cash
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel sequences symbols fry words assocs tools.annotations ;
+IN: advice
+
+SYMBOLS: before after around ;
+
+: get-advice ( word type -- seq )
+    word-prop values ;
+
+: call-before ( word --  )
+    before get-advice [ call ] each ;
+
+: call-after ( word --  )
+    after get-advice [ call ] each ;
+    
+: advise-before ( quot name word --  )
+    before word-prop set-at ;
+    
+: advise-after ( quot name word --  )
+    after word-prop set-at ;
+
+: remove-advice ( name word loc --  )
+    word-prop delete-at ;
+    
+: make-advised ( word -- )
+    [ dup [ over '[ _ call-before @  _ call-after ] ] annotate ]
+    [ { before after around } [ H{ } clone swap set-word-prop ] with each ] bi ;
+    
\ No newline at end of file
diff --git a/extra/advice/authors.txt b/extra/advice/authors.txt
new file mode 100644 (file)
index 0000000..4b7af4a
--- /dev/null
@@ -0,0 +1 @@
+James Cash
diff --git a/extra/advice/tags.txt b/extra/advice/tags.txt
new file mode 100644 (file)
index 0000000..a87b65d
--- /dev/null
@@ -0,0 +1,3 @@
+advice
+aspect
+annotations