add create functions

This commit is contained in:
2023-02-27 00:07:13 +00:00
parent f0620354c0
commit 1b3a4c44d9
23 changed files with 580 additions and 125 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"math"
"strconv"
"strings"
)
func anyToArgon(x any, quote bool) string {
@@ -22,8 +23,31 @@ func anyToArgon(x any, quote bool) string {
} else if math.IsInf(num, -1) {
return "-infinity"
} else {
return strconv.FormatFloat(num, 'f', -1, 64)
return numberToString(x, 0)
}
case bool:
return strconv.FormatBool(x)
case nil:
return "null"
case ArMap:
keys := make([]any, len(x))
i := 0
for k := range x {
keys[i] = k
i++
}
output := []string{}
for _, key := range keys {
output = append(output, anyToArgon(key, true)+": "+anyToArgon(x[key], true))
}
return "{" + strings.Join(output, ", ") + "}"
case builtinFunc:
return "<builtin function " + x.name + ">"
case Callable:
return "<function " + x.name + ">"
case ArClass:
return anyToArgon(x.value, false)
default:
return fmt.Sprint(x)
}