lua-users home
lua-l archive

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


On Sun, Jun 2, 2019 at 7:07 PM Andrew Gierth wrote:

 Dibyendu> Do people find anything ugly about current Lua syntax?

The need to put ; before a statement starting with ( is very ugly.


The possible way to fix this ugliness is to change Lua syntax so that a newline before ( is considered as statement delimiter.
And probably almost none of the old code would be broken by this syntax change.
Most people write
   func(
   ...)
Almost none of programmers writes
   func
   (...)


 
The "x and y or z" workaround for the lack of a real ternary conditional
operator is ugly and dangerous. (And the popularity of this idiom shows
the need for such an operator.)



"x and y or z" is a smart feature of Lua.
It gets "almost ternary" operator without additional syntax.
If you're so pedantic (about the case when y is falsey), use the following:
({y, z})[x and 1 or 2]

 

Having to use select('#',...) with all its attendant overheads just to
count the number of args to a vararg function is ugly.



Yes, that's really ugly, especially from the performance's point of view.
Suggested fix is to introduce new Lua syntax for using vararg as a pseudo-table value.
Assuming new syntax is <vararg>:
   local k_th_arg = <vararg>[k]  -- no actual table exists, so indexing is emulated using additional VM instruction
   local num_args = #<vararg>    -- "borders" in pseudo-table are ignored, the result is the same as select('#',...)



 
 Dibyendu> What about the proposed new syntax <toclose> and <const>?

... meh. It doesn't look too bad to me and the proposed alternatives
seem worse.


The motto of Lua 5.4 is "Surprise! We have angle brackets in Lua!" :-)