From fcd980f14888974875a858f1608bc533df173966 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 7 Dec 2017 19:48:48 -0800 Subject: [PATCH] Some primitive implementations --- src/rukka_lang/mod.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index 1814a86..1b25158 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -49,28 +49,35 @@ impl EvaluatorState { fn new() -> EvaluatorState { EvaluatorState { } } fn eval(&mut self, expr: Sexp) -> Result { use self::Sexp::*; - println!("Eval'd sexp: {:?}", expr); Ok(match expr { SymbolAtom(sym) => unimplemented!(), expr @ StringAtom(_) => expr, expr @ NumberAtom(_) => expr, - Cons(box car, box cdr) => { - match car { + Cons(box operator, box operands) => { + match operator { SymbolAtom(ref sym) => match &sym[..] { - "quote" => cdr, + "quote" => operands, "eq?" => unimplemented!(), - "cons" => match cdr { + "cons" => match operands { Cons(box cadr, box Cons(box caddr, box Nil)) => { - println!("NEWL {:?}|| NEWR {:?}", cadr, caddr); let newl = self.eval(cadr)?; let newr = self.eval(caddr)?; Cons(Box::new(newl), Box::new(newr)) }, _ => return Err(format!("Bad arguments for cons")), }, - "car" => unimplemented!(), - "cdr" => unimplemented!(), - "atom?" => unimplemented!(), + "car" => match operands { + Cons(box car, _) => car, + _ => return Err(format!("called car with a non-pair argument")), + }, + "cdr" => match operands { + Cons(_, box cdr) => cdr, + _ => return Err(format!("called cdr with a non-pair argument")), + }, + "atom?" => match operands { + Cons(_, _) => SymbolAtom(format!("#f")), + _ => SymbolAtom(format!("#t")), + }, "define" => unimplemented!(), "lambda" => unimplemented!(), "cond" => unimplemented!(),