4 module Printer
= struct
5 let rec display ff obj
=
6 let print_int = fprintf ff
"%d" in
7 let print_string = fprintf ff
"%s" in
8 let rec print_separated = function
11 | x
::y
-> (display ff x
); print_string " "; (print_separated y
)
14 Int
(i
) -> print_int i
15 | String
(s
) -> print_string ("\""^s^
"\"")
16 | Symbol
(s
) -> print_string s
17 | Null
-> print_string "()"
18 | True
-> print_string "#t"
19 | False
-> print_string "#f"
20 | Closure
(_
, _
, _
) -> print_string "#<closure>"
21 | Continuation
(_
) -> print_string "#<continuation>"
22 | Quotation x
-> display ff x
25 print_string "("; print_separated l
; print_string ")"; close_box
()
26 | _
-> print_string "#<unknown>"
28 let rec write ff obj
=
29 let print_int = fprintf ff
"%d" in
30 let print_string = fprintf ff
"%s" in
31 let rec print_separated = function
34 | x
::y
-> (display ff x
); print_string " "; (print_separated y
)
37 Int
(i
) -> print_int i
39 | Symbol
(s
) -> print_string s
40 | Null
-> print_string "()"
41 | True
-> print_string "#t"
42 | False
-> print_string "#f"
43 | Closure
(_
, _
, _
) -> print_string "#<closure>"
44 | Continuation
(_
) -> print_string "#<continuation>"
45 | Quotation x
-> display ff x
48 print_string "("; print_separated l
; print_string ")"; close_box
()
49 | _
-> print_string "#<unknown>"