pub fn execute(&mut self, toplevel: &Toplevel) -> Result<Option<String>, String> {
        match toplevel {
            Toplevel::Expr(e) => match has_type(&e, &self.global_tenv) {
                Err(type_error) => Err(format!("Type Error: {}", type_error)),
                Ok(typ) => match eval(&e, &self.global_tenv, &self.global_env) {
                    Err(runtime_error) => Err(format!("Error: {}", runtime_error)),
                    Ok(val) => Ok(Some(format!("(the {} {})", typ, val))),
                },
            },
            Toplevel::Claim(ident, e) => {
                if !is_type(&e) {
                    Err(format!("Type Error: {} is not a type!", e))
                } else if RESERVED_IDENTIFIERS
                    .iter()
                    .any(|reserved| ident.as_str() == *reserved)
                {
                    Err(format!(
                        "Type Error: Try to claim the identifier {}, which is reserved",
                        ident
                    ))
                } else if self.global_tenv.contains_key(ident) {
                    Err(format!(
                        "Type Error: the variable {} is already claimed!",
                        ident
                    ))
                } else {
                    self.global_tenv = Box::new(self.global_tenv.update(
                        ident.clone(),
                        eval(&e, &self.global_tenv, &self.global_env).unwrap(),
                    ));
                    Ok(None)
                }
            }
            Toplevel::Define(ident, e) => match self.global_tenv.get(ident) {
                None => Err(format!(
                    "Type Error: the variable {} is never claimed!",
                    ident
                )),
                Some(typ) => {
                    if !is_a(&e, typ, &self.global_tenv) {
                        Err(format!(
                            "Type Error: the variable {} is claimed to be a {}!",
                            ident, typ
                        ))
                    } else if self.global_env.contains_key(ident) {
                        Err(format!(
                            "Type Error: the variable {} is already defined!",
                            ident
                        ))
                    } else {
                        self.global_env = Box::new(self.global_env.update(
                            ident.clone(),
                            eval(&e, &self.global_tenv, &self.global_env).unwrap(),
                        ));
                        Ok(None)
                    }
                }
            },
        }
    }
// Executes a toplevel
// If successful, optionally returns a message
// If fail, returns an error message
Executes a toplevel
If successful, optionally returns a message
If fail, returns an error message
Executes a toplevel If successful optionally returns a message If fail returns an error message
pub fn execute(&mut self, toplevel: &Toplevel) -> Result<Option<String>, String> {
        match toplevel {
            Toplevel::Expr(e) => match has_type(&e, &self.global_tenv) {
                Err(type_error) => Err(format!("Type Error: {}", type_error)),
                Ok(typ) => match eval(&e, &self.global_tenv, &self.global_env) {
                    Err(runtime_error) => Err(format!("Error: {}", runtime_error)),
                    Ok(val) => Ok(Some(format!("(the {} {})", typ, val))),
                },
            },
            Toplevel::Claim(ident, e) => {
                if !is_type(&e) {
                    Err(format!("Type Error: {} is not a type!", e))
                } else if RESERVED_IDENTIFIERS
                    .iter()
                    .any(|reserved| ident.as_str() == *reserved)
                {
                    Err(format!(
                        "Type Error: Try to claim the identifier {}, which is reserved",
                        ident
                    ))
                } else if self.global_tenv.contains_key(ident) {
                    Err(format!(
                        "Type Error: the variable {} is already claimed!",
                        ident
                    ))
                } else {
                    self.global_tenv = Box::new(self.global_tenv.update(
                        ident.clone(),
                        eval(&e, &self.global_tenv, &self.global_env).unwrap(),
                    ));
                    Ok(None)
                }
            }
            Toplevel::Define(ident, e) => match self.global_tenv.get(ident) {
                None => Err(format!(
                    "Type Error: the variable {} is never claimed!",
                    ident
                )),
                Some(typ) => {
                    if !is_a(&e, typ, &self.global_tenv) {
                        Err(format!(
                            "Type Error: the variable {} is claimed to be a {}!",
                            ident, typ
                        ))
                    } else if self.global_env.contains_key(ident) {
                        Err(format!(
                            "Type Error: the variable {} is already defined!",
                            ident
                        ))
                    } else {
                        self.global_env = Box::new(self.global_env.update(
                            ident.clone(),
                            eval(&e, &self.global_tenv, &self.global_env).unwrap(),
                        ));
                        Ok(None)
                    }
                }
            },
        }
    }
pub fn execute ( & mut self , toplevel : & Toplevel ) -> Result < Option < String > , String > { match toplevel { Toplevel :: Expr ( e ) => match has_type ( & e , & self . global_tenv ) { Err ( type_error ) => Err ( format ! ( " " type_error ) ) , Ok ( typ ) => match eval ( & e , & self . global_tenv , & self . global_env ) { Err ( runtime_error ) => Err ( format ! ( " " runtime_error ) ) , Ok ( val ) => Ok ( Some ( format ! ( " " typ val ) ) ) , } , } , Toplevel :: Claim ( ident , e ) => { if ! is_type ( & e ) { Err ( format ! ( " " e ) ) } else if RESERVED_IDENTIFIERS . iter ( ) . any ( | reserved | ident . as_str ( ) == * reserved ) { Err ( format ! ( " " ident ) ) } else if self . global_tenv . contains_key ( ident ) { Err ( format ! ( " " ident ) ) } else { self . global_tenv = Box :: new ( self . global_tenv . update ( ident . clone ( ) , eval ( & e , & self . global_tenv , & self . global_env ) . unwrap ( ) , ) ) ; Ok ( None ) } } Toplevel :: Define ( ident , e ) => match self . global_tenv . get ( ident ) { None => Err ( format ! ( " " ident ) ) , Some ( typ ) => { if ! is_a ( & e , typ , & self . global_tenv ) { Err ( format ! ( " " ident typ ) ) } else if self . global_env . contains_key ( ident ) { Err ( format ! ( " " ident ) ) } else { self . global_env = Box :: new ( self . global_env . update ( ident . clone ( ) , eval ( & e , & self . global_tenv , & self . global_env ) . unwrap ( ) , ) ) ; Ok ( None ) } } } , } }
Executes a toplevel
If successful, optionally returns a message
If fail, returns an error message
Executes a toplevel If successful optionally returns a message If fail returns an error message
&mut self
toplevel
&Toplevel
&mut self
toplevel
&Toplevel