From 73612d14658fc4dd0d9377634b62ef1ba1a46353 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 7 Dec 2017 20:28:09 -0800 Subject: [PATCH] Define half-working --- src/rukka_lang/mod.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index 246ae67..464a2dc 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -3,8 +3,11 @@ use schala_lib::{ProgrammingLanguageInterface, EvalOptions, ReplOutput}; use std::iter::Peekable; use std::vec::IntoIter; use std::str::Chars; +use std::collections::HashMap; -pub struct EvaluatorState { } +pub struct EvaluatorState { + vars: HashMap +} pub struct Rukka { state: EvaluatorState @@ -45,7 +48,11 @@ impl ProgrammingLanguageInterface for Rukka { } impl EvaluatorState { - fn new() -> EvaluatorState { EvaluatorState { } } + fn new() -> EvaluatorState { + EvaluatorState { + vars: HashMap::new(), + } + } fn eval(&mut self, expr: Sexp) -> Result { use self::Sexp::*; Ok(match expr { @@ -87,7 +94,14 @@ impl EvaluatorState { Cons(_, _) => False, _ => True, }, - "define" => unimplemented!(), + "define" => match operands { + Cons(box SymbolAtom(sym), box Cons(box expr, box Nil)) => { + let evaluated = self.eval(expr)?; + self.vars.insert(sym, evaluated); + Nil + }, + _ => return Err(format!("Bad assignment")), + } "lambda" => unimplemented!(), "cond" => unimplemented!(), _ => unimplemented!(),