Check indexes etc for `at`
This commit is contained in:
parent
6ec0da6353
commit
77c9c39295
|
@ -40,7 +40,8 @@ enum errorCode {
|
||||||
NOT_A_LIST,
|
NOT_A_LIST,
|
||||||
SCRIPT_NOT_FOUND,
|
SCRIPT_NOT_FOUND,
|
||||||
NO_CLONE_SPECIFIED,
|
NO_CLONE_SPECIFIED,
|
||||||
CAN_ONLY_EVAL_STRINGS
|
CAN_ONLY_EVAL_STRINGS,
|
||||||
|
INDEX_PAST_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MALLOC_FLAG 64
|
#define MALLOC_FLAG 64
|
||||||
|
|
|
@ -462,7 +462,12 @@ Object prepend(Object list, Object newElement, struct Environment *env)
|
||||||
|
|
||||||
Object at(Object index, Object list, 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)
|
Object rest(Object list, Object ignore, struct Environment *env)
|
||||||
|
|
Loading…
Reference in New Issue