Commit | Line | Data |
---|---|---|
a870ad3f | 1 | (de pr-str (Ast PrintReadably) |
8d229b7c VS |
2 | (let Value (MAL-value Ast) |
3 | (case (MAL-type Ast) | |
a870ad3f VS |
4 | ((true false nil) |
5 | (sym @) ) | |
118269ab | 6 | (string (if PrintReadably (repr Value) Value)) |
a870ad3f VS |
7 | (keyword (pack ":" Value)) |
8 | ((number symbol) Value) | |
118269ab | 9 | (fn "#<subr>") |
624e67cb | 10 | (func "#<func>") |
a870ad3f VS |
11 | (list (pr-list Value PrintReadably "(" ")")) |
12 | (vector (pr-list Value PrintReadably "[" "]")) | |
13 | (map (pr-list Value PrintReadably "{" "}")) | |
30a55a91 | 14 | (atom (pack "(atom " (pr-str Value PrintReadably) ")")) |
1809f9ba | 15 | (T (pretty Value) (throw 'err (MAL-error (MAL-string "[pr-str] unimplemented type")))) ) ) ) |
118269ab VS |
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 "\"") ) ) ) | |
a870ad3f VS |
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) ) ) |