lua-users home
lua-l archive

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


On 12/12/2012 14:44, Roberto Ierusalimschy wrote:
There's no honest ambiguity in the syntax -- it's just a question of
protecting against likely bugs.

f()
(g or h)()

is naturally read as 2 statements, though given Lua's grammar it should be
parsed as just one.

I think Lua's grammar allows that code to be read as two statements; it
is a very "honest" ambiguity.

Yes, but in 5.2, it reads it as one statement only.

function f()
  print("Foo")
  return function ()
    print("Bar")
      return function ()
        print("Baz")
    end
  end
end

function h()
  print("Brrrr")
end


f()
(g or h)()

f()
;(g or h)()

==>

Foo
Bar
Baz

Foo
Brrr


Scala, which attempted to ditch semi-colons too, chose to see two consecutive newlines as a statement separator. It makes sense (if you separate statements, that's likely because they are independent), it looks better than an occasional semi-colon (even more starting a line!) but it is a bit brittle, IMHO.

Perhaps the designers of C made these separators mandatory for a reason, after all... :-)
(Now, one has to admit that the cases like above, where semi-colons are really mandatory, are quite rare, I think.)

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --