You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
local lib = {
f1(a)::
local a = true;
a,
f2(a)::
local a = a && true;
a,
f3(a)::
local a = true;
local a = false;
a,
f4(a)::
local b = a && true;
local a = b;
a,
};
lib.f1(false) &&
lib.f2(false) &&
lib.f3(false) &&
lib.f4(false) &&
true
Both f1 and f3, f4 work so it seems like f2 should work. Is recursive redecleration explicitly forbidden? It seems quite useful (e.g.) :
local result =
if condition then
result + { "foo" : "bar" }
else
result
...
result
The error is a RUNTIME error and it should probably be a STATIC error if this explicitly forbidden.
is actually referring recursively to the a that is being defined on the same line, so the infinite loop is expected behavior.
You can of course write one that terminates:
local x = false && x
In this case the shortcut semantics for && prevents the x from being recursively evaluated.
This is the same as e.g. Haskell. In fact I think even in C you can do int x = x + 1 although it's undefined behavior because rather than being a recursive definition, you're reading x before it's been initialized.
I see that it is interpreted as a declaration and not a reassignment which is strange from my naive perspective as it seems like the language then must allow redecleration within a scope just not recursive decleration.
Both f1 and f3, f4 work so it seems like f2 should work. Is recursive redecleration explicitly forbidden? It seems quite useful (e.g.) :
The error is a RUNTIME error and it should probably be a STATIC error if this explicitly forbidden.
The text was updated successfully, but these errors were encountered: