%mathpiper,def="Push"

Function("Push",{stack,element})
[
  DestructiveInsert(stack,1,element);
];

%/mathpiper



%mathpiper_docs,name="Push",categories="User Functions;Lists (Operations)"
*CMD Push --- add an element on top of a stack
*STD
*CALL
	Push(stack, expr)

*PARMS

{stack} -- a list (which serves as the stack container)

{expr} -- expression to push on "stack"

*DESC

This is part of a simple implementation of a stack, internally
represented as a list. This command pushes the expression "expr" on
top of the stack, and returns the stack afterwards.

*E.G.

In> stack := {};
Result: {};
In> Push(stack, x);
Result: {x};
In> Push(stack, x2);
Result: {x2,x};
In> PopFront(stack);
Result: x2;

*SEE Pop, PopFront, PopBack
%/mathpiper_docs