-
Notifications
You must be signed in to change notification settings - Fork 1
/
io.lisp
67 lines (43 loc) · 1.29 KB
/
io.lisp
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
(in-package :arc-compat.internal)
(in-readtable :common-lisp)
(in-suite arc-compat)
;;; This software is copyright (c) Paul Graham and Robert Morris. Permission
;;; to use it is granted under the Perl Foundations's Artistic License 2.0.
;;;
;;; Ported to Common Lisp by CHIBA Masaomi.
(def pr args
(map1 #'disp args)
(car args))
(def prn args
(do1 (apply #'pr args)
(writec #\newline)))
(mac after (x . ys)
`(unwind-protect ,x ,@ys))
(flet ((expander (f var name body)
`(let ,var (,f ,name)
(after (do ,@body) (close ,var)))))
(mac w/infile (var name . body)
(expander 'infile var name body))
(mac w/outfile (var name . body)
(expander 'outfile var name body))
(mac w/instring (var str . body)
(expander 'instring var str body))
(mac w/socket (var port . body)
(expander 'open-socket var port body))
)
(mac w/outstring (var . body)
`(let ,var (make-string-output-stream) ,@body))
(mac w/stdout (str . body)
`(let cl:*standard-output* ,str ,@body))
(mac w/stdin (str . body)
`(let *standard-input* ,str ,@body))
(mac tostring body
(w/uniq gv
`(w/outstring ,gv
(w/stdout ,gv ,@body)
(inside ,gv))))
(mac fromstring (str . body)
(w/uniq gv
`(w/instring ,gv ,str
(w/stdin ,gv ,@body))))
;;; eof