Function eval_with_mutable_context

Source
pub fn eval_with_mutable_context(
    input: &str,
    context: &mut Context,
) -> EvalResult<Option<Value>>
Expand description

Evaluate an expression or add a declaration to the provided context.

See also eval and eval_with_static_context.

Returns Ok(Some(Value)) if the request was an evaluation, or Ok(None) if it was a declaration.

ยงExamples

use num_parser::*;

let mut context = Context::default();

// Add a declaration
let var_res = eval_with_mutable_context("a = 4", &mut context).unwrap();
let func_res = eval_with_mutable_context("g(x,y) = xsin(y)", &mut context).unwrap();
// Both results are None
assert_eq!(var_res, None);
assert_eq!(func_res, None);

let res = eval_with_mutable_context("g(1,pi/2) + a", &mut context).unwrap();

assert_eq!(res, Some(Value::from(5)));