Not really like this fix either

Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
teo3300
2023-07-27 16:57:29 +02:00
parent 24a42d5628
commit 81cfe11092
2 changed files with 7 additions and 8 deletions

View File

@ -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(),
})
}

View File

@ -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),