diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-04-20 18:16:29 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-04-20 18:16:29 -0400 |
commit | a3b17025af9ad559466763d2c760aa5830fb496d (patch) | |
tree | 044dbd055bf9f3e559b4cae9793e0736f0e60ee8 | |
parent | a60b735fe4c9b157e16205015f7173e9feb5080d (diff) | |
download | spectrum-a3b17025af9ad559466763d2c760aa5830fb496d.tar.gz spectrum-a3b17025af9ad559466763d2c760aa5830fb496d.zip |
rust: start implementing action_apply
-rw-r--r-- | minimal.rs | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -256,7 +256,26 @@ fn lambda_action<'a>(list: &'a Vec<SchemeExpr>, ctx: HashMap<&'a str, SchemeExpr } fn apply_action<'a>(list: &'a Vec<SchemeExpr>, ctx: HashMap<&'a str, SchemeExpr<'a>>) -> Result<SchemeExpr<'a>, &'static str> { - Ok(SchemeExpr::SchemeNull) + if list.len() == 0 { + // TODO: is this correct? + return Ok(SchemeExpr::SchemeNull); + } + let action = &list[0]; + // XXX: shouldn't be an unwrap here, should be a try!() + let args: Vec<SchemeExpr> = list.iter().skip(1).map(|x| scheme_meaning(x, ctx.clone()).unwrap()).collect(); + // XXX: only things that work with more than one arg + match action { + &SchemeExpr::SchemeBuiltin("+") => { + let mut val: f64 = 0.; + for arg in args { + val += match arg { + SchemeExpr::SchemeNum(x) => x, + _ => { return Err("+ builtin only takes nums"); }, + }; + } + Ok(SchemeExpr::SchemeNum(val)) }, + _ => { return Err("unimplemented builtin"); } + } } fn scheme_meaning<'a>(ast: &'a SchemeExpr, ctx: HashMap<&'a str, SchemeExpr<'a>>) -> Result<SchemeExpr<'a>, &'static str> { |