2016-10-02 16:55:19 +03:00
|
|
|
(de pr-str (Ast PrintReadably)
|
2016-10-02 20:41:49 +03:00
|
|
|
(let Value (MAL-value Ast)
|
|
|
|
(case (MAL-type Ast)
|
2016-10-02 16:55:19 +03:00
|
|
|
((true false nil)
|
|
|
|
(sym @) )
|
2016-10-04 23:10:55 +03:00
|
|
|
(string (if PrintReadably (repr Value) Value))
|
2016-10-02 16:55:19 +03:00
|
|
|
(keyword (pack ":" Value))
|
|
|
|
((number symbol) Value)
|
2016-10-04 23:10:55 +03:00
|
|
|
(fn "#<subr>")
|
2016-10-11 19:24:50 +03:00
|
|
|
(func "#<func>")
|
2016-10-02 16:55:19 +03:00
|
|
|
(list (pr-list Value PrintReadably "(" ")"))
|
|
|
|
(vector (pr-list Value PrintReadably "[" "]"))
|
|
|
|
(map (pr-list Value PrintReadably "{" "}"))
|
2016-10-14 11:39:49 +03:00
|
|
|
(atom (pack "(atom " (pr-str Value PrintReadably) ")"))
|
2016-10-22 13:37:24 +03:00
|
|
|
(T (pretty Value) (throw 'err (MAL-error (MAL-string "[pr-str] unimplemented type")))) ) ) )
|
2016-10-04 23:10:55 +03:00
|
|
|
|
|
|
|
(de repr (X)
|
|
|
|
(let Chars (chop X)
|
|
|
|
(if (not X)
|
|
|
|
"\"\""
|
|
|
|
(setq Chars (replace Chars "\\" "\\\\"))
|
|
|
|
(setq Chars (replace Chars "\"" "\\\""))
|
|
|
|
(setq Chars (replace Chars "\n" "\\n"))
|
|
|
|
(pack "\"" Chars "\"") ) ) )
|
2016-10-02 16:55:19 +03:00
|
|
|
|
|
|
|
(de pr-list (Forms PrintReadably Starter Ender)
|
|
|
|
(let Values (mapcar '((Form) (pr-str Form PrintReadably)) Forms)
|
|
|
|
(pack Starter (glue " " Values) Ender) ) )
|