[][src]Function parsley::proc_utils::make_fold_from0_numeric

pub fn make_fold_from0_numeric<F>(f: F, name: Option<&str>) -> SExp where
    F: Fn(Num, Num) -> Num + 'static, 

Make a variadic procedure that takes a list of numeric arguments, reserves the value of the first element as the initial accumulator, then folds the rest of the list into a number.

Note

The underlying numeric type is f64.

Example

use parsley::prelude::*;
use parsley::proc_utils::*;

let my_subtract = |accumulator, current| accumulator - current;
let my_sub_proc = make_fold_from0_numeric(my_subtract, None);

assert_eq!(
    Context::base().eval(
        sexp![my_sub_proc, 1, 2, -3, 4]
    ).unwrap(),
    SExp::from(-2),
);