Пример #1
0
func NewRootScope() *Scope {
	root := NewScope(nil)
	root.Put("+", primitives.NewAdd())
	root.Put("-", primitives.NewSub())
	root.Put("*", primitives.NewMult())
	root.Put("/", primitives.NewDiv())
	root.Put("=", primitives.NewEq())
	root.Put(">", primitives.NewGt())
	root.Put(">=", primitives.NewGtE())
	root.Put("<", primitives.NewLt())
	root.Put("<=", primitives.NewLtE())
	root.Put("%", primitives.NewMod())
	root.Put("and", primitives.NewAnd())
	root.Put("or", primitives.NewOr())
	root.Put("eqv?", primitives.NewIsEqv())
	root.Put("type-of", primitives.NewTypeOf())
	root.Put("display", primitives.NewDisplay())
	root.Put("newline", primitives.NewNewline())
	root.Put("car", primitives.NewCar())
	root.Put("cdr", primitives.NewCdr())
	root.Put("cons", primitives.NewCons())
	root.Put("make-chan", primitives.NewMakeChan())
	root.Put("close-chan", primitives.NewCloseChan())
	root.Put("<-chan", primitives.NewChanRecv())
	root.Put("chan<-", primitives.NewChanSend())
	root.Put("sleep", primitives.NewSleep())
	root.Put("random", primitives.NewRandom())
	root.Put("#t", value.NewBoolValue(true))
	root.Put("#f", value.NewBoolValue(false))
	return root
}
Пример #2
0
func (self *Eq) Apply(args []value.Value) value.Value {
	checkargsnumber(args, 2)
	if v1, ok := args[0].(*value.IntValue); ok {
		if v2, ok := args[1].(*value.IntValue); ok {
			return value.NewBoolValue(v1.Value == v2.Value)
		} else if v2, ok := args[1].(*value.FloatValue); ok {
			return value.NewBoolValue(float64(v1.Value) == v2.Value)
		}
	} else if v1, ok := args[0].(*value.FloatValue); ok {
		if v2, ok := args[1].(*value.IntValue); ok {
			return value.NewBoolValue(v1.Value == float64(v2.Value))
		} else if v2, ok := args[1].(*value.FloatValue); ok {
			return value.NewBoolValue(v1.Value == v2.Value)
		}
	}
	panic(fmt.Sprint("incorrect argument type for `=', expected number?"))
}
Пример #3
0
func (self *Or) Apply(args []value.Value) value.Value {
	result := false
	for _, arg := range args {
		if val, ok := arg.(*value.BoolValue); ok {
			result = result || val.Value
		} else {
			panic(fmt.Sprint("incorrect argument type for `or', expected bool?"))
		}
	}
	return value.NewBoolValue(result)
}