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::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
@ -634,6 +633,7 @@ impl ops::Div for Value {
}
}
Functio::Able { params, body } => {
let fraction = 1.0 / rhs.into_i32() as f64;
let len = body.len();
Functio::Able {
params,
@ -643,13 +643,22 @@ impl ops::Div for Value {
.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) => {
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;