Commit 352a4d41d974374e3797aef882e5ff1c7c1dd48e

Thomas de Grivel 2024-04-17T16:18:24

list.c3

diff --git a/lib/c3/0.1/list.c3 b/lib/c3/0.1/list.c3
new file mode 100644
index 0000000..71bcb0c
--- /dev/null
+++ b/lib/c3/0.1/list.c3
@@ -0,0 +1,20 @@
+defmodule List do
+
+  def cast = cfn List "list_init_cast" (Result, Sym, Tag)
+
+  def map = fn {
+    ([], _) do
+      [] }
+    end
+    ([a | b], f) do
+      [f(a) | map(b, f)]
+    end
+  }
+
+  def reverse = fn {
+    (x) { reverse(x, []) }
+    ([], acc) { acc }
+    ([a | b], acc) { reverse(b, [a | acc]) }
+  }
+
+end