mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
add comparisons
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user