1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
use super::math_node::{MathNodeType, NodeIndex}; use std::fmt; #[derive(Default, Debug, Clone)] pub struct Lambda { pub children: Vec<NodeIndex>, pub bindings: Vec<NodeIndex>, pub expr: Option<NodeIndex>, pub parent: Option<NodeIndex>, } impl Lambda { pub fn index(&mut self, tag_type: MathNodeType, location: NodeIndex) { match tag_type { MathNodeType::Op | MathNodeType::Apply | MathNodeType::Lambda | MathNodeType::Piecewise | MathNodeType::Ci | MathNodeType::Cn | MathNodeType::Constant => { if self.expr == None { self.expr = Some(location); } else { panic!("Can't have two expressions in a lambda function!"); } } MathNodeType::BVar => { self.bindings.push(location); } MathNodeType::Root | MathNodeType::Piece | MathNodeType::Otherwise => { panic!("Can't have {} in a lambda function!", tag_type); } } } } impl fmt::Display for Lambda { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "Bindings: {:?}, Expr: {:?}, Children: {:?}, Parent: {:?}", self.bindings, self.expr, self.children, self.parent ) } }