RosettaCodeData/Task/Stack/Elisa/stack-2.elisa

26 lines
906 B
Plaintext

component GenericStack ( Stack, ElementType );
type Stack;
Stack(MaxSize = integer) -> Stack;
Empty( Stack ) -> boolean;
Full ( Stack ) -> boolean;
Push ( Stack, ElementType)-> nothing;
Pull ( Stack ) -> ElementType;
begin
type sequence = term;
ElementType & sequence => sequence;
nil = null (sequence);
head (sequence) -> ElementType;
head (X & Y) = ElementType:X;
tail (sequence) -> sequence;
tail (X & Y) = Y;
Stack (Size) = Stack:[ list = nil ];
Empty ( stack ) = (stack.list == nil);
Full ( stack ) = false;
Push ( stack, ElementType ) = [ stack.list:= ElementType & stack.list ];
Pull ( stack ) = [ exception (Empty (stack), "Stack Underflow");
Head = head(stack.list); stack.list:=tail(stack.list); Head];
end component GenericStack;