diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index a4cea06..7f671a0 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -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) -> Vec {