Struct arithmetic_eval::fns::Push
source · pub struct Push;
Expand description
Function that appends a value onto a tuple.
Type
(using arithmetic-typing
notation)
(['T; N], 'T) -> ['T; N + 1]
Examples
let program = "
repeat = |x, times| {
(_, acc) = while(
(0, ()),
|(i, _)| i < times,
|(i, acc)| (i + 1, push(acc, x)),
);
acc
};
repeat(-2, 3) == (-2, -2, -2) &&
repeat((7,), 4) == ((7,), (7,), (7,), (7,))
";
let program = Untyped::<F32Grammar>::parse_statements(program)?;
let module = ExecutableModule::new("test_push", &program)?;
let mut env = Environment::new();
env.insert_native_fn("while", fns::While)
.insert_native_fn("push", fns::Push);
assert_eq!(module.with_env(&env)?.run()?, Value::Bool(true));
Trait Implementations§
source§impl<T> NativeFn<T> for Push
impl<T> NativeFn<T> for Push
source§fn evaluate(
&self,
args: Vec<SpannedValue<T>>,
ctx: &mut CallContext<'_, T>
) -> EvalResult<T>
fn evaluate( &self, args: Vec<SpannedValue<T>>, ctx: &mut CallContext<'_, T> ) -> EvalResult<T>
Executes the function on the specified arguments.
impl Copy for Push
Auto Trait Implementations§
impl RefUnwindSafe for Push
impl Send for Push
impl Sync for Push
impl Unpin for Push
impl UnwindSafe for Push
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more