1 import { _list_Q, _keyword_Q, Vector, Atom } from './types'
3 export function pr_str(obj, print_readably) {
4 if (typeof print_readably === 'undefined') { print_readably = true }
5 var _r = print_readably
7 return "(" + obj.map(e => pr_str(e,_r)).join(' ') + ")"
8 } else if (obj instanceof Vector) {
9 return "[" + obj.map(e => pr_str(e,_r)).join(' ') + "]"
10 } else if (obj instanceof Map) {
12 for (let [k,v] of obj) {
13 ret.push(pr_str(k,_r), pr_str(v,_r))
15 return "{" + ret.join(' ') + "}"
16 } else if (typeof obj === "string") {
17 if (_keyword_Q(obj)) {
18 return ':' + obj.slice(1)
20 return '"' + obj.replace(/\\/g, "\\\\")
22 .replace(/\n/g, "\\n") + '"'
26 } else if (typeof obj === 'symbol') {
27 return Symbol.keyFor(obj)
28 } else if (obj === null) {
30 } else if (obj instanceof Atom) {
31 return "(atom " + pr_str(obj.val,_r) + ")"