(require aspect-scheme-2)
(define (open-file f)
(print (list "open file" f))
(newline))
(define open-adv (call open-file))
(define ((((trace-adv s) proceed) c) a)
(print (list "advised" s c a))
(newline)
(app/prim proceed a))
(define (mymap f l)
(if (null? l)
'()
(cons (f (car l)) (mymap f (cdr l)))))
(around open-adv (trace-adv 0)
(open-file "boston"))
(around open-adv (trace-adv "1a")
(map open-file '("boston" "providence")))
(around open-adv (trace-adv "1b")
(mymap open-file '("boston" "providence")))
(map (around open-adv (trace-adv 2)
(lambda (f) (open-file f)))
'("boston" "providence"))
(fluid-around open-adv (trace-adv 3)
(map open-file '("boston" "providence")))
(map (fluid-around open-adv (trace-adv 4)
(lambda (f) (open-file f)))
'("boston" "providence"))
(around open-adv (trace-adv "6a")
(around open-adv (trace-adv "5a")
(open-file '"boston")))
(around open-adv (trace-adv "6b")
(around open-adv (trace-adv "5b")
(map open-file '("boston" "providence"))))
(around open-adv (trace-adv "6c")
(around open-adv (trace-adv "5c")
(mymap open-file '("boston" "providence"))))
(fluid-around open-adv (trace-adv "12")
(fluid-around open-adv (trace-adv "11")
(mymap open-file '("boston" "providence"))))
(around open-adv (trace-adv 8)
(fluid-around open-adv (trace-adv 7)
(open-file "boston")))
((fluid-around open-adv (trace-adv 9)
(around open-adv (trace-adv 10)
(lambda (f) (open-file f))))
"boston")
(fluid-around open-adv (trace-adv "12")
(fluid-around open-adv (trace-adv "11")
(map open-file '("boston" "providence"))))
(fluid-around open-adv (trace-adv "14")
(fluid-around open-adv (trace-adv "13")
(mymap open-file '("boston" "providence"))))
(newline)
(define (fact n k)
(if (= 0 n)
k
(fact (- n 1) (* k n))))
(let ([(((adv proceed) c) n k) (print (list n k))
(newline)
(proceed n k)])
(around (call fact)
adv
(fact 4 1)))
(fluid-around (call fact)
(lambda (proceed)
(lambda (c)
(lambda (n k)
(print (list n k))
(newline)
(app/prim proceed n k))))
(fact 4 1))
(around (&& (call fact) args)
(lambda (proceed)
(lambda (cn ck)
(lambda (n k)
(print (list cn ck n k))
(newline)
(if (= 1 n)
k
(app/prim proceed n k)))))
(fact 4 1))
(define (foo) #t)
(around (|| (call foo) (call open-file)) (trace-adv '||)
(open-file "boston"))
(around (&& (call foo) (call open-file)) (trace-adv '&&)
(open-file "boston"))
(around (|| (call call) (call open-file)) (trace-adv '||call1)
(open-file "boston"))
(fluid-around (|| (call call) (call open-file)) (trace-adv '||call2)
(open-file "boston"))