diff --git a/schemius/src/core/accessor.rs b/schemius/src/core/accessor.rs index 46045d1..afeb919 100644 --- a/schemius/src/core/accessor.rs +++ b/schemius/src/core/accessor.rs @@ -1,53 +1,50 @@ +use core::fmt::Debug; use std::{ - cell::RefCell, + cell::{Ref, RefCell, RefMut}, ops::{Deref, DerefMut}, rc::Rc, - sync::{Arc, Mutex}, + sync::{Arc, Mutex, MutexGuard}, }; -pub trait Accessor<T: Clone> { +pub trait Accessor<T> { fn new(src: T) -> Self; - fn borrow(&self) -> impl Deref<Target = T>; - fn borrow_mut(&self) -> impl DerefMut<Target = T>; + fn access(&self) -> impl Deref<Target = T>; + fn access_mut(&self) -> impl DerefMut<Target = T>; fn replace(&self, src: T) -> T; } -#[derive(Debug, Clone)] -pub struct BaseAccessor<T> { - inner: Rc<RefCell<T>>, -} +#[derive(Clone, Debug)] +pub struct BaseAccessor<T>(Rc<RefCell<T>>); -#[derive(Debug, Clone)] -pub struct ThreadSafeAccessor<T> { - inner: Arc<Mutex<T>>, -} +#[derive(Clone, Debug)] +pub struct ThreadSafeAccessor<T>(Arc<Mutex<T>>); -impl<T: Clone> Accessor<T> for BaseAccessor<T> { +impl<T> Accessor<T> for BaseAccessor<T> { fn new(src: T) -> Self { - Self { inner: Rc::new(RefCell::new(src)) } + Self(Rc::new(RefCell::new(src))) } - fn borrow(&self) -> impl Deref<Target = T> { - self.inner.borrow() + fn access(&self) -> Ref<T> { + self.0.try_borrow().unwrap() } - fn borrow_mut(&self) -> impl DerefMut<Target = T> { - self.inner.borrow_mut() + fn access_mut(&self) -> RefMut<T> { + self.0.try_borrow_mut().unwrap() } fn replace(&self, src: T) -> T { - std::mem::replace(&mut *self.inner.borrow_mut(), src) + std::mem::replace(&mut *self.0.try_borrow_mut().unwrap(), src) } } -impl<T: Clone> Accessor<T> for ThreadSafeAccessor<T> { +impl<T> Accessor<T> for ThreadSafeAccessor<T> { fn new(src: T) -> Self { - Self { inner: Arc::new(Mutex::new(src)) } + Self(Arc::new(Mutex::new(src))) } - fn borrow(&self) -> impl Deref<Target = T> { - self.inner.try_lock().unwrap() + fn access(&self) -> MutexGuard<T> { + self.0.try_lock().unwrap() } - fn borrow_mut(&self) -> impl DerefMut<Target = T> { - self.inner.try_lock().unwrap() + fn access_mut(&self) -> MutexGuard<T> { + self.0.try_lock().unwrap() } fn replace(&self, src: T) -> T { - std::mem::replace(&mut *self.inner.try_lock().unwrap(), src) + std::mem::replace(&mut *self.0.try_lock().unwrap(), src) } } diff --git a/schemius/src/core/builtins/base_procs.rs b/schemius/src/core/builtins/base_procs.rs index 12e4463..8ffd0bc 100644 --- a/schemius/src/core/builtins/base_procs.rs +++ b/schemius/src/core/builtins/base_procs.rs @@ -15,7 +15,7 @@ pub fn r_apply(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { to_be_evaluated.push(proc.clone()); match args { - SExpr::List(list) => list.borrow().iter().for_each(|arg| to_be_evaluated.push(arg.clone())), + SExpr::List(list) => list.access().iter().for_each(|arg| to_be_evaluated.push(arg.clone())), other => return Err(format!("Exception in #<apply>: {} is not a list", other)), } @@ -36,7 +36,7 @@ pub fn r_display(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { } match args.s_car().unwrap() { - SExpr::String(string) => Ok(SExpr::Symbol(string.borrow().to_string())), // Avoids double quotes + SExpr::String(string) => Ok(SExpr::Symbol(string.access().to_string())), // Avoids double quotes expr => Ok(SExpr::Symbol(format!("{}", expr))), } } @@ -53,7 +53,7 @@ pub fn r_environment_bindings(args: ProcedureArgs, env: ProcedureEnv) -> Procedu )); } - let env_guard = env.borrow(); + let env_guard = env.access(); let mut bindings = env_guard.get_bindings().clone(); bindings.sort_by(|a, b| a.0.cmp(b.0)); diff --git a/schemius/src/core/builtins/list_procs.rs b/schemius/src/core/builtins/list_procs.rs index 8c4c8cc..b751a02 100644 --- a/schemius/src/core/builtins/list_procs.rs +++ b/schemius/src/core/builtins/list_procs.rs @@ -12,11 +12,11 @@ pub fn r_set_car(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { match args.s_car().unwrap() { SExpr::List(list) => { - list.borrow_mut().set_car(args.s_cadr().unwrap().clone()); + list.access_mut().set_car(args.s_cadr().unwrap().clone()); Ok(SExpr::Unspecified) } SExpr::Pair(pair) => { - let old_cdr = pair.borrow().1.clone(); + let old_cdr = pair.access().1.clone(); pair.replace((Box::new(args.s_cadr().unwrap().clone()), old_cdr)); Ok(SExpr::Unspecified) @@ -36,7 +36,7 @@ pub fn r_cons(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { SExpr::List(list) => { let mut new_list = vec![]; new_list.push(car); - list.borrow_mut().iter().for_each(|x| new_list.push(x.clone())); + list.access_mut().iter().for_each(|x| new_list.push(x.clone())); Ok(SExpr::List(SchemeList::new(new_list))) } @@ -84,11 +84,11 @@ pub fn r_car(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { match &args.s_car().unwrap() { SExpr::Pair(pair) => { - let car = pair.borrow().0.clone(); + let car = pair.access().0.clone(); Ok(*car) } SExpr::List(list) => { - let borrowed = list.borrow(); + let borrowed = list.access(); if borrowed.s_len() > 0 { let car = if borrowed.s_car().unwrap().is_quote().unwrap() { borrowed.s_cdr().unwrap().s_car().unwrap().clone() @@ -111,11 +111,11 @@ pub fn r_cdr(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { match args.s_car().unwrap() { SExpr::Pair(pair) => { - let cdr = pair.borrow().1.clone(); + let cdr = pair.access().1.clone(); Ok(*cdr) } SExpr::List(list) => { - let list = list.borrow(); + let list = list.access(); match list.s_len() { 1.. => { @@ -165,7 +165,7 @@ pub fn r_list_ref(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { match args.s_car().unwrap() { SExpr::List(list) => { let index = args.s_cadr().unwrap().as_int().unwrap() as usize; - let borrowed = list.borrow(); + let borrowed = list.access(); let len = borrowed.s_len(); if index >= len { @@ -190,7 +190,7 @@ pub fn r_list_tail(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { match args.s_car().unwrap() { SExpr::List(list) => { let index = args.s_cadr().unwrap().as_int()? as usize; - let borrowed = list.borrow(); + let borrowed = list.access(); let len = borrowed.s_len(); if index >= len { @@ -214,7 +214,7 @@ pub fn r_reverse(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { match args.s_car().unwrap() { SExpr::List(list) => { - let reversed = list.borrow().s_reverse(); + let reversed = list.access().s_reverse(); Ok(SExpr::List(SchemeList::new(reversed))) } _ => Err(String::from("Exception in #<reverse>: expected a list")), @@ -229,7 +229,7 @@ pub fn r_length(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { match args.s_car().unwrap() { SExpr::List(list) => { - let len = list.borrow().s_len(); + let len = list.access().s_len(); Ok(SExpr::Number(SNumber::Int(NativeInt::from(len as NativeInt)))) } _ => Err(String::from("Exception in #<length>: expected a list")), diff --git a/schemius/src/core/builtins/special_forms.rs b/schemius/src/core/builtins/special_forms.rs index 7adfc66..87b8042 100644 --- a/schemius/src/core/builtins/special_forms.rs +++ b/schemius/src/core/builtins/special_forms.rs @@ -30,7 +30,7 @@ pub fn r_lambda(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput { } let arg_names = match args.s_car().unwrap() { - SExpr::List(ref list) => match list_args(&list.borrow()) { + SExpr::List(ref list) => match list_args(&list.access()) { Ok(names) => names, Err(e) => return Err(e), }, @@ -53,7 +53,7 @@ pub fn r_define(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput { other => other, }; - match env.borrow_mut().define(name, &value) { + match env.access_mut().define(name, &value) { Ok(_) => Ok(SExpr::Ok), Err(_) => Err(format!("Exception: error defining {}", name)), } @@ -61,16 +61,16 @@ pub fn r_define(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput { Err(e) => Err(e), }, SExpr::List(list) => { - if list.borrow().s_len() == 0 { + if list.access().s_len() == 0 { return Err(String::from("Exception (TODO?): deal with empty lists")); } - let lambda_name = list.borrow().s_car().unwrap().to_string(); + let lambda_name = list.access().s_car().unwrap().to_string(); let mut lambda_args: Vec<SExpr> = vec![]; let lambda_body = &mut args.s_cdr().unwrap(); - if list.borrow().s_len() > 1 { - for arg in &list.borrow()[1..] { + if list.access().s_len() > 1 { + for arg in &list.access()[1..] { lambda_args.push(arg.clone()); } } @@ -83,7 +83,7 @@ pub fn r_define(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput { Err(e) => return Err(e), }; - match env.borrow_mut().define(&lambda_name, &lambda_proc) { + match env.access_mut().define(&lambda_name, &lambda_proc) { Ok(_) => Ok(SExpr::Ok), Err(_) => Err(String::from("")), } @@ -110,7 +110,7 @@ pub fn r_set(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput { other => other, }; - match env.borrow_mut().set(&name, &value) { + match env.access_mut().set(&name, &value) { Ok(_) => Ok(SExpr::Ok), Err(e) => Err(e), } @@ -134,15 +134,15 @@ pub fn r_let(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput { match args.s_car().unwrap() { SExpr::List(list) => { - for binding in list.borrow().iter() { + for binding in list.access().iter() { match binding { SExpr::List(binding) => { - let borrowed_binding = binding.borrow(); + let borrowed_binding = binding.access(); match borrowed_binding.s_car().unwrap() { SExpr::Symbol(symbol) => { match eval(&borrowed_binding[1], env.clone()) { Ok(expr) => { - let_env.borrow_mut().define(&symbol, &expr).unwrap() + let_env.access_mut().define(&symbol, &expr).unwrap() } Err(e) => return Err(e), } @@ -181,17 +181,17 @@ pub fn r_let_star(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput { match args.s_car().unwrap() { SExpr::List(list) => { - for binding in list.borrow().iter() { + for binding in list.access().iter() { match binding { SExpr::List(binding) => { - let borrowed_binding = binding.borrow(); + let borrowed_binding = binding.access(); match &borrowed_binding[0] { SExpr::Symbol(symbol) => { match eval(&borrowed_binding[1], inner_env.clone()) { Ok(expr) => { inner_env = Environment::new_child(inner_env.clone()); inner_env = Environment::new_child(inner_env.clone()); - inner_env.borrow_mut().define(&symbol, &expr).unwrap(); + inner_env.access_mut().define(&symbol, &expr).unwrap(); } Err(e) => return Err(e), } @@ -331,7 +331,7 @@ pub fn r_quasiquote(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput // After each and every unquoting indexes will be shifted by a certain offset let mut offset: i32 = 0; - let mut borrowed_list = list.borrow_mut(); + let mut borrowed_list = list.access_mut(); loop { if unquotes.is_empty() { @@ -382,7 +382,7 @@ pub fn r_quasiquote(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput if let SExpr::Symbol(symbol) = suspect { if !env - .borrow() + .access() .get(&symbol) .unwrap() .is_procedure() @@ -409,7 +409,7 @@ pub fn r_quasiquote(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput } // Unquoting symbol or atom None => { - to_be_evaluated = list.borrow()[unquote_index + 1].clone(); + to_be_evaluated = list.access()[unquote_index + 1].clone(); first_idx = unquote_index - 1; // Index of the left parenthesis preceding the unquote symbol last_idx = unquote_index + 3; // Index of the right parenthesis + 1 } @@ -425,14 +425,14 @@ pub fn r_quasiquote(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput match evaluated { Ok(ref res) => match res { SExpr::List(internal) => { - let borrowed_internal = internal.borrow(); + let borrowed_internal = internal.access(); offset -= (borrowed_internal.s_len() - 1) as i32; for i in (first_idx..last_idx).rev() { borrowed_list.remove(i); } - for i in (0..internal.borrow().s_len()).rev() { + for i in (0..internal.access().s_len()).rev() { borrowed_list.splice( first_idx..first_idx, [borrowed_internal[i].clone()], @@ -484,16 +484,16 @@ pub fn r_cond(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput { for block in iterator { match block { SExpr::List(list) => { - if list.borrow().s_len() != 2 { + if list.access().s_len() != 2 { return Err(String::from( "Exception: malformed args provided to #<procedure cond>", )); } - let first = eval(&list.borrow()[0], env.clone()); + let first = eval(&list.access()[0], env.clone()); match first { Ok(condition) => match condition { SExpr::Boolean(val) => match val { - true => return Ok(list.borrow()[1].clone()), + true => return Ok(list.access()[1].clone()), false => continue, }, _ => { diff --git a/schemius/src/core/builtins/string_procs.rs b/schemius/src/core/builtins/string_procs.rs index d9ae931..0443402 100644 --- a/schemius/src/core/builtins/string_procs.rs +++ b/schemius/src/core/builtins/string_procs.rs @@ -65,7 +65,7 @@ pub fn r_string_append(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput for arg in args { match arg { - SExpr::String(string) => output.push_str(string.borrow().as_str()), + SExpr::String(string) => output.push_str(string.access().as_str()), other => return Err(format!("Exception in string-append: {} is not a string", other)), } } @@ -83,10 +83,10 @@ pub fn r_string_ref(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { SExpr::String(string) => match args.s_cadr().unwrap() { SExpr::Number(index) => { let index = index.to_int().unwrap() as usize; - let is_in_range = index < string.borrow().len(); + let is_in_range = index < string.access().len(); if is_in_range { - let character = string.borrow().chars().nth(index).unwrap(); + let character = string.access().chars().nth(index).unwrap(); Ok(SExpr::Char(character)) } else { Err("Exception in string-ref: index out of range".to_string()) @@ -111,17 +111,17 @@ pub fn r_string_set(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput { SExpr::String(string) => match args.s_cadr().unwrap() { SExpr::Number(index) => { let index = index.to_int().unwrap() as usize; - let is_in_range = index < string.borrow().len(); + let is_in_range = index < string.access().len(); if is_in_range { match &args[2] { SExpr::Char(character) => { let replacement = character.to_string(); string - .borrow_mut() + .access_mut() .replace_range(index..index + 1, replacement.as_str()); - let output = string.borrow().clone(); + let output = string.access().clone(); Ok(SExpr::String(SchemeString::new(output))) } other => Err(format!("Exception in string-set!: {} is not a char", other)), @@ -144,7 +144,7 @@ pub fn r_string_upcase(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput match args.s_car().unwrap() { SExpr::String(string) => { - let output = string.borrow().to_uppercase(); + let output = string.access().to_uppercase(); Ok(SExpr::String(SchemeString::new(output))) } other => Err(format!("Exception in string-upcase: {} is not a string", other)), @@ -159,7 +159,7 @@ pub fn r_string_downcase(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutpu match args.s_car().unwrap() { SExpr::String(string) => { - let output = string.borrow().to_lowercase(); + let output = string.access().to_lowercase(); Ok(SExpr::String(SchemeString::new(output))) } other => Err(format!("Exception in string-downcase: {} is not a string", other)), @@ -174,7 +174,7 @@ pub fn r_string_length(args: ProcedureArgs, _: ProcedureEnv) -> ProcedureOutput match args.s_car().unwrap() { SExpr::String(string) => { - let length = string.borrow().len(); + let length = string.access().len(); Ok(SExpr::Number(SchemeNumber::Int(length as NativeInt))) } other => Err(format!("Exception in string-length: {} is not a string", other)), diff --git a/schemius/src/core/environment.rs b/schemius/src/core/environment.rs index 1e18cf8..0f98b31 100644 --- a/schemius/src/core/environment.rs +++ b/schemius/src/core/environment.rs @@ -50,7 +50,7 @@ impl SchemeEnvironment for Environment { Ok(()) } else { match self.parent { - Some(ref parent) => parent.borrow_mut().set(key, value), + Some(ref parent) => parent.access_mut().set(key, value), None => Err(format!("Exception: {} is not bound", key)), } } @@ -60,7 +60,7 @@ impl SchemeEnvironment for Environment { match self.table.get(key) { Some(val) => Some(val.clone()), None => match self.parent { - Some(ref parent) => parent.borrow().get(key), + Some(ref parent) => parent.access().get(key), None => None, }, } @@ -73,7 +73,7 @@ impl SchemeEnvironment for Environment { } fn get_root(env: ProcedureEnv) -> ProcedureEnv { - match &env.borrow().parent { + match &env.access().parent { Some(frame) => Environment::get_root(frame.clone()), None => env.clone(), } diff --git a/schemius/src/core/evaluator.rs b/schemius/src/core/evaluator.rs index 45991f8..9d2aadf 100644 --- a/schemius/src/core/evaluator.rs +++ b/schemius/src/core/evaluator.rs @@ -53,7 +53,7 @@ pub fn eval(expression: &SExpr, env: ProcedureEnv) -> EvalOutput { loop { match current_expression { SExpr::Symbol(ref val) => { - return match current_env.borrow().get(val) { + return match current_env.access().get(val) { Some(v) => Ok(v), None => Err(format!( "Exception: in eval: could not find a value bound to <{}>", @@ -62,12 +62,12 @@ pub fn eval(expression: &SExpr, env: ProcedureEnv) -> EvalOutput { } } SExpr::List(list) => { - if list.borrow().s_len() > 0 { - let first = eval(list.borrow().s_car().unwrap(), current_env.clone()); + if list.access().s_len() > 0 { + let first = eval(list.access().s_car().unwrap(), current_env.clone()); match first { Ok(res) => match res { SExpr::Procedure(proc) => { - let args = list.borrow().s_cdr().unwrap(); + let args = list.access().s_cdr().unwrap(); match proc { Procedure::SpecialForm(special_form) => { @@ -125,7 +125,7 @@ pub fn eval(expression: &SExpr, env: ProcedureEnv) -> EvalOutput { for (name, arg) in arg_names.iter().zip(expanded_args.iter()) { - if lambda_env.borrow_mut().define(&name, &arg).is_err() + if lambda_env.access_mut().define(&name, &arg).is_err() { return Err(String::from("Exception: could not bind value to the procedure frame")); } diff --git a/schemius/src/core/s_expression/mod.rs b/schemius/src/core/s_expression/mod.rs index 0b946d4..b0f5a47 100644 --- a/schemius/src/core/s_expression/mod.rs +++ b/schemius/src/core/s_expression/mod.rs @@ -51,25 +51,25 @@ impl fmt::Display for SExpr { SExpr::Char(val) => write!(f, "#\\{}", val), SExpr::Number(val) => write!(f, "{}", val), SExpr::Boolean(val) => write!(f, "#{}", if *val { "t" } else { "f" }), - SExpr::String(ref val) => write!(f, "\"{}\"", *val.borrow()), + SExpr::String(ref val) => write!(f, "\"{}\"", *val.access()), SExpr::Procedure(app) => match app { Procedure::SpecialForm(_) => write!(f, "#<special form>"), Procedure::Primitive(_) => write!(f, "#<primitive>"), Procedure::Compound(args, _, _) => write!(f, "#<procedure ({})>", args.join(", ")), }, SExpr::Pair(val) => { - let borrowed_val = val.borrow(); + let borrowed_val = val.access(); write!(f, "({} . {})", borrowed_val.0, borrowed_val.1) } SExpr::List(ref val) => write!( f, "({})", - val.borrow().iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" ") + val.access().iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" ") ), SExpr::Vector(ref val) => write!( f, "#({})", - val.borrow().iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" ") + val.access().iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" ") ), SExpr::Unspecified => writeln!(f), SExpr::Ok => write!(f, "ok"), @@ -94,7 +94,7 @@ impl SExpr { pub fn as_list(&self) -> Result<ListImplementation, String> { Ok(match self { - SExpr::List(list) => list.borrow().clone(), + SExpr::List(list) => list.access().clone(), _ => panic!("Exception: {} is not a list", self), }) } @@ -106,7 +106,7 @@ impl SExpr { pub fn unquote(&self) -> Result<SExpr, String> { match self { SExpr::List(list) => { - let borrowed_list = list.borrow(); + let borrowed_list = list.access(); if borrowed_list.first().unwrap().is_quote().unwrap() { Ok(borrowed_list[1].clone()) } else { @@ -168,7 +168,7 @@ impl SExpr { pub fn is_applyable(&self) -> Result<bool, String> { match self { - SExpr::List(list) if list.borrow().s_car().unwrap().is_procedure()? => Ok(true), + SExpr::List(list) if list.access().s_car().unwrap().is_procedure()? => Ok(true), _ => Ok(false), } } @@ -183,7 +183,7 @@ impl SExpr { pub fn is_quoted_list(&self) -> Result<bool, String> { match self { SExpr::List(list) => { - let borrowed = list.borrow(); + let borrowed = list.access(); if borrowed.s_len() > 0 { let car = borrowed.s_car().unwrap(); match car { @@ -359,7 +359,7 @@ impl SExpr { pub fn is_null(&self) -> result::Result<bool, String> { match self { SExpr::List(list) => { - if list.borrow().is_empty() { + if list.access().is_empty() { Ok(true) } else { Ok(false) @@ -372,7 +372,7 @@ impl SExpr { pub fn matching_brackets(&self) -> Option<Vec<(usize, usize, usize)>> { match self { SExpr::List(list) => { - let list = list.borrow(); + let list = list.access(); if !list.first().unwrap().symbol_is("(").unwrap() { return None; } @@ -430,7 +430,7 @@ impl SExpr { pub fn find_symbol(&self, symbol: &str) -> Option<Vec<usize>> { match self.flatten() { Ok(SExpr::List(flattened)) => { - let borrowed_flattened = flattened.borrow(); + let borrowed_flattened = flattened.access(); if borrowed_flattened.first().unwrap().symbol_is("(").unwrap() { return None; @@ -459,10 +459,10 @@ impl SExpr { let mut flattened = vec![]; flattened.push(SExpr::Symbol(String::from("("))); - list.borrow().iter().for_each(|item| match item { + list.access().iter().for_each(|item| match item { SExpr::List(_) => { if let Ok(SExpr::List(internal)) = item.flatten() { - internal.borrow().iter().for_each(|x| flattened.push(x.clone())) + internal.access().iter().for_each(|x| flattened.push(x.clone())) } } other => flattened.push(other.clone()), @@ -473,7 +473,7 @@ impl SExpr { Ok(SExpr::List(SchemeList::new(flattened.clone()))) } SExpr::Pair(pair) => { - let pair = pair.borrow(); + let pair = pair.access(); SExpr::List(SchemeList::new(vec![ *pair.0.clone(), SExpr::Symbol(".".to_string()), @@ -490,7 +490,7 @@ impl SExpr { match self { SExpr::List(list) => { let cloned = list.clone(); - let mut unflattened = cloned.borrow_mut(); + let mut unflattened = cloned.access_mut(); if !unflattened.first().unwrap().symbol_is("(").unwrap() { return Ok(self.clone());