aboutsummaryrefslogtreecommitdiff
path: root/c/types.c
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-16 23:57:50 -0500
committerJoel Martin <github@martintribe.org>2014-04-16 23:57:50 -0500
commit8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 (patch)
tree13e5b2878f19ee24272ead8a92a9cb84b33ad0e5 /c/types.c
parenta05f7822b10ed4cdd61ed8384299a003baf1c1c6 (diff)
downloadmal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.tar.gz
mal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.zip
All: move some fns to core. Major cleanup.
- Don't import/require core until step4. - Define cond/or macros from step8
Diffstat (limited to 'c/types.c')
-rw-r--r--c/types.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/c/types.c b/c/types.c
index 5c06d9d..3f1771b 100644
--- a/c/types.c
+++ b/c/types.c
@@ -124,8 +124,8 @@ MalVal *malval_new_atom(MalVal *val) {
}
-MalVal *malval_new_function(void *(*func)(void *), int arg_cnt, MalVal* metadata) {
- MalVal *mv = malval_new(MAL_FUNCTION_C, metadata);
+MalVal *malval_new_function(void *(*func)(void *), int arg_cnt) {
+ MalVal *mv = malval_new(MAL_FUNCTION_C, NULL);
mv->func_arg_cnt = arg_cnt;
assert(mv->func_arg_cnt <= 20,
"native function restricted to 20 args (%d given)",
@@ -420,13 +420,37 @@ int _sequential_Q(MalVal *seq) {
MalVal *_nth(MalVal *seq, int idx) {
assert_type(seq, MAL_LIST|MAL_VECTOR,
- "nth called with non-sequential");
+ "_nth called with non-sequential");
if (idx >= _count(seq)) {
return &mal_nil;
}
return g_array_index(seq->val.array, MalVal*, idx);
}
+MalVal *_first(MalVal *seq) {
+ assert_type(seq, MAL_LIST|MAL_VECTOR,
+ "_first called with non-sequential");
+ if (_count(seq) == 0) {
+ return &mal_nil;
+ }
+ return g_array_index(seq->val.array, MalVal*, 0);
+}
+
+MalVal *_last(MalVal *seq) {
+ assert_type(seq, MAL_LIST|MAL_VECTOR,
+ "_last called with non-sequential");
+ if (_count(seq) == 0) {
+ return &mal_nil;
+ }
+ return g_array_index(seq->val.array, MalVal*, _count(seq)-1);
+}
+
+
+MalVal *_rest(MalVal *seq) {
+ return _slice(seq, 1, _count(seq));
+}
+
+
MalVal *_map2(MalVal *(*func)(void*, void*), MalVal *lst, void *arg2) {
MalVal *e, *el;
assert_type(lst, MAL_LIST|MAL_VECTOR,