Function division

pull/1/head
Alex Bethel 2021-12-08 16:33:06 -07:00
parent d8ecfed5d5
commit 4851e0375a
1 changed files with 33 additions and 4 deletions

View File

@ -107,9 +107,7 @@ impl Value {
instructions,
tape_len,
} => (instructions.len() + tape_len) as _,
Functio::Able { params, body } => {
(params.len() + format!("{:?}", body).len()) as _
}
Functio::Able { params, body } => (params.len() + format!("{:?}", body).len()) as _,
Functio::Eval(s) => s.len() as _,
},
Value::Int(i) => i,
@ -456,7 +454,38 @@ impl ops::Div for Value {
})),
Value::Bool(b) => Value::Bool(!b || rhs.into_bool()),
Value::Abool(_) => !self + rhs,
Value::Functio(_) => todo!(),
Value::Functio(f) => {
let fraction = 1.0 / rhs.into_i32() as f64;
Value::Functio(match f {
Functio::Bf {
instructions,
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::Eval(s) => {
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;