aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-04-20 18:16:29 -0400
committerbnewbold <bnewbold@robocracy.org>2016-04-20 18:16:29 -0400
commita3b17025af9ad559466763d2c760aa5830fb496d (patch)
tree044dbd055bf9f3e559b4cae9793e0736f0e60ee8
parenta60b735fe4c9b157e16205015f7173e9feb5080d (diff)
downloadspectrum-a3b17025af9ad559466763d2c760aa5830fb496d.tar.gz
spectrum-a3b17025af9ad559466763d2c760aa5830fb496d.zip
rust: start implementing action_apply
-rw-r--r--minimal.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/minimal.rs b/minimal.rs
index 58e7273..21ef227 100644
--- a/minimal.rs
+++ b/minimal.rs
@@ -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> {