Implement REPL resolves #5

This commit is contained in:
2021-05-30 10:19:35 -04:00
parent 390c5d1b48
commit aaa93d8593
4 changed files with 60 additions and 24 deletions

View File

@@ -1,9 +1,9 @@
use crate::parser::Datum;
use crate::parser::Datum::*;
use crate::parser::make_symbol;
use crate::environment;
use crate::environment::Env;
use crate::parser::make_symbol;
use crate::parser::Datum;
use crate::parser::Datum::*;
fn is_true(exp: &Datum) -> bool {
match exp {
Boolean(b) => *b,
@@ -16,7 +16,7 @@ fn is_true(exp: &Datum) -> bool {
fn has_tag(vec: &Vec<Datum>, tag: &str) -> bool {
if vec.len() == 0 {
return false;
}
}
if let Symbol(s) = &vec[0] {
if s == tag {
return true;
@@ -49,7 +49,7 @@ fn interpret_define(args: &Vec<Datum>, env: &mut Env) -> Datum {
let var = &args[1];
let val = interpret(&args[2], env);
environment::define_variable(var, val, env)
},
}
List(v) => {
// procedure definition
let definition_var = &v[0];
@@ -65,8 +65,8 @@ fn interpret_define(args: &Vec<Datum>, env: &mut Env) -> Datum {
let lambda_body = Datum::List(args[2..].to_vec());
let lambda = Datum::List(vec![make_symbol("lambda"), lambda_parameters, lambda_body]);
environment::define_variable(definition_var, lambda, env)
},
_ => panic!("INTERPRET-DEFINE -- cannot define {:?}", args)
}
_ => panic!("INTERPRET-DEFINE -- cannot define {:?}", args),
}
}
@@ -106,8 +106,8 @@ fn interpret_application(vec: &Vec<Datum>, env: &mut Env) -> Datum {
}
environment::shrink_environment(env);
r
},
_ => panic!("INTERPRET-APPLICATION -- not-aplicable {:?}", args[0])
}
_ => panic!("INTERPRET-APPLICATION -- not-aplicable {:?}", args[0]),
}
}