use std::{
rc::Rc,
cell::RefCell,
};
use crate::common::{
stamp::stamp,
lambda::Lambda,
data::Data,
};
#[derive(Debug, Clone, PartialEq)]
pub struct Closure {
pub id: String,
pub lambda: Lambda,
pub captures: Vec<Rc<RefCell<Data>>>,
}
impl Closure {
pub fn wrap(lambda: Lambda) -> Closure {
Closure {
id: stamp(0),
lambda,
captures: vec![],
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::common::lambda::Lambda;
#[test]
fn unique() {
let lambda = Lambda::empty();
let a = Closure::wrap(lambda.clone());
let b = Closure::wrap(lambda.clone());
assert_ne!(a.id, b.id);
}
}