diff --git a/tiger-linked-list.tig b/tiger-linked-list.tig new file mode 100644 index 0000000..9fd3edd --- /dev/null +++ b/tiger-linked-list.tig @@ -0,0 +1,30 @@ +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