Check indexes etc for `at`

This commit is contained in:
Sage Vaillancourt 2021-07-05 01:13:45 -04:00
parent 6ec0da6353
commit 77c9c39295
2 changed files with 8 additions and 2 deletions

View File

@ -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

View File

@ -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)