On 2026-01-30 06:17, Jure Bagić wrote:
> My general question is, why the index syntax in function statement names is not
> allowed?
>
> -- Jure
Hello Jure,
For me it's questionable favor to programmers from languages where
"function" is name-assigning statement.
In static languages you can't actually run code. You can't
MyModule = {}
MyModule[GetFancyName()] = function() end
when your writing package function.
In Lua it's expression, you can create and run function without name.
But you want name if you want reference it to call again.
(From my point of view..)
That function-statement curtsy syntax is not elegant. It emphasizes on
where function is located and hides fact that it is just rigged expression.
local t = {}
function t.a() end
-- vs
t.a = function() end
And ":" in statement-function definition is just wrong (for me):
local t = {}
function t:a() return self end -- What are those "s" "e" "l" "f" ?
print(t:a()) --
print(t) -- Ah, it's parent table! Nice hardcoded name!
-- vs
t.a = function(Id) return Id end -- Freudism, but no questions
print(t:a())
print(t)
-- Martin