|
|
@ -15,7 +15,11 @@ func define(env *environment, args ...interface{}) (interface{}, error) {
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf(`first argument to *define* must be symbol, received %v`, reflect.TypeOf(args[0]))
|
|
|
|
return nil, fmt.Errorf(`first argument to *define* must be symbol, received %v`, reflect.TypeOf(args[0]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env.set(s, args[1])
|
|
|
|
v, err := eval(args[1], env)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
env.set(s, v)
|
|
|
|
return nil, nil
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -36,3 +40,22 @@ func _if(env *environment, args ...interface{}) (interface{}, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return eval(args[1], env)
|
|
|
|
return eval(args[1], env)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set(env *environment, args ...interface{}) (interface{}, error) {
|
|
|
|
|
|
|
|
if len(args) != 2 {
|
|
|
|
|
|
|
|
return nil, fmt.Errorf(`received %d arguments in *set!*, expected exactly 2`, len(args))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s, ok := args[0].(symbol)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
return nil, fmt.Errorf(`first argument to *set!* must be symbol, received %v`, reflect.TypeOf(args[0]))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !env.defined(s) {
|
|
|
|
|
|
|
|
return nil, fmt.Errorf(`cannot *set!* undefined symbol %v`, s)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
v, err := eval(args[1], env)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
env.set(s, v)
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
|
|
|
}
|
|
|
|