Environment

Struct Environment 

Source
pub struct Environment { /* private fields */ }
Expand description

An environment frame (variable bindings)

Corresponds to OpenJade’s environment frames in Interpreter.

§Lexical Scoping

Each frame has:

  • bindings: Variables defined in this frame
  • parent: Enclosing scope (None for global environment)

Variable lookup walks up the parent chain until found or global reached.

Implementations§

Source§

impl Environment

Source

pub fn new_global() -> Gc<Self>

Create a new global (top-level) environment

Source

pub fn extend(parent: Gc<Environment>) -> Gc<Self>

Create a new child environment extending the given parent

Used for:

  • Function calls (parameters in new scope)
  • let, let*, letrec bindings
  • Internal defines
Source

pub fn define(&self, name: &str, value: Value)

Define a variable in this environment (set binding)

Mutates the current frame.

Used for:

  • define expressions
  • Function parameter bindings
  • let bindings
§DSSSL Note

DSSSL is mostly functional, but define at top-level is imperative. Internal defines in lambda bodies create a new frame.

Source

pub fn lookup(&self, name: &str) -> Option<Value>

Look up a variable in this environment or any parent

Returns None if variable is undefined.

Walks up the parent chain until:

  • Variable found → return value
  • Global reached and not found → return None

Corresponds to OpenJade’s Interpreter::lookup().

Source

pub fn set(&self, name: &str, value: Value) -> Result<(), String>

Set an existing variable (mutation)

Returns Ok(()) if variable found and updated, Err if not found.

Used for:

  • set! expressions
§R4RS vs DSSSL

R4RS allows set! on any variable. DSSSL restricts mutation (mostly functional). For now, we allow it (OpenJade does).

Source

pub fn is_defined(&self, name: &str) -> bool

Check if a variable is defined in this environment or any parent

Source

pub fn parent(&self) -> Option<Gc<Environment>>

Get the parent environment (if any)

Source

pub fn local_bindings(&self) -> Vec<(Rc<str>, Value)>

Get all bindings in this frame (not including parents)

Used for debugging and introspection.

Trait Implementations§

Source§

impl Clone for Environment

Source§

fn clone(&self) -> Environment

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Environment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Environment

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Finalize for Environment

Source§

impl Trace for Environment

Source§

unsafe fn trace(&self)

Marks all contained Gcs.
Source§

unsafe fn root(&self)

Increments the root-count of all contained Gcs.
Source§

unsafe fn unroot(&self)

Decrements the root-count of all contained Gcs.
Source§

fn finalize_glue(&self)

Runs Finalize::finalize() on this object and all contained subobjects

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.