slope/nogui.go

54 lines
989 B
Go
Raw Normal View History

// +build !gui
package main
import (
"fmt"
"strconv"
"strings"
)
var guiLib = vars{}
func String(v expression, rawString bool) string {
switch v := v.(type) {
case []expression:
l := make([]string, len(v))
for i, x := range v {
l[i] = String(x, true)
}
return "(" + strings.Join(l, " ") + ")"
case string:
if rawString {
return fmt.Sprintf("\"%s\"", escapeString(v))
}
return v
case exception:
return string(v)
case bool:
if v {
return "#t"
}
return "#f"
case number:
return strconv.FormatFloat(float64(v), 'f', -1, 64)
case proc:
var b strings.Builder
b.WriteString("(lambda ")
b.WriteString(String(v.params, true))
b.WriteRune(' ')
body := String(v.body, true)
if strings.HasPrefix(body, "(begin ") {
body = body[7:]
}
b.WriteString(body)
return b.String()
case func(...expression) expression:
return fmt.Sprint("Built-in: ", &v)
case *IOHandle:
return fmt.Sprintf("%+v", v)
default:
return fmt.Sprint(v)
}
}