func BindArguments(env *scope.Scope, params Node, args Value) { if name, ok := params.(*Name); ok && args == NilPairValue { // ((lambda x <body>) '()) env.Put(name.Identifier, args) return } for { if params == NilPair && args == NilPairValue { return } else if params == NilPair && args != NilPairValue { panic(fmt.Sprint("too many arguments")) } else if params != NilPair && args == NilPairValue { panic(fmt.Sprint("missing arguments")) } switch params.(type) { case *Pair: // R5RS declare first element must be a *Name* name, _ := params.(*Pair).First.(*Name) pair, ok := args.(*PairValue) if !ok { panic(fmt.Sprint("arguments does not match given number")) } env.Put(name.Identifier, pair.First) params = params.(*Pair).Second args = pair.Second case *Name: env.Put(params.(*Name).Identifier, args) return } } }
func Define(env *scope.Scope, pattern string, value interface{}) { env.Put(pattern, value) }