1
0
tigersay/tiger-linked-list.tig

31 lines
864 B
Plaintext
Raw Normal View History

2024-03-10 14:12:06 +00:00
let
type int_node = { val: int, next: int_node }
type int_list = { first: int_node }
function list_new (): int_list =
int_list { first = nil }
function list_add (list: int_list, new_int: int) =
list.first := int_node { val = new_int
, next = list.first }
function list_sum (list: int_list) : int =
let function sum_help (node: int_node): int =
if node <> nil
then node.val + sum_help(node.next)
else 0
in sum_help(list.first)
end
var integers := list_new()
in
list_add(integers, 1);
list_add(integers, 4);
list_add(integers, 1);
list_add(integers, 2);
list_add(integers, 1);
for i := 1 to list_sum(integers) do
print(concat(chr(i + 48), ". line of text\n"));
print("The 10th and last line of text!")
end