lua-users home
lua-l archive

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


But I *really* like the undef syntax design!

OK, this does sound interesting too.

On Mar 17, 2018, at 8:16 AM, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:

> For backward compatibility, usual table constructor {...} creates a table
> with "user-specified length" set to nil.
> New syntax {...#} is used for constructing a table
> with its "user-specified length" set to actual data length.
> 
> Probably, syntax {...#} is not nice.

I wonder how much code would break by replacing the existing meaning of #{}. It's legal, but it's so weird nobody likely uses it. (Famous last words!)

Making the full constructor syntax available would have a runtime cost.

  n = 37
  #{1, 2, [n]=37}

It's not very Lua-like, but I could live with a requirement that all *keys* be constants for this kind of shortcut constructor.

For completeness, add the sugar:

  f#{math.pi} <=> f(#{math.pi})

-- 
Jay