added map expressions

This commit is contained in:
Francesco Cozzuto
2021-11-26 10:11:17 +01:00
parent ed32b1a52b
commit ac4dfbc8d3
8 changed files with 327 additions and 116 deletions
+36
View File
@@ -0,0 +1,36 @@
stack = {count: 0, head: none};
fun push(stack, value)
{
node = {prev: none, item: value};
node.prev = stack.head;
stack.head = node;
stack.count = stack.count + 1;
}
fun pop(stack)
{
if stack.head == none:
return none; # return it; ?
value = stack.head.item;
stack.head = stack.head.prev;
stack.count = stack.count - 1;
return value;
}
push(stack, 1);
push(stack, 2);
push(stack, 3);
x = pop(stack);
y = pop(stack);
z = pop(stack);
w = pop(stack);
assert(x == 3);
assert(y == 2);
assert(z == 1);
assert(w == none);