more builtins

This commit is contained in:
Chuck Smith
2024-03-24 16:03:08 -04:00
parent b4ba660704
commit a08fc1520c
12 changed files with 243 additions and 3 deletions

19
builtins/chr.go Normal file
View File

@@ -0,0 +1,19 @@
package builtins
import (
"fmt"
"monkey/object"
)
// Chr ...
func Chr(args ...object.Object) object.Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
len(args))
}
if i, ok := args[0].(*object.Integer); ok {
return &object.String{Value: fmt.Sprintf("%c", rune(i.Value))}
}
return newError("argument to `chr` not supported, got %s", args[0].Type())
}