DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / picolisp / printer.l
1 (de pr-str (Ast PrintReadably)
2 (let Value (MAL-value Ast)
3 (case (MAL-type Ast)
4 ((true false nil)
5 (sym @) )
6 (string (if PrintReadably (repr Value) Value))
7 (keyword (pack ":" Value))
8 ((number symbol) Value)
9 (fn "#<subr>")
10 (func "#<func>")
11 (list (pr-list Value PrintReadably "(" ")"))
12 (vector (pr-list Value PrintReadably "[" "]"))
13 (map (pr-list Value PrintReadably "{" "}"))
14 (atom (pack "(atom " (pr-str Value PrintReadably) ")"))
15 (T (pretty Value) (throw 'err (MAL-error (MAL-string "[pr-str] unimplemented type")))) ) ) )
16
17 (de repr (X)
18 (let Chars (chop X)
19 (if (not X)
20 "\"\""
21 (setq Chars (replace Chars "\\" "\\\\"))
22 (setq Chars (replace Chars "\"" "\\\""))
23 (setq Chars (replace Chars "\n" "\\n"))
24 (pack "\"" Chars "\"") ) ) )
25
26 (de pr-list (Forms PrintReadably Starter Ender)
27 (let Values (mapcar '((Form) (pr-str Form PrintReadably)) Forms)
28 (pack Starter (glue " " Values) Ender) ) )