Correct declare_variable example

This commit is contained in:
Shadowfacts 2021-05-16 14:59:08 -04:00
parent 2abf6344d3
commit b3502f257f
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 5 additions and 1 deletions

View File

@ -72,9 +72,13 @@ impl Context {
} }
fn declare_variable(&mut self, name: &str, value: Value) { fn declare_variable(&mut self, name: &str, value: Value) {
if self.variables.contains_key(name) {
panic!("cannot re-declare variable {}", name);
} else {
self.variables.insert(name.into(), value); self.variables.insert(name.into(), value);
} }
} }
}
``` ```
Every `eval_` function has also changed to take a reference to the current context[^1] and the main `eval` function creates a context before evaluating each statement. Every `eval_` function has also changed to take a reference to the current context[^1] and the main `eval` function creates a context before evaluating each statement.