implemented subtraction for built-in functios

This commit is contained in:
Erin 2022-02-13 00:25:56 +01:00 committed by ondra05
parent 5d5c66fb3c
commit 0ac507e3b3

View file

@ -635,7 +635,27 @@ impl ops::Sub for Value {
) )
.into_functio(), .into_functio(),
}, },
Functio::Builtin(_) => todo!(), Functio::Builtin(b) => {
let arity = b.arity;
let resulting_arity = arity.saturating_sub(rhs.into_i32() as usize);
Functio::Builtin(BuiltinFunctio::new(
move |args| {
b.call(
&args
.iter()
.cloned()
.take(resulting_arity)
.chain(std::iter::repeat_with(|| {
Rc::new(RefCell::new(Value::Nul))
}))
.take(arity)
.collect::<Vec<_>>(),
)
},
resulting_arity,
))
}
Functio::Chain { functios, .. } => { Functio::Chain { functios, .. } => {
let rhs = rhs.into_functio(); let rhs = rhs.into_functio();
let (a, b) = *functios; let (a, b) = *functios;