aboutsummaryrefslogtreecommitdiff
path: root/src/function.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/function.rs')
-rw-r--r--src/function.rs68
1 files changed, 0 insertions, 68 deletions
diff --git a/src/function.rs b/src/function.rs
deleted file mode 100644
index 4daebf4..0000000
--- a/src/function.rs
+++ /dev/null
@@ -1,68 +0,0 @@
-use crate::{complex::Complex, context::Context};
-
-pub struct FunctionArgument {
- args : Vec<Complex>,
-}
-
-impl FunctionArgument {
- pub fn new(args: Vec<Complex>) -> Self {
- Self { args }
- }
-
- pub fn get(&self, i : usize) -> Complex {
- self.args[i]
- }
-
- pub fn len(&self) -> usize {
- self.args.len()
- }
-
- pub fn is_empty(&self) -> bool {
- self.args.len() == 0
- }
-
- pub fn data(&self) -> &[Complex] {
- &self.args
- }
-}
-
-pub trait Function {
- fn eval(&self, args: FunctionArgument, ctx: &Context) -> Result<Complex, String>;
-}
-
-#[macro_export]
-macro_rules! functions {
- {$($x:expr => $y:expr), *} => {
- {
- let mut h : HashMap<String, Arc<dyn Function>> = HashMap::new();
- $(
- h.insert($x.to_string(), Arc::new($y));
- )*
- h
- }
- };
-}
-
-
-// Some default implementations
-impl<T> Function for T
-where
- T: Fn(Complex) -> Complex,
-{
- fn eval(&self, args: FunctionArgument, _ctx: &Context) -> Result<Complex, String> {
- if args.len() == 1 {
- Ok(self(args.get(0)))
- } else {
- Err("too many arguments".to_string())
- }
- }
-}
-
-
-pub struct EmptyFunction {}
-
-impl Function for EmptyFunction {
- fn eval(&self, _args: FunctionArgument, _ctx: &Context) -> Result<Complex, String> {
- Err("function not implemented in this scope".to_string())
- }
-}