-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathllog.scm
83 lines (67 loc) · 2.2 KB
/
llog.scm
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
;; This file is part of mowedline.
;; Copyright (C) 2011-2013 John J. Foerch
;;
;; mowedline is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; mowedline is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with mowedline. If not, see <http://www.gnu.org/licenses/>.
(module llog
(llog-watch
llog-unwatch
llog-watch-only
llog-unwatch-all
llog-indent-string
llog-line
llog
llog-indent
llog-unindent)
(import chicken scheme)
(use srfi-1
srfi-13
extras)
(define llog-watches '())
(define (llog-watch . syms)
(set! llog-watches (lset-union eq? llog-watches syms)))
(define (llog-unwatch . syms)
(set! llog-watches (lset-difference eq? llog-watches syms)))
(define (llog-watch-only . syms)
(set! llog-watches syms))
(define (llog-unwatch-all)
(set! llog-watches '()))
(define llog-depth 0)
(define llog-indent-string (make-parameter " "))
(define (llog-line type format . args)
(when (memq type llog-watches)
(apply printf (string-append "~A~A " format "~%")
(xsubstring (llog-indent-string)
0
(* llog-depth
(string-length (llog-indent-string))))
type args)))
(define (llog-indent type)
(when (memq type llog-watches)
(set! llog-depth (+ llog-depth 1))))
(define (llog-unindent type)
(when (memq type llog-watches)
(set! llog-depth (- llog-depth 1))))
(define-syntax llog
(syntax-rules ()
((llog (type format . args) form . forms)
(dynamic-wind
(lambda () #f)
(lambda ()
(llog type format . args)
(llog-indent 'type)
form . forms)
(lambda () (llog-unindent 'type))))
((llog type format . args)
(llog-line 'type format . args))))
)