type checking and error handling for builtins improved.
Some checks failed
Build / build (push) Successful in 11m16s
Test / build (push) Failing after 17m0s

This commit is contained in:
Chuck Smith
2024-03-25 16:18:08 -04:00
parent 1c99d2198b
commit 6d234099d1
52 changed files with 650 additions and 433 deletions

View File

@@ -14,6 +14,36 @@ func (ao *Array) Type() ObjectType {
return ARRAY_OBJ
}
func (ao *Array) Bool() bool {
return len(ao.Elements) > 0
}
func (a *Array) PopLeft() Object {
if len(a.Elements) > 0 {
e := a.Elements[0]
a.Elements = a.Elements[1:]
return e
}
return &Null{}
}
func (a *Array) PopRight() Object {
if len(a.Elements) > 0 {
e := a.Elements[(len(a.Elements) - 1)]
a.Elements = a.Elements[:(len(a.Elements) - 1)]
return e
}
return &Null{}
}
func (a *Array) Prepend(obj Object) {
a.Elements = append([]Object{obj}, a.Elements...)
}
func (a *Array) Append(obj Object) {
a.Elements = append(a.Elements, obj)
}
func (ao *Array) Inspect() string {
var out bytes.Buffer
@@ -32,9 +62,9 @@ func (ao *Array) String() string {
return ao.Inspect()
}
func (a *Array) Less(i, j int) bool {
if cmp, ok := a.Elements[i].(Comparable); ok {
return cmp.Compare(a.Elements[j]) == -1
func (ao *Array) Less(i, j int) bool {
if cmp, ok := ao.Elements[i].(Comparable); ok {
return cmp.Compare(ao.Elements[j]) == -1
}
return false
}