lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


The thing is that in your proposed table syntax, you *aren’t* simply defining a function that can be called later in the current environment, as you would in a language like C.

You are initialising a named key in a table to have the value “some function”. And there is a well-defined and very clear syntax for doing that in table constructors, where you write { key = value }.

If you are really concerned about Lua users who are put off by the fact that Lua “isn’t like the programming languages they are used to” and who would prefer to see coding usage that they are more familiar with...

...then they are going to get stuck on “do ... end” and “then ... end” where they expect squiggly brackets,, and on arrays, where they expect element 1 to be numbered 0.

So function name() ... end puts the function called name into the current environment, and { name = function() ... end } creates a key called name, inside a table, that is a function.

I wouldn’t call that “mixed styles” or describe name = function() ... end as “incongruous”. Seems perfectly clear to me.


...

On 1 Jun 2021, at 19:34, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:

On Tue, Jun 1, 2021 at 5:58 PM Paul Ducklin wrote:
   local func = function() ... end
...looks nicer than...
   local function func() ... end

It seems there exist two groups of Lua users.

1) First group - users who prefer to emphasize that Lua functions as just regular objects.
The "natural inclination" of 1nd group users is to use the "function" keyword for producing R-values only.
They would be happy with named-functions-syntax completely removed from Lua (despite the small problem with local recursive functions).

2) Second group - users who prefer to write Lua scripts in a way similar to programming in other languages.
The "natural inclination" of 2nd group users is to always see a function's name after the keyword "function".
From their point of view the existing Lua syntax for defining local and global functions is nice.
But when they try to define a function inside an object they are forced to use incongruous "name=function" syntax.
Mixing the two styles in one Lua program is ugly.

 
 I don’t understand the “problem” you are trying to solve

The problem is: the users from 1st and 2nd groups do not have "equal rights".
The former are quite happy in the current Lua, they can always follow their favorite "all-functions-are-anonymous" style.
The latter are unable to always follow their favorite "each-function-is-defined-with-a-name" style.

Please note that most Lua newcomers are in the second group.