lua-users home
lua-l archive

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


On 20/06/2019 12:43, Paul Ducklin wrote:
Add two new keywords. Avoid complex syntactic hacks!



Adding keywords is more disruptive to old code. Moreover, if more attributes were needed in the future you will have solved nothing.

Here the attempt is to come up with a syntax which is both readable and backward compatible AND that allows future extensions without further syntax change.



On 20 Jun 2019, at 10:22, Lorenzo Donati <lorenzodonatibz@tiscali.it> wrote:

On 20/06/2019 07:39, Egor Skriptunoff wrote:
On Fri, Jun 14, 2019 at 11:22 PM Viacheslav Usov wrote:

This is probably bikeshedding, but:
local (x scoped), (y const), (z const alias) = a, b, c



This is a nice bikeshedding!
From aesthetic point of view, it looks more pleasant than other possible
syntax such as <const>, @const and :const

Definitely!

As far as bikeshedding goes :-) I was one of the proponent of the @const syntax because interfered less with my "internal parser" (angle brackets are either too C++ or they may be confused with relops, especially with long list of attributes).

This new suggestion is both elegant and readable. "()" means "grouping" anyway in Lua, so no confusion. The "(var_name att_list)" allows both multiple var declarations in a single local statement and also multiple attribute /with no comma inbetween/ (which could confuse reader in long statements with both multiple vars AND multiple attributes.

This might also elegantly allow parametrized attributes (e.g. for optional type checking)

Contrived example with hard wrapping (and funny attributes):

local (x const helpful alias ),
  (y const alias integer(32) ),
  (z const final float(64) ),
  (errmsg const string(256) whatever )
= mytable, 345, 23.4, myfunc(a,b,c)

Still quite readable!

I think I love it! :-)

I hope this doesn't open the door to some nasty ambiguity (I can't say, I'm no big grammar expert) so that Lua team may possibly consider its adoption!

The only problem I see is that it can't be applied so easily to global variables or table fields, if ever this was a long term goal.

Hooray for Viacheslav! :-)

Cheers!

-- Lorenzo