Implement function chain division

This commit is contained in:
Alex Bethel 2021-12-14 16:16:28 -06:00
parent 183f26f415
commit ec4a7e2447

View file

@ -617,13 +617,12 @@ impl ops::Div for Value {
})), })),
Value::Bool(b) => Value::Bool(!b || rhs.into_bool()), Value::Bool(b) => Value::Bool(!b || rhs.into_bool()),
Value::Abool(_) => !self + rhs, Value::Abool(_) => !self + rhs,
Value::Functio(f) => { Value::Functio(f) => Value::Functio(match f {
let fraction = 1.0 / rhs.into_i32() as f64;
Value::Functio(match f {
Functio::Bf { Functio::Bf {
instructions, instructions,
tape_len, tape_len,
} => { } => {
let fraction = 1.0 / rhs.into_i32() as f64;
let len = instructions.len(); let len = instructions.len();
Functio::Bf { Functio::Bf {
instructions: instructions instructions: instructions
@ -634,6 +633,7 @@ impl ops::Div for Value {
} }
} }
Functio::Able { params, body } => { Functio::Able { params, body } => {
let fraction = 1.0 / rhs.into_i32() as f64;
let len = body.len(); let len = body.len();
Functio::Able { Functio::Able {
params, params,
@ -643,13 +643,22 @@ impl ops::Div for Value {
.collect(), .collect(),
} }
} }
Functio::Chain { .. } => todo!(":P"), Functio::Chain { functios, kind } => {
let functios = *functios;
Functio::Chain {
functios: Box::new((
(Value::Functio(functios.0) / rhs.clone()).into_functio(),
(Value::Functio(functios.1) / rhs).into_functio(),
)),
kind,
}
}
Functio::Eval(s) => { Functio::Eval(s) => {
let fraction = 1.0 / rhs.into_i32() as f64;
let len = s.len(); let len = s.len();
Functio::Eval(s.chars().take((len as f64 * fraction) as usize).collect()) Functio::Eval(s.chars().take((len as f64 * fraction) as usize).collect())
} }
}) }),
}
Value::Cart(c) => { Value::Cart(c) => {
let cart_len = c.len(); let cart_len = c.len();
let chunk_len = rhs.into_i32() as usize; let chunk_len = rhs.into_i32() as usize;