Ejemplo n.º 1
0
/*
This method evaluates the element using the first and second value
and returns the result value. If the second operand type is missing
then return a missing value. If it is a number, check if it is an
absolute number (equal to its trucated value), and return the element
at that index using the Index method. If it isnt a number or missing,
then check the first elements type. If it is missing return missing
otherwise return null value.
*/
func (this *Element) Apply(context Context, first, second value.Value) (value.Value, error) {
	switch second.Type() {
	case value.NUMBER:
		s := second.Actual().(float64)
		if s == math.Trunc(s) {
			v, _ := first.Index(int(s))
			return v, nil
		}
	case value.MISSING:
		return value.MISSING_VALUE, nil
	}

	if first.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else {
		return value.NULL_VALUE, nil
	}
}