]> gitweb.factorcode.org Git - factor.git/commitdiff
More work on around-advice
authorJames Cash <james.nvc@gmail.com>
Thu, 6 Nov 2008 05:20:15 +0000 (00:20 -0500)
committerJames Cash <james.nvc@gmail.com>
Thu, 6 Nov 2008 05:20:52 +0000 (00:20 -0500)
extra/advice/advice.factor

index 3fb694185424ebb7d31583f2b54e01f57edc105c..a71b9590f1806787891aa731076c02cb3b43474c 100644 (file)
@@ -3,7 +3,7 @@
 USING: kernel sequences symbols fry words assocs tools.annotations coroutines ;
 IN: advice
 
-SYMBOLS: before after around ;
+SYMBOLS: before after around advised ;
 
 : advise ( quot name word loc --  )
     word-prop set-at ;
@@ -28,17 +28,20 @@ SYMBOLS: before after around ;
     after get-advice [ call ] each ;
 
 : call-around ( main word --  )
-    around get-advice [ [ coresume ] each ] dip call
-    around get-advice reverse [ coresume ] each ;
+    around get-advice tuck 
+    [ [ coresume ] each ] [ call ] [ reverse [ coresume ] each ] tri* ;
 
 : remove-advice ( name word loc --  )
     word-prop delete-at ;
 
 : ad-do-it ( input -- result )
     coyield ;
-    
+
+: advised? ( word -- ? )
+    advised word-prop ;
     
 : make-advised ( word -- )
     [ dup [ over dup '[ _ call-before _ _ call-around _ call-after ] ] annotate ]
-    [ { before after around } [ H{ } clone swap set-word-prop ] with each ] bi ;
+    [ { before after around } [ H{ } clone swap set-word-prop ] with each ] 
+    [ t advised set-word-prop ] tri ;
     
\ No newline at end of file