summaryrefslogtreecommitdiff
path: root/miralib/ex/stack.m
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-04 12:32:20 -0500
committerJakob Kaivo <jkk@ung.org>2022-03-04 12:32:20 -0500
commit55f277e77428d7423ae906a8e1f1324d35b07a7d (patch)
tree5c1c04703dff89c46b349025d2d3ec88ea9b3819 /miralib/ex/stack.m
import Miranda 2.066 from upstream
Diffstat (limited to 'miralib/ex/stack.m')
-rw-r--r--miralib/ex/stack.m19
1 files changed, 19 insertions, 0 deletions
diff --git a/miralib/ex/stack.m b/miralib/ex/stack.m
new file mode 100644
index 0000000..d7a1af2
--- /dev/null
+++ b/miralib/ex/stack.m
@@ -0,0 +1,19 @@
+||This script defines stack, as an abstract data type based on lists.
+||Note that there is a show function for stacks, causing them to print
+||in a sensible way.
+
+abstype stack *
+with empty::stack *; push::*->stack *->stack *;
+ pop::stack *->stack *; top::stack *->*; isempty::stack *->bool;
+ showstack::(*->[char])->stack *->[char]
+
+stack * == [*]
+empty = []
+push a x = a:x
+pop(a:x) = x
+top(a:x) = a
+isempty x = (x=[])
+showstack f [] = "empty"
+showstack f (a:x) = "(push " ++ f a ++ " " ++ showstack f x ++ ")"
+
+teststack = push 1(push 2(push 3 empty))