environment keys now include parent environments

master
Jordan Orelli 12 years ago
parent b6948645bd
commit 0101163559

@ -228,11 +228,3 @@ var cdr = builtin{
return s.items[1:], nil return s.items[1:], nil
}, },
} }
var names = builtin{
name: "names",
arity: 0,
fn: func(vals []interface{}) (interface{}, error) {
return universe.keys(), nil
},
}

@ -46,6 +46,9 @@ func (e environment) keys() []string {
for key, _ := range e.items { for key, _ := range e.items {
keys = append(keys, string(key)) keys = append(keys, string(key))
} }
if e.outer != nil {
keys = append(keys, e.outer.keys()...)
}
sort.Strings(keys) sort.Strings(keys)
return keys return keys
} }

@ -272,3 +272,12 @@ var begin = special{
return v, nil return v, nil
}, },
} }
var names = special{
name: "names",
arity: 0,
variadic: false,
fn: func(env *environment, args []interface{}) (interface{}, error) {
return env.keys(), nil
},
}

Loading…
Cancel
Save