2022-04-21 22:09:11 +00:00
|
|
|
// +build !gui
|
2021-11-09 06:50:26 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
2022-04-21 03:39:15 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2021-11-09 06:50:26 +00:00
|
|
|
var guiLib = vars{}
|
2022-04-21 03:39:15 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|