From 01011635598d8a7d84a65e2d0d30646c88ed168a Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 15 Jun 2013 00:49:34 -0400 Subject: [PATCH] environment keys now include parent environments --- builtin.go | 8 -------- env.go | 3 +++ special.go | 9 +++++++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/builtin.go b/builtin.go index f765a3f..8c69394 100644 --- a/builtin.go +++ b/builtin.go @@ -228,11 +228,3 @@ var cdr = builtin{ return s.items[1:], nil }, } - -var names = builtin{ - name: "names", - arity: 0, - fn: func(vals []interface{}) (interface{}, error) { - return universe.keys(), nil - }, -} diff --git a/env.go b/env.go index 2273629..66ef5e4 100644 --- a/env.go +++ b/env.go @@ -46,6 +46,9 @@ func (e environment) keys() []string { for key, _ := range e.items { keys = append(keys, string(key)) } + if e.outer != nil { + keys = append(keys, e.outer.keys()...) + } sort.Strings(keys) return keys } diff --git a/special.go b/special.go index 8f25f35..28a6f17 100644 --- a/special.go +++ b/special.go @@ -272,3 +272,12 @@ var begin = special{ return v, nil }, } + +var names = special{ + name: "names", + arity: 0, + variadic: false, + fn: func(env *environment, args []interface{}) (interface{}, error) { + return env.keys(), nil + }, +}