1
1
mirror of https://github.com/kanaka/mal.git synced 2024-10-26 22:28:26 +03:00
mal/impls/picolisp/printer.l

29 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

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) ) )