pub fn to_sexp(&self, child: Id) -> Sexp {
        let node = &self.nodes[usize::from(child)];
        match node {
            Lambda::Var(_) | Lambda::IVar(_) | Lambda::Prim(_) => sexp::parse(&node.to_string()).unwrap(),
            Lambda::App([f,x]) => {
                let f = self.to_sexp(*f);
                let x = self.to_sexp(*x);
                let app = Sexp::Atom(sexp::Atom::S("app".to_string()));
                Sexp::List(vec![app,f,x])
            },
            Lambda::Lam([b]) => {
                let b = self.to_sexp(*b);
                let lam = Sexp::Atom(sexp::Atom::S("lam".to_string()));
                Sexp::List(vec![lam,b])
            },
            Lambda::Programs(root_ids) => {
                let mut res = vec![Sexp::Atom(sexp::Atom::S("programs".to_string()))];
                root_ids.iter().for_each(|id| res.push(self.to_sexp(*id)));
                Sexp::List(res)
            }
        }
    }
/// convert to an s expression. Useful for printing / parsing purposes
convert to an s expression. Useful for printing / parsing purposes
convert to an s expression . Useful for printing / parsing purposes
pub fn to_sexp(&self, child: Id) -> Sexp {
        let node = &self.nodes[usize::from(child)];
        match node {
            Lambda::Var(_) | Lambda::IVar(_) | Lambda::Prim(_) => sexp::parse(&node.to_string()).unwrap(),
            Lambda::App([f,x]) => {
                let f = self.to_sexp(*f);
                let x = self.to_sexp(*x);
                let app = Sexp::Atom(sexp::Atom::S("app".to_string()));
                Sexp::List(vec![app,f,x])
            },
            Lambda::Lam([b]) => {
                let b = self.to_sexp(*b);
                let lam = Sexp::Atom(sexp::Atom::S("lam".to_string()));
                Sexp::List(vec![lam,b])
            },
            Lambda::Programs(root_ids) => {
                let mut res = vec![Sexp::Atom(sexp::Atom::S("programs".to_string()))];
                root_ids.iter().for_each(|id| res.push(self.to_sexp(*id)));
                Sexp::List(res)
            }
        }
    }
pub fn to_sexp ( & self , child : Id ) -> Sexp { let node = & self . nodes [ usize :: from ( child ) ] ; match node { Lambda :: Var ( _ ) | Lambda :: IVar ( _ ) | Lambda :: Prim ( _ ) => sexp :: parse ( & node . to_string ( ) ) . unwrap ( ) , Lambda :: App ( [ f , x ] ) => { let f = self . to_sexp ( * f ) ; let x = self . to_sexp ( * x ) ; let app = Sexp :: Atom ( sexp :: Atom :: S ( " " . to_string ( ) ) ) ; Sexp :: List ( vec ! [ app f x ] ) } , Lambda :: Lam ( [ b ] ) => { let b = self . to_sexp ( * b ) ; let lam = Sexp :: Atom ( sexp :: Atom :: S ( " " . to_string ( ) ) ) ; Sexp :: List ( vec ! [ lam b ] ) } , Lambda :: Programs ( root_ids ) => { let mut res = vec ! [ Sexp Atom ( sexp Atom S ( " " to_string ( ) ) ) ] ; root_ids . iter ( ) . for_each ( | id | res . push ( self . to_sexp ( * id ) ) ) ; Sexp :: List ( res ) } } }
convert to an s expression.
convert to an s expression .
&self
child
Id
&self
child
Id