forked from shadowfacts/shadowfacts.net
Correct declare_variable example
This commit is contained in:
parent
2abf6344d3
commit
b3502f257f
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue