Implement function chain division

This commit is contained in:
Alex Bethel 2021-12-14 16:16:28 -06:00
parent c1471bcdb7
commit 20b1408179

View file

@ -617,39 +617,48 @@ 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; Functio::Bf {
Value::Functio(match f { instructions,
tape_len,
} => {
let fraction = 1.0 / rhs.into_i32() as f64;
let len = instructions.len();
Functio::Bf { Functio::Bf {
instructions, instructions: instructions
.into_iter()
.take((len as f64 * fraction) as usize)
.collect(),
tape_len, tape_len,
} => {
let len = instructions.len();
Functio::Bf {
instructions: instructions
.into_iter()
.take((len as f64 * fraction) as usize)
.collect(),
tape_len,
}
} }
Functio::Able { params, body } => { }
let len = body.len(); Functio::Able { params, body } => {
Functio::Able { let fraction = 1.0 / rhs.into_i32() as f64;
params, let len = body.len();
body: body Functio::Able {
.into_iter() params,
.take((len as f64 * fraction) as usize) body: body
.collect(), .into_iter()
} .take((len as f64 * fraction) as usize)
.collect(),
} }
Functio::Chain { .. } => todo!(":P"), }
Functio::Eval(s) => { Functio::Chain { functios, kind } => {
let len = s.len(); let functios = *functios;
Functio::Eval(s.chars().take((len as f64 * fraction) as usize).collect()) Functio::Chain {
functios: Box::new((
(Value::Functio(functios.0) / rhs.clone()).into_functio(),
(Value::Functio(functios.1) / rhs).into_functio(),
)),
kind,
} }
}) }
} Functio::Eval(s) => {
let fraction = 1.0 / rhs.into_i32() as f64;
let len = s.len();
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;