diff --git a/src/object.h b/src/object.h index df7b8e4..ff4e220 100644 --- a/src/object.h +++ b/src/object.h @@ -40,7 +40,8 @@ enum errorCode { NOT_A_LIST, SCRIPT_NOT_FOUND, NO_CLONE_SPECIFIED, - CAN_ONLY_EVAL_STRINGS + CAN_ONLY_EVAL_STRINGS, + INDEX_PAST_END, }; #define MALLOC_FLAG 64 diff --git a/src/pebblisp.c b/src/pebblisp.c index 77e029b..55cd717 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -462,7 +462,12 @@ Object prepend(Object list, Object newElement, struct Environment *env) Object at(Object index, Object list, struct Environment *env) { - return cloneObject(*itemAt(&list, index.number)); + const Object *found = itemAt(&list, index.number); + if(found) { + return cloneObject(*found); + } else { + return errorObject(INDEX_PAST_END); + } } Object rest(Object list, Object ignore, struct Environment *env)