mirror of
https://github.com/kanaka/mal.git
synced 2024-09-20 01:57:09 +03:00
28 lines
986 B
Plaintext
28 lines
986 B
Plaintext
(de pr-str (Ast PrintReadably)
|
|
(let Value (MAL-value Ast)
|
|
(case (MAL-type Ast)
|
|
((true false nil)
|
|
(sym @) )
|
|
(string (if PrintReadably (repr Value) Value))
|
|
(keyword (pack ":" Value))
|
|
((number symbol) Value)
|
|
(fn "#<subr>")
|
|
(func "#<func>")
|
|
(list (pr-list Value PrintReadably "(" ")"))
|
|
(vector (pr-list Value PrintReadably "[" "]"))
|
|
(map (pr-list Value PrintReadably "{" "}"))
|
|
(T (pretty Value) (throw 'err (MAL-error "[pr-str] unimplemented type"))) ) ) )
|
|
|
|
(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 "\"") ) ) )
|
|
|
|
(de pr-list (Forms PrintReadably Starter Ender)
|
|
(let Values (mapcar '((Form) (pr-str Form PrintReadably)) Forms)
|
|
(pack Starter (glue " " Values) Ender) ) )
|