From 7aeb9d525d79924bb52e6b1f86139412e153ce1e Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 9 Dec 2021 17:18:37 +0100 Subject: [PATCH] Implemented coercions when subtracting able functios --- ablescript/src/variables.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 96c963dc..f16f94c4 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -472,7 +472,35 @@ impl ops::Sub for Value { tape_len: lhs_tl, }, }, - Functio::Able { params, body } => todo!(), + Functio::Able { + params: lhs_params, + body: lhs_body, + } => match rhs.into_functio() { + Functio::Able { + params: rhs_params, + body: rhs_body, + } => Functio::Able { + params: lhs_params + .into_iter() + .zip(rhs_params.into_iter()) + .filter_map(|(l, r)| if l != r { Some(l) } else { None }) + .collect(), + body: lhs_body + .into_iter() + .zip(rhs_body.into_iter()) + .filter_map(|(l, r)| if l != r { Some(l) } else { None }) + .collect(), + }, + rhs => Value::Int( + Value::Functio(Functio::Able { + params: lhs_params, + body: lhs_body, + }) + .into_i32() + - Value::Functio(rhs).into_i32(), + ) + .into_functio(), + }, Functio::Chain { functios, kind } => todo!(), Functio::Eval(lhs_code) => Functio::Eval(lhs_code.replace( &match rhs.into_functio() {