1 ! Copyright (C) 2008 James Cash
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel sequences io io.streams.string math tools.test advice math.parser
4 parser namespaces multiline eval words assocs ;
14 [ "bar" ] "barify" \ foo advise-before
18 { "bar" "foo" "baz" } [
19 [ "baz" ] "bazify" \ foo advise-after
24 "barify" \ foo before remove-advice
32 [ 2 * ] "double" \ bar advise-before
37 [ 3 / ] "third" \ bar advise-after
42 [ -1 * ad-do-it 3 + ] "frobnobicate" \ bar advise-around
46 : add ( a b -- c ) + ;
50 [ [ 2 * ] bi@ ] "double-args" \ add advise-before
55 [ 3 * ad-do-it 1- ] "around1" \ add advise-around
60 ! [ [ 1- ] bi@ ad-do-it 2 / ] "around2" \ add advise-around
64 ! { { "around1" "around2" } } [
65 ! \ add around word-prop keys
70 2 3 add \ add advised?
73 ! : quux ( a b -- c ) * ;
76 ! <" USING: advice kernel math ;
79 ! ADVISE: quux halve before [ 2 / ] bi@ ;
84 ! { 3+3/4 "1+1/2 2+1/2 3+3/4" } [
85 ! <" USING: advice kernel math math.parser io io.streams.string ;
87 ! ADVISE: quux log around
88 ! 2dup [ number>string write " " write ] bi@
90 ! dup number>string write ;
91 ! [ 3 5 quux ] with-string-writer"> eval