aboutsummaryrefslogtreecommitdiff
path: root/go/src/printer/printer.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/src/printer/printer.go')
-rw-r--r--go/src/printer/printer.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/go/src/printer/printer.go b/go/src/printer/printer.go
index 83d4c84..fa1c0fb 100644
--- a/go/src/printer/printer.go
+++ b/go/src/printer/printer.go
@@ -9,14 +9,27 @@ import (
"types"
)
+func _pr_list(lst []types.MalType, pr bool, start string, end string) string {
+ str_list := make([]string, 0, len(lst))
+ for _, e := range lst {
+ str_list = append(str_list, Pr_str(e, pr))
+ }
+ return start + strings.Join(str_list, " ") + end
+}
+
func Pr_str(obj types.MalType, print_readably bool) string {
switch tobj := obj.(type) {
case types.List:
- str_list := make([]string, 0, len(tobj.Val))
- for _, e := range tobj.Val {
- str_list = append(str_list, Pr_str(e, print_readably))
+ return _pr_list(tobj.Val, print_readably, "(", ")")
+ case types.Vector:
+ return _pr_list(tobj.Val, print_readably, "[", "]")
+ case map[string]types.MalType:
+ str_list := make([]string, 0, len(tobj)*2)
+ for k, v := range tobj {
+ str_list = append(str_list, Pr_str(k, print_readably))
+ str_list = append(str_list, Pr_str(v, print_readably))
}
- return "(" + strings.Join(str_list, " ") + ")"
+ return "{" + strings.Join(str_list, " ") + "}"
case string:
if print_readably {
// TODO: quote backslash, quote, and newline
@@ -31,5 +44,4 @@ func Pr_str(obj types.MalType, print_readably bool) string {
default:
return fmt.Sprintf("%v", obj)
}
- return "<printed>"
}