From 8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 16 Apr 2014 23:57:50 -0500 Subject: All: move some fns to core. Major cleanup. - Don't import/require core until step4. - Define cond/or macros from step8 --- c/types.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'c/types.c') 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, -- cgit v1.2.3