blob: 0a0e0b70ac8382f49864ee618514126b4ea84db2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import types.{MalList, MalVector, MalHashMap, MalFunction}
object printer {
def _pr_str(obj: Any, print_readably: Boolean = true): String = {
val _r = print_readably
return obj match {
case v: MalVector => v.toString(_r)
case l: MalList => l.toString(_r)
case hm: MalHashMap => hm.toString(_r)
case s: String => {
if (s.length > 0 && s(0) == '\u029e') {
":" + s.substring(1,s.length)
} else if (_r) {
//println("here1: " + s)
"\"" + s.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\n", "\\n") + "\""
} else {
s
}
}
case Symbol(s) => s
case a: types.Atom => "(atom " + a.value + ")"
case null => "nil"
case _ => {
if (obj.isInstanceOf[MalFunction]) {
val f = obj.asInstanceOf[MalFunction]
"<function (fn* " + _pr_str(f.params) + " " + _pr_str(f.ast) + ")>"
} else {
obj.toString
}
}
}
}
def _pr_list(lst: List[Any], print_readably: Boolean = true,
sep: String = " "): String = {
lst.map{_pr_str(_, print_readably)}.mkString(sep)
}
}
// vim: ts=2:sw=2
|