Exemple #1
0
func check(operands []interface{}, types []int, compi compiType, compf compfType, comps compsType) value.Value {
	typ := types[0]

	for i, _ := range operands {
		if i == 0 {
			continue
		}
		switch typ {
		case 0: // int
			if !compi(operands[i-1].(int64), operands[i].(int64)) {
				return value.NewBool(false)
			}
		case 1: // float
			if !compf(operands[i-1].(float64), operands[i].(float64)) {
				return value.NewBool(false)
			}
		case 2: // string
			if !comps(operands[i-1].(string), operands[i].(string)) {
				return value.NewBool(false)
			}
		}
	}

	return value.NewBool(true)
}
Exemple #2
0
func (self *IsEqv) Call(args ...value.Value) value.Value {
	if len(args) != 2 {
		panic(fmt.Errorf("eqv?: unexpeced arguments number, expected: 2, given %v", len(args)))
	}

	if args[0].String() != args[1].String() {
		return value.NewBool(false)
	}

	var ok bool
	switch args[0].(type) {
	case *value.Bool:
		_, ok = args[1].(*value.Bool)
	case *value.Int:
		_, ok = args[1].(*value.Int)
	case *value.Char:
		_, ok = args[1].(*value.Char)
	case *value.String:
		_, ok = args[1].(*value.String)
	case *value.Float:
		_, ok = args[1].(*value.Float)
	case *value.Symbol:
		_, ok = args[1].(*value.Symbol)
	case *value.List:
		_, ok = args[1].(*value.List)
	case *value.Vect:
		_, ok = args[1].(*value.Vect)
	case *value.Closure:
		_, ok = args[1].(*value.Closure)
	case *value.Chan:
		_, ok = args[1].(*value.Chan)
	}
	return value.NewBool(ok)
}
Exemple #3
0
func (self *IsNull) Call(args ...value.Value) value.Value {
	if len(args) != 1 {
		panic(fmt.Errorf("null?: arity mismatch, expected 1, given %v\n", len(args)))
	}

	if arg, ok := args[0].(*value.List); !ok {
		panic(fmt.Errorf("null?: contract violation, expected: list?"))
	} else {
		if arg.Empty() {
			return value.NewBool(true)
		} else {
			return value.NewBool(false)
		}
	}

	return nil
}
Exemple #4
0
func (self *Bool) Eval(env *scope.Scope) value.Value {
	return value.NewBool(self.value)
}