From d33aa57f8e825c016d0f11c263a1b187223d45eb Mon Sep 17 00:00:00 2001 From: samsonium Date: Sat, 17 Oct 2026 21:57:04 +0300 Subject: [PATCH] feat: add first hard example Hard example tests all actual language features. For now its: - Classes - Methods - Recursive calls - Object move and borrowing --- exl/hard-1.fzs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 exl/hard-1.fzs diff --git a/exl/hard-1.fzs b/exl/hard-1.fzs new file mode 100644 index 0000000..077d26e --- /dev/null +++ b/exl/hard-1.fzs @@ -0,0 +1,61 @@ +class Node +{ + int value; + Node next; + + fn append(int val) Node + { + if (this.next == null) + { + Node tail = new Node; + tail.value = val; + tail.next = null; + this.next = tail; + return this; + } + + this.next = this.next.append(val); + return this; + } + + fn sum() int + { + if (this.next == null) + return this.value; + + return this.value + this.next.sum(); + } + + fn printList() + { + printline(this.value); + if (this.next != null) + this.next.printList(); + } +} + +fn createList(int count) Node +{ + if (count <= 0) + return null; + + Node head = new Node; + head.value = count; + head.next = createList(count - 1); + return head; +} + +printline("===== Test 1: factory & recursive escaping ====="); +Node list = createList(3); +printline("Elements:"); +list.printList(); + +printline("===== Test 2: mutation & methods ====="); +int total = list.sum(); +printline("Sum of elements:"); +printline(total); + +if (total == 16) + printline("Tests passed!"); +else printline("Tests failed"); +