1 local string = require('string')
2 local table = require('table')
3 local types
= require('types')
4 local utils
= require('utils')
8 function M
._pr_str(obj
, print_readably
)
9 local _r
= print_readably
10 if utils
.instanceOf(obj
, types
.Symbol
) then
12 elseif types
._list_Q(obj
) then
13 return "(" .. table.concat(utils
.map(function(e
)
14 return M
._pr_str(e
,_r
) end, obj
), " ") .. ")"
15 elseif types
._vector_Q(obj
) then
16 return "[" .. table.concat(utils
.map(function(e
)
17 return M
._pr_str(e
,_r
) end, obj
), " ") .. "]"
18 elseif types
._hash_map_Q(obj
) then
20 for k
,v
in pairs(obj
) do
21 res
[#res
+1] = M
._pr_str(k
, _r
)
22 res
[#res
+1] = M
._pr_str(v
, _r
)
24 return "{".. table.concat(res
, " ").."}"
25 elseif type(obj
) == 'string' then
26 if string.sub(obj
,1,1) == "\177" then
27 return ':' .. string.sub(obj
,2)
30 local sval
= obj
:gsub('\\', '\\\\')
31 sval
= sval
:gsub('"', '\\"')
32 sval
= sval
:gsub('\n', '\\n')
33 return '"' .. sval
.. '"'
38 elseif obj
== types
.Nil
then
40 elseif obj
== true then
42 elseif obj
== false then
44 elseif types
._malfunc_Q(obj
) then
45 return "(fn* "..M
._pr_str(obj
.params
).." "..M
._pr_str(obj
.ast
)..")"
46 elseif types
._atom_Q(obj
) then
47 return "(atom "..M
._pr_str(obj
.val
)..")"
48 elseif type(obj
) == 'function' or types
._functionref_Q(obj
) then
51 return string.format("%s", obj
)