pub struct Function {
pub parameters: Vec<String>,
pub body: Vec<Statement>,
pub env: EnvRef,
}
Expand description
This struct is how the interpreter stores functions. It contains the function’s parameters, body and a reference to the environment in which it was defined.
By keeping a reference to the environment where the function was created, the interpreter can access the variables within that environment when the function is called. This also enables the interpreter to create closures.
Closures are functions that retain access to the environment in which they were defined. Even if that environment goes out of scope, the function holds onto that environment, keeping it alive, allowing it to still access the variables within.
Fields§
§parameters: Vec<String>
§body: Vec<Statement>
§env: EnvRef
Trait Implementations§
Source§impl Debug for Function
Implementing the Debug
trait for Function
allows printing of the function’s
parameters and the number of statements in its body.
impl Debug for Function
Implementing the Debug
trait for Function
allows printing of the function’s
parameters and the number of statements in its body.
impl StructuralPartialEq for Function
Auto Trait Implementations§
impl Freeze for Function
impl !RefUnwindSafe for Function
impl !Send for Function
impl !Sync for Function
impl Unpin for Function
impl !UnwindSafe for Function
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more