push
void push(var self, var obj);
Push the object obj onto the top of object self.
pop
void pop(var self);
Pop the top item from the object self.
push_at
void push_at(var self, var obj, var key);
Push the object obj onto the object self at a given key.
pop_at
void pop_at(var self, var key);
Pop the object from the object self at a given key.
Usage
var x = new(Array, Int);
push(x, $I( 0));
push(x, $I( 5));
push(x, $I(10));
show(get(x, $I(0))); /* 0 */
show(get(x, $I(1))); /* 5 */
show(get(x, $I(2))); /* 10 */
pop_at(x, $I(1));
show(get(x, $I(0))); /* 0 */
show(get(x, $I(1))); /* 10 */
Pushable and Popable object
The Push class provides an interface for the addition and removal of objects from another in a positional sense.
push can be used to add new objects to a collection and pop to remove them. Usage of push can require assign to be defined on the argument.
struct Push {
void (*push)(var, var);
void (*pop)(var);
void (*push_at)(var, var, var);
void (*pop_at)(var, var);
};