list.c
void list_insert(atom_t* obj, int index, atom_t* item, char bind) {
    list_assert(obj, "list_ins");
    if (!item) {
        printf("\x1b[95m" "Fatal error: list_ins: bad item!\n" "\x1b[0m");
        exit(EXIT_FAILURE);
    }

    list_t* l = obj->val.list;

    // Allocate more space if necessary
    if (l->len == l->maxlen) {
        l->maxlen *= 1.5;
        l->items = realloc(l->items, l->maxlen * sizeof(atom_t*));
    }

    if (index > l->len || index < 0)
        // insert item at the end of the list
        index = l->len;
    else
        // shift items to free space
        memmove(l->items + index + 1, l->items + index, (l->len - index) * sizeof(atom_t*));

    // Insert item
    l->items[index] = item;
    ++l->len;
    if (bind)
        atom_bind(item, obj);
}
/*
--------------------------------------
list_insert

    Insert item to list at given index.
--------------------------------------
*/
list_insert
Insert item to list at given index.
list_insert Insert item to list at given index .
void list_insert(atom_t* obj, int index, atom_t* item, char bind) {
    list_assert(obj, "list_ins");
    if (!item) {
        printf("\x1b[95m" "Fatal error: list_ins: bad item!\n" "\x1b[0m");
        exit(EXIT_FAILURE);
    }
    list_t* l = obj->val.list;
    if (l->len == l->maxlen) {
        l->maxlen *= 1.5;
        l->items = realloc(l->items, l->maxlen * sizeof(atom_t*));
    }
    if (index > l->len || index < 0)
        index = l->len;
    else
        memmove(l->items + index + 1, l->items + index, (l->len - index) * sizeof(atom_t*));
    l->items[index] = item;
    ++l->len;
    if (bind)
        atom_bind(item, obj);
}
void list_insert ( atom_t * obj , int index , atom_t * item , char bind ) { list_assert ( obj , " " ) ; if ( ! item ) { printf ( " \x1b " " \n " " \x1b " ) ; exit ( EXIT_FAILURE ) ; } list_t * l = obj -> val . list ; if ( l -> len == l -> maxlen ) { l -> maxlen *= 1.5 ; l -> items = realloc ( l -> items , l -> maxlen * sizeof ( atom_t * ) ) ; } if ( index > l -> len || index < 0 ) index = l -> len ; else memmove ( l -> items + index + 1 , l -> items + index , ( l -> len - index ) * sizeof ( atom_t * ) ) ; l -> items [ index ] = item ; ++ l -> len ; if ( bind ) atom_bind ( item , obj ) ; }
list_insert
Insert item to list at given index.
list_insert Insert item to list at given index .
// Allocate more space if necessary // insert item at the end of the list // shift items to free space // Insert item