/
debug-print-test.el
124 lines (113 loc) · 3.07 KB
/
debug-print-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
(require 'debug-print)
;; Note that the below are result with `eval-last-sexp'.
;; Evaluation with `debug-print-eval-last-sexp' will cause duplicate replacement.
(debug-print:code-walk '() nil)
; => nil
(debug-print:code-walk '(a b c d) nil)
; => (a b c d)
(debug-print:code-walk '(func ::?= a) nil)
; => (func
; (debug-print a nil))
(debug-print:code-walk '(func ::?= a b) nil)
; => (func
; (debug-print a nil)
; b)
(keu:replace-in-tree '((::?= @ ())) '(func ::?= a b))
; => (func a b)
(debug-print:code-walk ''(+ 1 ::?= (+ 2 3)) nil)
; => '(+ 1
; (debug-print
; (+ 2 3)
; nil))
(debug-print:code-walk '`(+ 1 ::?= (+ 2 3)) nil)
; => '(+ 1
; (debug-print
; (+ 2 3)
; nil))
;; The following should return '(+ 1 5) and display debugging message,
;; but it does not work! I don't know any ideas for it. Users have to
;; use `debug-print' directly.
(debug-print:code-walk `'(+ 1 ,::?= (+ 2 3)) nil)
; => '(+ 1
; (debug-print
; (+ 2 3)
; nil))
(debug-print:code-walk '(defun fact (n)
(if (zerop n)
1
(* n ::?= (fact (- n 1)))))
nil)
; => (defun fact
; (n)
; (if
; (zerop n)
; 1
; (* n
; (debug-print
; (fact
; (- n 1))
; "fact"))))
(debug-print:code-walk '(defsubst hoge (n) (foo ::?= n)) nil)
; => (prog1
; (defun hoge
; (n)
; (foo
; (debug-print n "hoge")))
; (progn
; (put 'hoge 'byte-optimizer 'byte-compile-inline-expand)))
(debug-print:code-walk '(defmacro fact* (n)
(if (zerop n)
1
`(* ,n ::?= (fact* ,(- n 1)))))
nil)
; => (defmacro fact*
; (n)
; (if
; (zerop n)
; 1
; (list '* n '::\?=
; (list 'fact*
; (- n 1)))))
(debug-print-init)
;; an example from Gauche's document
(eval-with-debug-print
(defun fact (n)
(if (zerop n)
1
(* n ::?= (fact (- n 1))))))
(fact 5)
; => 120
;; and in the buffer "*debug-print*"
; ::?="fact"::(fact (- n 1))
; ::?="fact"::(fact (- n 1))
; ::?="fact"::(fact (- n 1))
; ::?="fact"::(fact (- n 1))
; ::?="fact"::(fact (- n 1))
; ::?- 1
; ::?- 1
; ::?- 2
; ::?- 6
; ::?- 24
;; test recursive macro definition
(eval-with-debug-print
(defmacro fact* (n)
(if (zerop n)
1
`(* ,n ::?= (fact* ,(- n 1))))))
(eval-with-debug-print (fact* 5))
; => 120
;; and in the buffer "*debug-print*"
; ::?=""::(* 4 (debug-print (* 3 (debug-print (* 2 (debug-print (* 1 (debug-print 1 nil)) nil)) nil)) nil))
; ::?=""::(* 3 (debug-print (* 2 (debug-print (* 1 (debug-print 1 nil)) nil)) nil))
; ::?=""::(* 2 (debug-print (* 1 (debug-print 1 nil)) nil))
; ::?=""::(* 1 (debug-print 1 nil))
; ::?=""::1
; ::?- 1
; ::?- 1
; ::?- 2
; ::?- 6
; ::?- 24
;; test `defadvice'
(eval-with-debug-print
(defadvice fact (around test disable)
ad-do-it))