aboutsummaryrefslogtreecommitdiff
path: root/go/src/core
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-18 20:33:49 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:50 -0600
commitb8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch)
treef4d977ed220e9a3f665cfbf4f68770a81e4c2095 /go/src/core
parentaaba249304b184e12e2445ab22d66df1f39a51a5 (diff)
downloadmal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz
mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'go/src/core')
-rw-r--r--go/src/core/core.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/go/src/core/core.go b/go/src/core/core.go
index 17e92f0..2acca69 100644
--- a/go/src/core/core.go
+++ b/go/src/core/core.go
@@ -140,7 +140,11 @@ func concat(a []MalType) (MalType, error) {
func nth(a []MalType) (MalType, error) {
slc, e := GetSlice(a[0]); if e != nil { return nil, e }
idx := a[1].(int)
- return slc[idx], nil
+ if idx < len(slc) {
+ return slc[idx], nil
+ } else {
+ return nil, errors.New("nth: index out of range")
+ }
}
func first(a []MalType) (MalType, error) {
@@ -294,8 +298,14 @@ var NS = map[string]MalType{
return True_Q(a[0]), nil },
"false?": func(a []MalType) (MalType, error) {
return False_Q(a[0]), nil },
+ "symbol": func(a []MalType) (MalType, error) {
+ return Symbol{a[0].(string)}, nil },
"symbol?": func(a []MalType) (MalType, error) {
return Symbol_Q(a[0]), nil },
+ "keyword": func(a []MalType) (MalType, error) {
+ return NewKeyword(a[0].(string)) },
+ "keyword?": func(a []MalType) (MalType, error) {
+ return Keyword_Q(a[0]), nil },
"pr-str": func(a []MalType) (MalType, error) { return pr_str(a) },
"str": func(a []MalType) (MalType, error) { return str(a) },