/// Get parameters, free variables, function body term from lambda
Get parameters, free variables, function body term from lambda
Get parameters free variables function body term from lambda
fn trans_lambda(&mut self, lambda: Lambda, cap_fv: bool) -> (Vec<VarDecl>, Vec<VarDecl>, TaggedTerm) {
        let params = lambda.param;
        let bd = *lambda.body;
        let (body_term, fvs) = {
            let mut present: Vec<Id> = Vec::new();
            let mut backup: Vec<(Id, Scheme)> = Vec::new();
            // Add parameter into env
            {
                let it = params.iter();
                for para in it {
                    let &VarDecl(ref n, ref t) = para;
                    let pname = n.to_owned();
                    if let Some(origin) = self.close_var(pname, t.to_owned()) {
                        backup.push((pname, origin));
                    }
                    present.push(pname);
                }
            }
            let body_term = self.transform(bd);
            let fvs = if cap_fv {
                let mut _fvs = self.fv(&body_term);
                for &VarDecl(ref n, _) in params.iter() {
                    _fvs.remove(n);
                }
                _fvs.iter().map(|vn| VarDecl(vn.to_owned(), self.env[vn].to_owned())).collect()
            } else { vec![] };
            // Reset env
            for bname in present {
                self.release_var(&bname);
            }
            for (bname, bty) in backup {
                self.close_var(bname, bty);
            }
            (body_term, fvs)
        };
        (params, fvs, body_term)
    }
fn trans_lambda ( & mut self , lambda : Lambda , cap_fv : bool ) -> ( Vec < VarDecl > , Vec < VarDecl > , TaggedTerm ) { let params = lambda . param ; let bd = * lambda . body ; let ( body_term , fvs ) = { let mut present : Vec < Id > = Vec :: new ( ) ; let mut backup : Vec < ( Id , Scheme ) > = Vec :: new ( ) ; // Add parameter into env { let it = params . iter ( ) ; for para in it { let & VarDecl ( ref n , ref t ) = para ; let pname = n . to_owned ( ) ; if let Some ( origin ) = self . close_var ( pname , t . to_owned ( ) ) { backup . push ( ( pname , origin ) ) ; } present . push ( pname ) ; } } let body_term = self . transform ( bd ) ; let fvs = if cap_fv { let mut _fvs = self . fv ( & body_term ) ; for & VarDecl ( ref n , _ ) in params . iter ( ) { _fvs . remove ( n ) ; } _fvs . iter ( ) . map ( | vn | VarDecl ( vn . to_owned ( ) , self . env [ vn ] . to_owned ( ) ) ) . collect ( ) } else { vec ! [ ] } ; // Reset env for bname in present { self . release_var ( & bname ) ; } for ( bname , bty ) in backup { self . close_var ( bname , bty ) ; } ( body_term , fvs ) } ; ( params , fvs , body_term ) }
Get parameters, free variables, function body term from lambda
Get parameters free variables function body term from lambda
&mut self
lambda
Lambda
cap_fv
bool