diff options
| author | Joel Martin <github@martintribe.org> | 2014-12-18 20:33:49 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:50 -0600 |
| commit | b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch) | |
| tree | f4d977ed220e9a3f665cfbf4f68770a81e4c2095 /rust/src/core.rs | |
| parent | aaba249304b184e12e2445ab22d66df1f39a51a5 (diff) | |
| download | mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip | |
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'rust/src/core.rs')
| -rw-r--r-- | rust/src/core.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/rust/src/core.rs b/rust/src/core.rs index e751f88..2bc3c39 100644 --- a/rust/src/core.rs +++ b/rust/src/core.rs @@ -281,7 +281,7 @@ pub fn nth(a:Vec<MalVal>) -> MalRet { _ => return err_str("nth called with non-integer index"), }; if idx >= seq.len() { - Ok(_nil()) + return err_str("nth: index out of range") } else { Ok(seq[idx].clone()) } @@ -342,6 +342,7 @@ pub fn count(a:Vec<MalVal>) -> MalRet { List(ref v,_) | Vector(ref v,_) => { Ok(_int(v.len().to_int().unwrap())) }, + Nil => Ok(_int(0)), _ => err_str("count called on non-sequence"), } } @@ -500,7 +501,10 @@ pub fn ns() -> HashMap<String,MalVal> { ns.insert("nil?".to_string(), func(types::nil_q)); ns.insert("true?".to_string(), func(types::true_q)); ns.insert("false?".to_string(), func(types::false_q)); + ns.insert("symbol".to_string(), func(types::_symbol)); ns.insert("symbol?".to_string(), func(types::symbol_q)); + ns.insert("keyword".to_string(), func(types::_keyword)); + ns.insert("keyword?".to_string(), func(types::keyword_q)); ns.insert("pr-str".to_string(), func(pr_str)); ns.insert("str".to_string(), func(str)); |
