lua-users home
lua-l archive

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

On Mon, Sep 20, 2010 at 11:53 PM, Jonathan Castello <> wrote:
> On Mon, Sep 20, 2010 at 8:29 PM, Nilson <> wrote:
>> Proposition 1. Make the separator optional in table initialization
>> Proposition 2. Extending the function name syntactic sugar to tables.
> If they're doable, I like these two a lot.

There have been proposals for these before:

And personally, I've wanted something like Proposition 1.  Lisp and
CMake languages allow this simpler syntax.  The major problem it poses
in Lua is that Lua expressions without a commas between them can too
easily run together.  {a "" {}} is valid in Lua 5.1, for example.  The
problem also occurs with statements without semicolons between them
("ambiguous syntax" error) but with a much lower frequency.

You can simulate a Perl-like "qw" quote operator though:

  -- like
  local function qw(s)
    local t = {}
    for x in s:gmatch("%S+") do
      t[#t+1] = x
    return t

  t = qw[[ foo  bar  baz ]]

Unfortunately, you can't easily embed variables, particularly
lexicals, inside these strings.  That's a common problem, and more
ideally you'd want Lua to expand qw at the macro/lexical processing
stage rather than at run-time:

>> Proposition 3: Unquoted strings constants

See qw above.