binsert

binsert — inserts a value into a buffer.

Syntax

binsert (buffer, position, value)

		

Arguments

buffer

A buffer.

position

A number giving the zero-based position of the new element within the buffer, or a function.

value

A number which will be cast to an 8-bit signed integer.

Returns

The value inserted.

Description

The binsert function inserts the value by moving all other values after position one space to the right, and removing the last value from the buffer.

If position is a function, it is taken to be a comparison function with two arguments. The value will be inserted using a binary insertion sort with the function as the comparison. A comparison function must return a negative number if the value is ordinally less than the buffer element, 0 if the two are equal, and a positive number if the value is ordinally greater than the buffer element.

Example

Gamma> x = string_to_buffer("Hellothere");
#{Hellothere}
Gamma> binsert(x,5,32);
32
Gamma> x;
#{Hello ther}
Gamma> 
		

See Also

buffer