2 IS_RPYTHON
= sys
.argv
[0].endswith('rpython')
5 from rpython
.rlib
.rsre
import rsre_re
as re
9 import mal_types
as types
10 from mal_types
import (MalType
, MalStr
, MalSym
, MalInt
,
11 nil
, true
, false
, MalAtom
, MalFunc
)
13 def _pr_a_str(s
, print_readably
=True):
14 if len(s
) > 0 and s
[0] == u
'\u029e':
17 return u
'"' + types
._replace
(u
'\\n', u
'\\n',
18 types
._replace
(u
'\"', u
'\\"',
19 types
._replace
(u
'\\', u
'\\\\', s
))) + u
'"'
23 def _pr_str(obj
, print_readably
=True):
24 assert isinstance(obj
, MalType
)
26 if types
._list
_Q
(obj
):
29 res
.append(_pr_str(e
,_r
))
30 return u
"(" + u
" ".join(res
) + u
")"
31 elif types
._vector
_Q
(obj
):
34 res
.append(_pr_str(e
,_r
))
35 return u
"[" + u
" ".join(res
) + u
"]"
36 elif types
._hash
_map
_Q
(obj
):
38 for k
in obj
.dct
.keys():
39 ret
.append(_pr_a_str(k
,_r
))
40 ret
.append(_pr_str(obj
.dct
[k
],_r
))
41 return u
"{" + u
" ".join(ret
) + u
"}"
42 elif isinstance(obj
, MalStr
):
43 return _pr_a_str(obj
.value
,_r
)
50 elif types
._atom
_Q
(obj
):
51 return u
"(atom " + _pr_str(obj
.get_value(),_r
) + u
")"
52 elif isinstance(obj
, MalSym
):
54 elif isinstance(obj
, MalInt
):
55 return unicode(str(obj
.value
))
56 elif isinstance(obj
, MalFunc
):