Eval complete

This commit is contained in:
Chuck Smith
2024-01-20 11:16:56 -05:00
parent 581573486c
commit 10821fc88a
4 changed files with 183 additions and 4 deletions

View File

@@ -1,16 +1,26 @@
package object
func NewEnclosedEnvironment(outer *Environment) *Environment {
env := NewEnvironment()
env.outer = outer
return env
}
func NewEnvironment() *Environment {
s := make(map[string]Object)
return &Environment{store: s}
return &Environment{store: s, outer: nil}
}
type Environment struct {
store map[string]Object
outer *Environment
}
func (e *Environment) Get(name string) (Object, bool) {
obj, ok := e.store[name]
if !ok && e.outer != nil {
obj, ok = e.outer.Get(name)
}
return obj, ok
}