Change code syntax to make it a bit better

Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
teo3300
2023-07-08 12:48:53 +02:00
parent 308d239ebc
commit 148196dae5
2 changed files with 6 additions and 12 deletions

View File

@ -66,9 +66,9 @@ pub fn env_init() -> Env {
env_init!(None,
"test" => Fun(|_| Ok(Str("This is a test function".to_string()))),
"quit" => Fun(|_| {println!("Bye!"); exit(0)}),
"+" => Fun(|a| int_op(0, |a, b| a + b, a)),
"-" => Fun(|a| int_op(0, |a, b| a - b, a)),
"*" => Fun(|a| int_op(1, |a, b| a * b, a)),
"/" => Fun(|a| int_op(1, |a, b| a / b, a))
"+" => Fun(|a| int_op(0, |a, b| a + b, a)),
"-" => Fun(|a| int_op(0, |a, b| a - b, a)),
"*" => Fun(|a| int_op(1, |a, b| a * b, a)),
"/" => Fun(|a| int_op(1, |a, b| a / b, a))
)
}

View File

@ -13,19 +13,13 @@ use crate::types::{MalRet, MalType};
#[allow(non_snake_case)]
/// Read input and generate an ast
fn READ(input: &str) -> MalRet {
match read_str(input) {
Ok(ast) => Ok(ast),
Err(err) => Err(format!("@ READ: {}", err)),
}
read_str(input).map_err(|err| format!("@ READ: {}", err))
}
#[allow(non_snake_case)]
/// Evaluate the generated ast
fn EVAL(ast: MalType, env: &mut Env) -> MalRet {
match eval(&ast, env) {
Ok(ast) => Ok(ast),
Err(err) => Err(format!("@ EVAL: {}", err)),
}
eval(&ast, env).map_err(|err| format!("@ EVAL: {}", err))
}
#[allow(non_snake_case)]