Shiny Language Reference

Language Reference > Basic Language


removeat

removeat(varname, int Position, int Count);

 

 

Removes elements from within an array

The REMOVEAT statement immediately alters the space allocated to an array variable by deleting exactly the number of elements specified at the position specified. As the name implies, REMOVEAT can only decrease the size of the array. To increase the size of the array, refer to realloc or insertat.

REMOVEAT may only be used on variables that have been declared as arrays. If REMOVEAT is supplied with a variable that is not declared as an array the compiler will generate an error.

If REMOVEAT is given an invalid position - either beyond the current size of the array or less than integer 0 - it will abort and leave the array untouched. This is a safety mechanism to ensure the wrong elements are not deleted. Brass assumes that if an invalid position is specified it was caused by faulty code logic and should therefore be ignored. If you need to test whether a removal worked simply compare the array size using getalloc before and after the REMOVEAT operation.

Refer to realloc for more information regarding resizing arrays.

 

Parameters

Varname

The variable, declared as an array, to resize.

Position

The zero based position to begin the deletion. For example, providing integer 0 for this parameter will delete elements at the start of the array. Providing integer 1 will delete elements after the first array element, etc.

Count

The number of elements to delete.

Return Value

No return value.

 

Example Code

// Declare an array with 5 elements
int test[5];
for(int ic = 0; ic < getalloc(test); ic++)
{
    // Set and print an example value
    test[ic] = ic * 10;
    print test[ic];
}

print "Resizing array...";

// Remove element #3 (zero based, therefore #3 is [2])
deleteat(test, 2, 1);

for(ic = 0; ic < getalloc(test); ic++)
{
    // Print the array contents with the removal
    print test[ic];
}