mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-12 09:15:32 +01:00
Not really like this fix either
Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
13
src/eval.rs
13
src/eval.rs
@ -13,12 +13,11 @@ fn call_func(func: &MalType, args: &[MalType]) -> MalRet {
|
||||
ast,
|
||||
env,
|
||||
} => {
|
||||
let mut inner_env = env_binds(env, &**params, args)?;
|
||||
let mut ret = Ok(Nil);
|
||||
for el in ast.iter() {
|
||||
ret = eval(el, &mut inner_env);
|
||||
let mut inner_env = env_binds(env, params, args)?;
|
||||
match eval(ast, &mut inner_env)? {
|
||||
List(list) => Ok(list.last().unwrap_or(&Nil).clone()),
|
||||
_ => Err("This should not happen".to_string()),
|
||||
}
|
||||
ret
|
||||
}
|
||||
_ => Err(format!("{:?} is not a function", func)),
|
||||
}
|
||||
@ -113,9 +112,9 @@ fn fn_star_form(list: &[MalType], env: &Env) -> MalRet {
|
||||
}
|
||||
let (binds, exprs) = car_cdr(list);
|
||||
Ok(MalFun {
|
||||
eval: eval,
|
||||
eval: eval_ast,
|
||||
params: Box::new(binds.clone()),
|
||||
ast: Box::new(exprs.to_vec()),
|
||||
ast: Box::new(List(exprs.to_vec())),
|
||||
env: env.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ pub enum MalType {
|
||||
MalFun {
|
||||
eval: fn(ast: &MalType, env: &mut Env) -> MalRet,
|
||||
params: Box<MalType>,
|
||||
ast: Box<MalArgs>,
|
||||
ast: Box<MalType>,
|
||||
env: Env,
|
||||
}, // Used for functions defined within mal
|
||||
Sym(String),
|
||||
|
||||
Reference in New Issue
Block a user