diff options
Diffstat (limited to 'src/eval/scope.rs')
| -rw-r--r-- | src/eval/scope.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/eval/scope.rs b/src/eval/scope.rs index a3c9234b..cfa2bccd 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -31,12 +31,8 @@ impl<'a> Scopes<'a> { } /// Create a new hierarchy of scopes with a base scope. - pub fn with_base(base: &'a Scope) -> Self { - Self { - top: Scope::new(), - scopes: vec![], - base: Some(base), - } + pub fn with_base(base: Option<&'a Scope>) -> Self { + Self { top: Scope::new(), scopes: vec![], base } } /// Enter a new scope. @@ -131,6 +127,11 @@ impl Scope { pub fn get(&self, var: &str) -> Option<&Slot> { self.values.get(var) } + + /// Iterate over all definitions. + pub fn iter(&self) -> impl Iterator<Item = (&str, &Slot)> { + self.values.iter().map(|(k, v)| (k.as_str(), v)) + } } impl Debug for Scope { |
