tests2.ss
(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 ([pc (call fact)]
      [(((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))

(let ([pc (&& (call fact)
              (cflowbelow (&& (call fact) args)))]
      [(((adv proceed) cn ck) n k) (print (list cn ck n k))
                                   (newline)
                                   (if (= 1 n)
                                       k
                                       (app/prim proceed n k))])
  (around pc adv
          (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"))

(after  (call open-file)
        (lambda (p) (lambda c (lambda a (display a))))
  (open-file "boston"))

(define oof open-file)
(define (open-file x) (oof x) x)

(display "around versions")
(newline)

(before (call open-file)
        (lambda (p) (lambda c (lambda a (display a))))
  (display (string-append "HI " (open-file "boston")))
  (newline))

(after (call open-file)
       (lambda (p) (lambda c (lambda a (display a))))
  (display (string-append "HI " (open-file "boston")))
  (newline))

(after-throwing  (call open-file)
                 (lambda (p) (lambda c (lambda a (display a))))
  (display (string-append "HI " (open-file "boston")))
  (newline))

(with-handlers ([(lambda (x) #t)
                 (lambda (x) (display "1"))])
  (after-throwing  (call open-file)
                   (lambda (p) (lambda c (lambda a (display a))))
    (display (string-append "HI " (open-file (raise "boston"))))
    (newline)))

(after-returning  (call open-file)
                  (lambda (p) (lambda c (lambda a (display a))))
  (display (string-append "HI " (open-file "boston")))
  (newline))

(with-handlers ([(lambda (x) #t)
                 (lambda (x) (display "1"))])
  (after-returning  (call open-file)
                    (lambda (p) (lambda c (lambda a (display a))))
    (display (string-append "HI " (open-file (raise "boston"))))
    (newline)))