type checking and error handling for builtins improved.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user