fn fold_term(&mut self, t: Term) -> Term {
        match t.value() {
            _ if self.stack.is_empty() => {
                // If there is no containing conjunction, make one.
                self.stack.push(vec![]);
                let mut new = self.fold_term(t);
                let mut rewrites = self.stack.pop().unwrap();
                for rewrite in rewrites.drain(..).rev() {
                    and_wrap(&mut new, rewrite);
                }
                new
            }
            Value::Expression(o) if self.needs_rewrite(o) => {
                // Rewrite sub-expressions, then push a temp onto the args.
                let mut new = fold_operation(o.clone(), self);
                let temp = Value::Variable(self.kb.gensym(temp_name(&o.operator)));
                new.args.push(Term::new_temporary(temp.clone()));

                // Push the rewritten expression into the top stack frame.
                self.stack
                    .last_mut()
                    .unwrap()
                    .push(t.clone_with_value(Value::Expression(new)));

                // Return the temp.
                t.clone_with_value(temp)
            }
            _ => fold_term(t, self),
        }
    }
/// Rewrite an expression as a temp, and push a rewritten
/// expression that binds the temp.
Rewrite an expression as a temp, and push a rewritten
expression that binds the temp.
Rewrite an expression as a temp and push a rewritten expression that binds the temp .
fn fold_term(&mut self, t: Term) -> Term {
        match t.value() {
            _ if self.stack.is_empty() => {
                // If there is no containing conjunction, make one.
                self.stack.push(vec![]);
                let mut new = self.fold_term(t);
                let mut rewrites = self.stack.pop().unwrap();
                for rewrite in rewrites.drain(..).rev() {
                    and_wrap(&mut new, rewrite);
                }
                new
            }
            Value::Expression(o) if self.needs_rewrite(o) => {
                // Rewrite sub-expressions, then push a temp onto the args.
                let mut new = fold_operation(o.clone(), self);
                let temp = Value::Variable(self.kb.gensym(temp_name(&o.operator)));
                new.args.push(Term::new_temporary(temp.clone()));
                // Push the rewritten expression into the top stack frame.
                self.stack
                    .last_mut()
                    .unwrap()
                    .push(t.clone_with_value(Value::Expression(new)));
                // Return the temp.
                t.clone_with_value(temp)
            }
            _ => fold_term(t, self),
        }
    }
fn fold_term ( & mut self , t : Term ) -> Term { match t . value ( ) { _ if self . stack . is_empty ( ) => { // If there is no containing conjunction, make one. self . stack . push ( vec ! [ ] ) ; let mut new = self . fold_term ( t ) ; let mut rewrites = self . stack . pop ( ) . unwrap ( ) ; for rewrite in rewrites . drain ( .. ) . rev ( ) { and_wrap ( & mut new , rewrite ) ; } new } Value :: Expression ( o ) if self . needs_rewrite ( o ) => { // Rewrite sub-expressions, then push a temp onto the args. let mut new = fold_operation ( o . clone ( ) , self ) ; let temp = Value :: Variable ( self . kb . gensym ( temp_name ( & o . operator ) ) ) ; new . args . push ( Term :: new_temporary ( temp . clone ( ) ) ) ; // Push the rewritten expression into the top stack frame. self . stack . last_mut ( ) . unwrap ( ) . push ( t . clone_with_value ( Value :: Expression ( new ) ) ) ; // Return the temp. t . clone_with_value ( temp ) } _ => fold_term ( t , self ) , } }
Rewrite an expression as a temp, and push a rewritten
expression that binds the temp.
Rewrite an expression as a temp and push a rewritten expression that binds the temp .
&mut self
t
Term