Implement support for cond resolves #4
This commit is contained in:
@@ -5,6 +5,7 @@ use std::mem;
|
||||
|
||||
type Mapping = (Datum, Datum);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Frame<'a> {
|
||||
mappings: Vec<Mapping>,
|
||||
outer: Option<&'a Frame<'a>>,
|
||||
|
||||
@@ -83,8 +83,17 @@ fn interpret_define(args: &Vec<Datum>, env: &mut Env) -> Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn interpret_cond(_vec: &Vec<Datum>, _env: &mut Env) -> Datum {
|
||||
Datum::Unspecified
|
||||
fn interpret_cond(vec: &Vec<Datum>, env: &mut Env) -> Datum {
|
||||
for i in 1..vec.len() {
|
||||
if let List(v) = &vec[i] {
|
||||
if has_tag(v, "else") || is_true(&interpret(&v[0], env)) {
|
||||
return interpret_begin(v, env);
|
||||
}
|
||||
} else {
|
||||
panic!("INTERPRET-COND -- not a list {:?}", vec[i])
|
||||
}
|
||||
}
|
||||
panic!("INTERPRET-COND -- missing else statement? {:?}", vec)
|
||||
}
|
||||
|
||||
fn interpret_begin(vec: &Vec<Datum>, env: &mut Env) -> Datum {
|
||||
|
||||
@@ -94,7 +94,7 @@ pub fn display(args: Vec<Datum>) -> Datum {
|
||||
Number(n) => print!("{}", n),
|
||||
String(s) => print!("{}", s),
|
||||
List(v) => print!("{:?}", v),
|
||||
_ => panic!("DISPLAY -- cannot-print {:?}", args[1]),
|
||||
_ => panic!("DISPLAY -- cannot-print {:?}", args[i]),
|
||||
};
|
||||
}
|
||||
io::stdout().flush().ok().expect("Could not flush stdout");
|
||||
|
||||
Reference in New Issue
Block a user