runtest: set INPUTRC to /dev/null
[jackhill/mal.git] / ruby / printer.rb
CommitLineData
107d9694 1require_relative "types"
f705f0fc
JM
2
3def _pr_str(obj, print_readably=true)
4 _r = print_readably
5 return case obj
6 when List
7 "(" + obj.map{|x| _pr_str(x, _r)}.join(" ") + ")"
8 when Vector
9 "[" + obj.map{|x| _pr_str(x, _r)}.join(" ") + "]"
3a56f91a
JM
10 when Hash
11 ret = []
12 obj.each{|k,v| ret.push(_pr_str(k,_r), _pr_str(v,_r))}
13 "{" + ret.join(" ") + "}"
f705f0fc 14 when String
b8ee29b2
JM
15 if obj[0] == "\u029e"
16 ":" + obj[1..-1]
17 elsif _r
8bf53bec 18 obj.inspect # escape special characters
f705f0fc
JM
19 else
20 obj
21 end
3a56f91a
JM
22 when Atom
23 "(atom " + _pr_str(obj.val, true) + ")"
f705f0fc
JM
24 when nil
25 "nil"
26 else
27 obj.to_s
28 end
29end