From b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 18 Dec 2014 20:33:49 -0600 Subject: All: add keywords. Also, fix nth and count to match cloure. --- rust/src/core.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'rust/src/core.rs') 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) -> 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) -> 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 { 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)); -- cgit v1.2.3