Functions now have names
This commit is contained in:
parent
dd1d7b8494
commit
0c097a72fb
5 changed files with 66 additions and 43 deletions
|
|
@ -3,7 +3,6 @@ use std::fmt;
|
|||
use crate::node::node_modifier::NodeModifier;
|
||||
use handler::*;
|
||||
|
||||
mod functions;
|
||||
mod handler;
|
||||
pub mod node_modifier;
|
||||
|
||||
|
|
@ -40,10 +39,18 @@ impl Node {
|
|||
max_children_count: Some(0),
|
||||
}
|
||||
}
|
||||
pub fn function(func: fn(Vec<f64>) -> f64, max_children_count: Option<usize>) -> Self {
|
||||
pub fn function(
|
||||
func_name: String,
|
||||
func: fn(Vec<f64>) -> f64,
|
||||
max_children_count: Option<usize>,
|
||||
) -> Self {
|
||||
Self {
|
||||
children: vec![],
|
||||
handler: NodeHandler::Function { function: func },
|
||||
handler: NodeHandler::Function {
|
||||
name: func_name,
|
||||
function: func,
|
||||
max_args: max_children_count,
|
||||
},
|
||||
max_children_count,
|
||||
}
|
||||
}
|
||||
|
|
@ -78,9 +85,13 @@ impl fmt::Display for Node {
|
|||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self.handler {
|
||||
match &self.handler {
|
||||
NodeHandler::Number { number } => number.to_string(),
|
||||
NodeHandler::Function { function } => "Function".to_string(),
|
||||
NodeHandler::Function {
|
||||
function,
|
||||
name,
|
||||
max_args,
|
||||
} => name.clone(),
|
||||
NodeHandler::Variable => "X".to_string(),
|
||||
NodeHandler::Empty => "Empty".to_string(),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue