|
|
|
|
|
by oedo
1015 days ago
|
|
Declaring a function with `lambda` prepends runtime nil checks for each argument to the function body (excluding optional args-- specified with a question mark, eg. `?x`-- and variable arguments, eg. `...`[1]). This Fennel: (fn foo [x y ...]
(print x y ...))
(lambda bar [x ?y ...]
(print x ?y ...))
...transpiles to this Lua: local function foo(x, y, ...)
return print(x, y, ...)
end
local function bar(x, _3fy, ...)
_G.assert((nil ~= x), "Missing argument x on test.fnl:3")
return print(x, _3fy, ...)
end
[1] Fennel's alternative `& xs` vargs format does create a runtime check in functions declared with lambda, but it always evaluates to true because it simply nil-checks the table (here `xs`) that it dumps Lua `...` vargs into. |
|