23 lines
446 B
Go
23 lines
446 B
Go
package builtins
|
|
|
|
import (
|
|
"monkey/internal/object"
|
|
"monkey/internal/typing"
|
|
)
|
|
|
|
// HashOf ...
|
|
func HashOf(args ...object.Object) object.Object {
|
|
if err := typing.Check(
|
|
"hash", args,
|
|
typing.ExactArgs(1),
|
|
); err != nil {
|
|
return newError(err.Error())
|
|
}
|
|
|
|
if hash, ok := args[0].(object.Hasher); ok {
|
|
return object.Integer{Value: int64(hash.Hash().Value)}
|
|
}
|
|
|
|
return newError("TypeError: hash() expected argument #1 to be hashable")
|
|
}
|