Add nth builtin
This commit is contained in:
@@ -69,6 +69,13 @@ LISP_FUNC_1(ucl_builtin_cdr, state, arg) {
|
||||
return ucl_cdr(arg);
|
||||
}
|
||||
|
||||
LISP_FUNC_2(ucl_builtin_nth, state, n, list) {
|
||||
UCL_COND_OR_RET_ERROR(n->type == UCL_TYPE_INT, "First argument to nth must be an integer");
|
||||
UCL_COND_OR_RET_ERROR(list->type == UCL_TYPE_CELL, "Second argument to nth must be a list");
|
||||
|
||||
return ucl_list_nth(list, n->integer);
|
||||
}
|
||||
|
||||
LISP_FUNC_2(ucl_builtin_add, state, arg0, arg1) {
|
||||
if (arg0->type != UCL_TYPE_INT) {
|
||||
return ucl_error_create("Invalid type of argument 0 to 'add'");
|
||||
|
||||
@@ -21,6 +21,7 @@ struct ucl_object *ucl_builtin_now_millis_mono(struct ucl_state *state, struct u
|
||||
|
||||
struct ucl_object *ucl_builtin_car(struct ucl_state *state, struct ucl_object *args);
|
||||
struct ucl_object *ucl_builtin_cdr(struct ucl_state *state, struct ucl_object *args);
|
||||
struct ucl_object *ucl_builtin_nth(struct ucl_state *state, struct ucl_object *args);
|
||||
struct ucl_object *ucl_builtin_list(struct ucl_state *state, struct ucl_object *args);
|
||||
struct ucl_object *ucl_builtin_print(struct ucl_state *state, struct ucl_object *args);
|
||||
struct ucl_object *ucl_builtin_printl(struct ucl_state *state, struct ucl_object *args);
|
||||
|
||||
@@ -49,11 +49,11 @@ int main(int argc, const char **argv) {
|
||||
ucl_state_put(state, "list-p", ucl_builtin_create(ucl_builtin_list_p));
|
||||
ucl_state_put(state, "car", ucl_builtin_create(ucl_builtin_car));
|
||||
ucl_state_put(state, "cdr", ucl_builtin_create(ucl_builtin_cdr));
|
||||
ucl_state_put(state, "nth", ucl_builtin_create(ucl_builtin_nth));
|
||||
// TODO:
|
||||
// - equality
|
||||
// - map
|
||||
// - reduce
|
||||
// - nth
|
||||
// - booleans (e.g. not)
|
||||
|
||||
if (argc < 2) {
|
||||
|
||||
Reference in New Issue
Block a user