Simplified Equality
Some checks failed
Build / build (push) Successful in 10m48s
Test / build (push) Failing after 17m11s

This commit is contained in:
Chuck Smith
2024-03-24 17:11:48 -04:00
parent fea9fb9f64
commit 1c99d2198b
11 changed files with 109 additions and 133 deletions

View File

@@ -9,24 +9,29 @@ type Integer struct {
func (i *Integer) Type() ObjectType {
return INTEGER_OBJ
}
func (i *Integer) Inspect() string {
return fmt.Sprintf("%d", i.Value)
}
func (i *Integer) Clone() Object {
return &Integer{Value: i.Value}
}
func (i *Integer) String() string {
return i.Inspect()
}
func (i *Integer) Equal(other Object) bool {
func (i *Integer) Compare(other Object) int {
if obj, ok := other.(*Integer); ok {
return i.Value == obj.Value
switch {
case i.Value < obj.Value:
return -1
case i.Value > obj.Value:
return 1
default:
return 0
}
}
return false
}
func (i *Integer) Less(other Object) bool {
if obj, ok := other.(*Integer); ok {
return i.Value < obj.Value
}
return true
return -1
}