Hash :
edad7979
Author :
Thomas de Grivel
Date :
2025-05-13T19:10:51
add tests for fn + block return and unwind_protect
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
quote fn (x) { x }
quote fn (x, _y) { x }
quote fn ([x | _y]) { x }
quote fn {
([]) { :error }
([x | _y]) { x }
(_) { :error }
}
quote fn (x) do
"Hello, world !"
x * 2
end
a = fn (x) { x }
a(1)
b = fn (x, _y) { x }
b(1, 2)
c = fn ([x | _y]) { x }
c([1, 2])
d = fn {
([]) { :error }
([x | _y]) { x }
(_) { :error2 }
}
d([1, 2])
e = fn (x) do
"Hello, world !"
x * 2
end
e(2)
quote do
f = fn (x) do
puts("Hello, world !")
x * 2
end
f(2)
end
do
f = fn (x) do
puts("Hello, world !")
x * 2
end
f(2)
end
quote f = fn (x) { fn (y) { x * y } }
f = fn (x) { fn (y) { x * y } }
quote g = f(2)
g = f(2)
quote g(3)
g(3)
quote h = fn (x) {
unwind_protect(do
puts("a")
return x * 2
-1
end, puts("b"))
}
h = fn (x) {
unwind_protect(do
puts("a")
return x * 2
-1
end, puts("b"))
}
quote h(21)
h(21)