mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-12 01:05:32 +01:00
Change code syntax to make it a bit better
Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
@ -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))
|
||||
)
|
||||
}
|
||||
|
||||
@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user