If expressions
This commit is contained in:
parent
07e19cbfa2
commit
9b4499c5ac
@ -111,7 +111,17 @@ impl EvaluatorState {
|
||||
_ => return Err(format!("Bad assignment")),
|
||||
}
|
||||
"lambda" => unimplemented!(),
|
||||
"cond" => unimplemented!(),
|
||||
"if" => match operands {
|
||||
Cons(box test, box body) => {
|
||||
let truth_value = test.truthy();
|
||||
match (truth_value, body) {
|
||||
(true, Cons(box consequent, _)) => consequent,
|
||||
(false, Cons(_, box Cons(box alternative, _))) => alternative,
|
||||
_ => return Err(format!("Bad if expression"))
|
||||
}
|
||||
},
|
||||
_ => return Err(format!("Bad if expression"))
|
||||
},
|
||||
_ => unimplemented!(),
|
||||
},
|
||||
other => {println!("OTHER? {:?}", other); unimplemented!() }
|
||||
@ -167,6 +177,14 @@ impl Sexp {
|
||||
&Nil => format!("()"),
|
||||
}
|
||||
}
|
||||
|
||||
fn truthy(&self) -> bool {
|
||||
use self::Sexp::*;
|
||||
match self {
|
||||
&False => false,
|
||||
_ => true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tokenize(input: &mut Peekable<Chars>) -> Vec<Token> {
|
||||
|
Loading…
Reference in New Issue
Block a user