aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-04-25 23:29:08 -0400
committerbnewbold <bnewbold@robocracy.org>2016-04-25 23:29:08 -0400
commit4b11d9fbd2b4ef0bc4fd3bfba18c3bd2ce10ea73 (patch)
tree871d8440f84502a514f0ccbd33fc01c286a022c3
parent6880d8194a03152fdb293565000efa7149aa0929 (diff)
downloadspectrum-4b11d9fbd2b4ef0bc4fd3bfba18c3bd2ce10ea73.zip
spectrum-4b11d9fbd2b4ef0bc4fd3bfba18c3bd2ce10ea73.tar.gz
rust: more car/cdr/cons tweaks (still needs review)
-rw-r--r--rust/spectrum.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/rust/spectrum.rs b/rust/spectrum.rs
index b61e3ad..3a0362f 100644
--- a/rust/spectrum.rs
+++ b/rust/spectrum.rs
@@ -520,7 +520,7 @@ fn apply_action(list: &Vec<SchemeExpr>,
&SchemeExpr::SchemeList(ref list) => {
Ok(list[0].clone())
},
- _ => Err(format!("cdr only takes lists"))
+ _ => Err(format!("car only takes lists"))
}
},
"cdr" => {
@@ -529,9 +529,13 @@ fn apply_action(list: &Vec<SchemeExpr>,
}
match &args[0] {
&SchemeExpr::SchemeList(ref list) => {
- Ok(SchemeExpr::SchemeList(list[1..].to_vec()))
+ if list.len() > 1 {
+ Ok(SchemeExpr::SchemeList(list[1..].to_vec()))
+ } else {
+ Ok(SchemeExpr::SchemeNull)
+ }
},
- _ => Err(format!("car only takes lists"))
+ _ => Err(format!("cdr only takes lists"))
}
},
"cons" => {
@@ -539,12 +543,15 @@ fn apply_action(list: &Vec<SchemeExpr>,
return Err(format!("cons takes two arguments"));
}
match &args[1] {
+ &SchemeExpr::SchemeNull => {
+ Ok(SchemeExpr::SchemeList(vec![args[0].clone()]))
+ },
&SchemeExpr::SchemeList(ref list) => {
let mut ret = vec![args[0].clone()];
ret.extend_from_slice(list);
Ok(SchemeExpr::SchemeList(ret))
},
- _ => Err(format!("cdr takes only lists"))
+ _ => Err(format!("cons second arg must be list or null"))
}
},
"display" => {