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 "{" "}")) | |
118269ab VS |
14 | (T (pretty Value) (throw 'err (MAL-error "[pr-str] unimplemented type"))) ) ) ) |
15 | ||
16 | (de repr (X) | |
17 | (let Chars (chop X) | |
18 | (if (not X) | |
19 | "\"\"" | |
20 | (setq Chars (replace Chars "\\" "\\\\")) | |
21 | (setq Chars (replace Chars "\"" "\\\"")) | |
22 | (setq Chars (replace Chars "\n" "\\n")) | |
23 | (pack "\"" Chars "\"") ) ) ) | |
a870ad3f VS |
24 | |
25 | (de pr-list (Forms PrintReadably Starter Ender) | |
26 | (let Values (mapcar '((Form) (pr-str Form PrintReadably)) Forms) | |
27 | (pack Starter (glue " " Values) Ender) ) ) |