more builtins
This commit is contained in:
16
builtins/hash.go
Normal file
16
builtins/hash.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package builtins
|
||||
|
||||
import "monkey/object"
|
||||
|
||||
// HashOf ...
|
||||
func HashOf(args ...object.Object) object.Object {
|
||||
if len(args) != 1 {
|
||||
return newError("wrong number of arguments. got=%d, want=1",
|
||||
len(args))
|
||||
}
|
||||
|
||||
if hash, ok := args[0].(object.Hashable); ok {
|
||||
return &object.Integer{Value: int64(hash.HashKey().Value)}
|
||||
}
|
||||
return newError("argument #1 to `hash()` is not hashable: %s", args[0].Inspect())
|
||||
}
|
||||
Reference in New Issue
Block a user