DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / coffee / printer.coffee
1 types = require "./types.coffee"
2
3 exports.println = (args...) -> console.log(args.join(" ")) || null
4
5 exports._pr_str = _pr_str = (obj, print_readably=true) ->
6 _r = print_readably
7 switch types._obj_type obj
8 when 'list' then '(' + obj.map((e) -> _pr_str(e,_r)).join(' ') + ')'
9 when 'vector' then '[' + obj.map((e) -> _pr_str(e,_r)).join(' ') + ']'
10 when 'hash-map'
11 ret = []
12 ret.push(_pr_str(k,_r), _pr_str(v,_r)) for k,v of obj
13 '{' + ret.join(' ') + '}'
14 when 'string'
15 if _r then '"' + (obj.replace(/\\/g, '\\\\')
16 .replace(/"/g, '\\"')
17 .replace(/\n/g, '\\n')) + '"'
18 else obj
19 when 'keyword' then ":" + obj.slice(1)
20 when 'symbol' then obj.name
21 when 'nil' then 'nil'
22 when 'atom' then "(atom " + _pr_str(obj.val,_r) + ")"
23 else obj.toString()
24
25 # vim: ts=2:sw=2