add comparisons

This commit is contained in:
2023-03-08 00:15:26 +00:00
parent dfb93c60b4
commit 11ed803601
15 changed files with 416 additions and 88 deletions

View File

@@ -7,7 +7,10 @@ import (
"strings"
)
func anyToArgon(x any, quote bool) string {
func anyToArgon(x any, quote bool, simplify bool, depth int, indent int) string {
if depth == 0 {
return "(...)"
}
switch x := x.(type) {
case string:
if !quote {
@@ -23,7 +26,10 @@ func anyToArgon(x any, quote bool) string {
} else if math.IsInf(num, -1) {
return "-infinity"
} else {
return numberToString(x, 0)
if simplify {
return numberToString(x, 0, true)
}
return numberToString(x, 0, false)
}
case bool:
return strconv.FormatBool(x)
@@ -39,15 +45,15 @@ func anyToArgon(x any, quote bool) string {
}
output := []string{}
for _, key := range keys {
output = append(output, anyToArgon(key, true)+": "+anyToArgon(x[key], true))
output = append(output, anyToArgon(key, true, true, depth, indent+1)+": "+anyToArgon(x[key], true, true, depth-1, indent+1))
}
return "{" + strings.Join(output, ", ") + "}"
return "{\n" + (strings.Repeat(" ", indent+1)) + strings.Join(output, ",\n"+(strings.Repeat(" ", indent+1))) + "\n" + (strings.Repeat(" ", indent)) + "}"
case builtinFunc:
return "<builtin function " + x.name + ">"
case Callable:
return "<function " + x.name + ">"
case ArClass:
return anyToArgon(x.value, false)
return anyToArgon(x.value, false, true, depth-1, indent+1)
default:
return fmt.Sprint(x)
}