Commit b54bd15e7ea8b390f7c840955507ad5763a6b388

Thomas de Grivel 2024-04-08T20:26:52

List.last

diff --git a/.ic3_history b/.ic3_history
index 9a549c0..f2d4f6f 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,21 +1,3 @@
-def beaucoup = 1 + 10000000000000000000000000000000000000000000
-double(beaucoup)
-dt
-double(3/4)
-1 / double(3/4)
-a = b
-a = 1
-b = a
-b = ^ a
-b = a
-a = ^ b
-a = ^ c
-a = ^ b
-b = 1
-a = ^ b
-a = c
-fib(10)
-fib(20)
 def fib = fn { (0) { 1 } (1) { 1 } (x) { if x < 0 then 1 else fib(x - 2) + fib(x - 1) end } }
 def fib = fn (x) { if x < 0 then 1 else fib(x - 2) + fib(x - 1) end }
 def fib = fn (x) { if x < 0 then
@@ -97,3 +79,21 @@ Tiyon.double_list(21 + 21)
 [42, x] = [42, 42]
 x
 Tiyon.double_list(21 + 21) = [42, y]
+def last = fn (x) do
+  [y | _] = List.reverse(x)
+  y
+end
+def last = fn (x) do
+  [y | _] = List.reverse(x)
+  y
+end
+def List.last = fn (x) do
+  [y | _] = List.reverse(x)
+  y
+end
+List.last([1, 2, 3, 4])
+def List.last = fn (x) do
+  [y | z] = List.reverse(x)
+  y
+end
+List.last([1, 2, 3, 4])
diff --git a/ic3/.ic3_history b/ic3/.ic3_history
index 8d20fcf..f073691 100644
--- a/ic3/.ic3_history
+++ b/ic3/.ic3_history
@@ -1,15 +1,3 @@
-fib(10)
-fib(20)
-def fib = fn { (0) { 1 } (1) { 1 } (x) { if x < 0 then 1 else fib(x - 2) + fib(x - 1) end } }
-def fib = fn (x) { if x < 0 then 1 else fib(x - 2) + fib(x - 1) end }
-def fib = fn (x) { if x < 0 then
-1
-else
-fib(x - 2) + fib(x - 1)
-end
-}
-if true then 1 else 2 end
-if true 1 else 2 end
 def fib = fn (x) { if x < 0 1 else fib(x - 2) + fib(x - 1) end }
 fib(-1)
 def fib = fn (x) { if x < 0 0 else fib(x - 2) + fib(x - 1) end }
@@ -81,19 +69,31 @@ Tiyon.double_list(21 + 21)
 [42, x] = [42, 42]
 x
 Tiyon.double_list(21 + 21) = [42, y]
-defmodule Tiyon do
-  def double_list = macro (x) do [x, x] end
+def last = fn (x) do
+  [y | _] = List.reverse(x)
+  y
 end
-Tiyon.double_list(21 + 21) = [42, y]
-defmodule Tiyon do
-  def double_list = macro (x) do [x, x] end
+def last = fn (x) do
+  [y | _] = List.reverse(x)
+  y
 end
-Tiyon.double_list(21 + 21) = y
-y
-defmodule Tiyon do
-  def double_list = macro (x) do [x, x] end
+def List.last = fn (x) do
+  [y | _] = List.reverse(x)
+  y
+end
+List.last([1, 2, 3, 4])
+def List.last = fn (x) do
+  [y | z] = List.reverse(x)
+  y
+end
+List.last([1, 2, 3, 4])
+def List.last = fn (x) do
+  [y | z] = List.reverse(x)
+  y
+end
+List.last([1, 2, 3, 4])
+def List.last = fn (x) do
+  [y | _] = List.reverse(x)
+  y
 end
-Tiyon.double_list(21 + 21) = y
-y
-Tiyon.double_list(21 + 21) = [42, z]
-z
+List.last([1, 2, 3, 4])