Rework environment mode fixes #8

This commit is contained in:
2021-05-30 11:57:59 -04:00
parent 3ae5ccb64c
commit e070441c31
3 changed files with 53 additions and 51 deletions

View File

@@ -96,16 +96,15 @@ fn interpret_application(vec: &Vec<Datum>, env: &mut Env) -> Datum {
let lambda_body = &v[2];
let lambda_args = args[1..].to_vec();
// FIXME: this does not optimize tail-calls
environment::extend_environment(lambda_parameters, List(lambda_args), env);
let mut r = Datum::Unspecified;
let mut new_env = environment::extend(lambda_parameters, List(lambda_args), env);
if let List(seq) = lambda_body {
for i in 0..seq.len() {
r = interpret(&seq[i], env);
for i in 0..(seq.len() - 1) {
interpret(&seq[i], &mut new_env);
}
interpret(&seq[seq.len() - 1], &mut new_env)
} else {
panic!("INTERPRET-APPLICATION -- no-list {:?}", lambda_body)
}
environment::shrink_environment(env);
r
}
_ => panic!("INTERPRET-APPLICATION -- not-aplicable {:?}", args[0]),
}