pub struct Env { /* private fields */ }Expand description
An evaluation environment mapping variable names to values.
Environments are immutable, and extending one shares it rather than copying
it: the extension holds a reference to the scope it extends, so binding a
name costs the same whatever else is in scope. That matters because the
evaluator extends the environment on every let, every lambda, and every
closure application.
A name bound twice is shadowed by the inner binding, and only the inner one
is observable: get returns it, iter yields it, and
len counts the name once.
Implementations§
Source§impl Env
impl Env
Sourcepub fn extend(&self, name: Arc<str>, value: Literal) -> Self
pub fn extend(&self, name: Arc<str>, value: Literal) -> Self
Extend the environment with a new binding, returning a new environment.
The environment extended is left as it was, and is shared rather than copied, so this costs the same at any width.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Arc<str>, &Literal)>
pub fn iter(&self) -> impl Iterator<Item = (&Arc<str>, &Literal)>
Iterate over the bindings in scope, in name order, each name once.
Name order rather than the order the bindings arrived in, so that two environments holding the same bindings read the same however they were assembled — which is what lets a hash or an encoding taken over an environment be a function of what it binds.