Tasmota/lib/libesp32/berry/examples/lambda.be

9 lines
236 B
Plaintext
Raw Normal View History

2021-04-12 18:53:35 +01:00
# simple lambda example
print((/a b c-> a * b + c)(2, 3, 4))
# Y-Combinator and factorial functions
Y = /f-> (/x-> f(/n-> x(x)(n)))(/x-> f(/n-> x(x)(n)))
F = /f-> /x-> x ? f(x - 1) * x : 1
fact = Y(F)
print('fact(10) == ' .. fact(10))