Implement function chain division

pull/1/head
Alex Bethel 2021-12-14 16:16:28 -06:00
parent fe1f20a925
commit f549c08a8f
1 changed files with 37 additions and 28 deletions

View File

@ -617,39 +617,48 @@ impl ops::Div for Value {
})),
Value::Bool(b) => Value::Bool(!b || rhs.into_bool()),
Value::Abool(_) => !self + rhs,
Value::Functio(f) => {
let fraction = 1.0 / rhs.into_i32() as f64;
Value::Functio(match f {
Value::Functio(f) => Value::Functio(match f {
Functio::Bf {
instructions,
tape_len,
} => {
let fraction = 1.0 / rhs.into_i32() as f64;
let len = instructions.len();
Functio::Bf {
instructions,
instructions: instructions
.into_iter()
.take((len as f64 * fraction) as usize)
.collect(),
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: body
.into_iter()
.take((len as f64 * fraction) as usize)
.collect(),
}
}
Functio::Able { params, body } => {
let fraction = 1.0 / rhs.into_i32() as f64;
let len = body.len();
Functio::Able {
params,
body: body
.into_iter()
.take((len as f64 * fraction) as usize)
.collect(),
}
Functio::Chain { .. } => todo!(":P"),
Functio::Eval(s) => {
let len = s.len();
Functio::Eval(s.chars().take((len as f64 * fraction) as usize).collect())
}
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) => {
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) => {
let cart_len = c.len();
let chunk_len = rhs.into_i32() as usize;