Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/domains/prim_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ pub static FIX: Lazy<Val> = Lazy::new(|| PrimFun(CurriedFn::new(Symbol::from("fi
fn fix(mut args: Env, handle: &Evaluator) -> VResult {
handle.data.borrow_mut().fix_counter += 1;
if handle.data.borrow().fix_counter > MAX_FIX_INVOCATIONS {
return Err(format!("Exceeded max number of fix invocations. Max was {}", MAX_FIX_INVOCATIONS));
return Err(format!("Exceeded max number of fix invocations. Max was {MAX_FIX_INVOCATIONS}"));
}
load_args!(args, fn_val: Val, x: Val);

// fix f x = f(fix f)(x)
let fixf = handle.apply(FIX.clone(), fn_val.clone()).unwrap();
let res = match handle.apply(fn_val, fixf) {
Ok(ffixf) => handle.apply(ffixf, x),
Err(err) => Err(format!("Could not apply fixf to f: {}",err))
Err(err) => Err(format!("Could not apply fixf to f: {err}"))
};
handle.data.borrow_mut().fix_counter -= 1;
res
Expand Down Expand Up @@ -336,6 +336,6 @@ mod tests {
assert_error::<ListVal, Val>(
"(fix1 $0 (lam (lam (if (empty? $0) $0 (cons (+ 1 (car $0)) ($1 $0))))))",
&[arg],
format!("Exceeded max number of fix invocations. Max was {}", MAX_FIX_INVOCATIONS));
format!("Exceeded max number of fix invocations. Max was {MAX_FIX_INVOCATIONS}"));
}
}
34 changes: 17 additions & 17 deletions src/parse_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ impl Display for Node {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Var(i, tag) => {
write!(f, "${}", i)?;
write!(f, "${i}")?;
if *tag != -1 {
write!(f, "_{}", tag)?;
write!(f, "_{tag}")?;
}
Ok(())
},
Self::Prim(p) => write!(f,"{}",p),
Self::Prim(p) => write!(f,"{p}"),
Self::App(_,_) => write!(f,"app"),
Self::Lam(_, tag) => {
write!(f,"lam")?;
if *tag != -1 {
write!(f, "_{}", tag)?;
write!(f, "_{tag}")?;
}
Ok(())
},
Self::IVar(i) => write!(f,"#{}",i),
Self::IVar(i) => write!(f,"#{i}"),
}
}
}
Expand All @@ -57,7 +57,7 @@ impl<'a> Display for Expr<'a> {
Node::Lam(b, tag) => {
write!(f,"(lam")?;
if *tag != -1 {
write!(f, "_{}", tag)?;
write!(f, "_{tag}")?;
}
write!(f," ")?;
fmt_local(e.get(*b), false, f)?;
Expand Down Expand Up @@ -92,7 +92,7 @@ impl ExprSet {
let next = s.chars().last().unwrap();
if next == '(' {
s = &s[..s.len()-1];
let num_items = items_of_depth.pop().ok_or_else(||format!("ExprSet parse error: mismatched parens in: {}",s_init))?;
let num_items = items_of_depth.pop().ok_or_else(||format!("ExprSet parse error: mismatched parens in: {s_init}"))?;
if num_items == 0 {
continue
}
Expand All @@ -110,7 +110,7 @@ impl ExprSet {
if let Some(num_items) = items_of_depth.last_mut() {
*num_items += 1;
} else {
return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init));
return Err(format!("ExprSet parse error: mismatched parens in: {s_init}"));
}
continue
}
Expand Down Expand Up @@ -151,37 +151,37 @@ impl ExprSet {
split.next().unwrap(); // strip "lam"
tag = split.next().unwrap().parse::<i32>().map_err(|e|e.to_string())?;
if tag < 0 {
return Err(format!("ExprSet parse error: lambda tag must be non-negative: {}", s_init))
return Err(format!("ExprSet parse error: lambda tag must be non-negative: {s_init}"))
}
}
// println!("remainder: {}",s);
let mut eof = false;
if let Some(c) = s.chars().last() {
if c != '(' {
return Err(format!("ExprSet parse error: `lam` must always have an immediately preceding parenthesis like so `(lam` unless its at the start of the parsed string: {}",s_init))
return Err(format!("ExprSet parse error: `lam` must always have an immediately preceding parenthesis like so `(lam` unless its at the start of the parsed string: {s_init}"))
}
s = &s[..s.len()-1]; // strip "("
} else {
eof = true;
};

let num_items = items_of_depth.pop().ok_or_else(||format!("ExprSet parse error: mismatched parens in: {}",s_init))?;
let num_items = items_of_depth.pop().ok_or_else(||format!("ExprSet parse error: mismatched parens in: {s_init}"))?;
if num_items != 1 {
return Err(format!("ExprSet parse error: `lam` must always be applied to exactly one argument, like `(lam (foo bar))`: {}",s_init))
return Err(format!("ExprSet parse error: `lam` must always be applied to exactly one argument, like `(lam (foo bar))`: {s_init}"))
}
let b: Idx = items.pop().unwrap();
items.push(self.add(Node::Lam(b, tag)));
// println!("added lam");
if eof {
if items.len() != 1 {
return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init));
return Err(format!("ExprSet parse error: mismatched parens in: {s_init}"));
}
return Ok(items.pop().unwrap())
}
if let Some(num_items) = items_of_depth.last_mut() {
*num_items += 1;
} else {
return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init));
return Err(format!("ExprSet parse error: mismatched parens in: {s_init}"));
}
continue
}
Expand All @@ -195,7 +195,7 @@ impl ExprSet {
rest = split.next().unwrap();
tag = split.next().unwrap().parse::<i32>().map_err(|e|e.to_string())?;
if tag < 0 {
return Err(format!("ExprSet parse error: variable tag must be non-negative: {}", s_init))
return Err(format!("ExprSet parse error: variable tag must be non-negative: {s_init}"))
}
}
Node::Var(rest.parse::<i32>().map_err(|e|e.to_string())?, tag)
Expand All @@ -214,7 +214,7 @@ impl ExprSet {
}

if items_of_depth.len() != 1 {
return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init));
return Err(format!("ExprSet parse error: mismatched parens in: {s_init}"));
}

let num_items = items_of_depth.pop().unwrap();
Expand All @@ -226,7 +226,7 @@ impl ExprSet {
items.push(self.add(Node::App(f, x)))
}
if items.len() != 1 {
return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init));
return Err(format!("ExprSet parse error: mismatched parens in: {s_init}"));
}

if self.order == Order::ParentFirst {
Expand Down
6 changes: 3 additions & 3 deletions src/parse_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::*;

/// this gets used by
pub fn parse(s: &str) -> Result<SlowType, String> {
let (ty, s_left) = parse_aux(s).map_err(|e| format!("{}\n when parsing: {}", e, s))?;
let (ty, s_left) = parse_aux(s).map_err(|e| format!("{e}\n when parsing: {s}"))?;
if !s_left.is_empty() {
return Err(format!("Type parse() error: extra closeparen\n when parsing: {}",s))
return Err(format!("Type parse() error: extra closeparen\n when parsing: {s}"))
}
Ok(ty)
}
Expand Down Expand Up @@ -81,7 +81,7 @@ fn parse_aux(mut s: &str) -> Result<(SlowType, &str), String> {
}

// arrows are a low prio operator so group everything before into one term
let ty_left = finish(res).map_err(|s| format!("during arrow rearranging: {}",s))?;
let ty_left = finish(res).map_err(|s| format!("during arrow rearranging: {s}"))?;
// parse everything to the right
let (ty_right, s_new) = parse_aux(&s[1..])?;
s = s_new;
Expand Down
8 changes: 4 additions & 4 deletions src/slow_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ impl std::fmt::Display for SlowType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn helper(ty: &SlowType, f: &mut std::fmt::Formatter<'_>, arrow_parens: bool) -> std::fmt::Result {
match ty {
SlowType::Var(i) => write!(f,"t{}", i),
SlowType::Var(i) => write!(f,"t{i}"),
SlowType::Term(name, args) => {
if args.is_empty() {
write!(f, "{}", name)
write!(f, "{name}")
} else if *name == *ARROW_SYM {
assert_eq!(args.len(), 2);
// write!(f, "({} {} {})", &args[0], name, &args[1])
Expand All @@ -188,7 +188,7 @@ impl std::fmt::Display for SlowType {
}
Ok(())
} else {
write!(f, "({}", name)?;
write!(f, "({name}")?;
for arg in args.iter() {
write!(f, " ")?;
helper(arg, f, true)?;
Expand Down Expand Up @@ -380,7 +380,7 @@ impl std::fmt::Display for Context {
for (i, item) in self.subst_unionfind.iter().enumerate() {
if let Some(ty) = item {
if !first { write!(f, ", ")? } else { first = false }
write!(f, "{}:{}", i, ty)?
write!(f, "{i}:{ty}")?
}
}
write!(f,"}}")
Expand Down