diff options
Diffstat (limited to 'src/math/expression_function.rs')
| -rw-r--r-- | src/math/expression_function.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/math/expression_function.rs b/src/math/expression_function.rs index 20f4816..44f83d1 100644 --- a/src/math/expression_function.rs +++ b/src/math/expression_function.rs @@ -5,6 +5,7 @@ use crate::math::{ complex::Complex, context::Context, expression::Expression, + operation::Operation, function::{Function, FunctionArgument, EmptyFunction} }; @@ -16,7 +17,7 @@ pub struct ExpressionFunction { } impl ExpressionFunction { - pub fn from_string(str: String) -> Self { + pub fn from_string(str: String, operations: &Vec<Operation>) -> Self { let str = str.replace(' ', ""); let (lhs, expr) = str.split_once('=').unwrap(); let (name, a) = lhs.split_once('(').unwrap(); @@ -25,7 +26,7 @@ impl ExpressionFunction { .map(|s| s.to_string()) .collect(); Self { - expr: Expression::from_string(expr), + expr: Expression::from_string(expr, operations), name: name.to_string(), args, } @@ -41,10 +42,11 @@ impl ExpressionFunction { } impl Function for ExpressionFunction { - fn eval(&self, args: FunctionArgument, ctx: &Context) -> Result<Complex, String> { + fn eval(&self, args: &FunctionArgument, ctx: &Context) -> Result<Complex, String> { if args.len() == self.args.len() { let mut nctx = ctx.clone(); - for (n, v) in zip(self.args.iter(), args.data().iter()) { + let vargs = args.eval_args(ctx)?; + for (n, v) in zip(self.args.iter(), vargs.iter()) { nctx.set_variable(n, *v) } nctx.set_function(self.name(), Arc::new(EmptyFunction {})); |