lua-users home
lua-l archive

Re: Ternary operator patch

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


On Wed, Sep 15, 2010 at 4:33 PM, David Kastrup <dak@gnu.org> wrote:
> It would have taken you 10% of the time for writing the above
> speculation to actually try it out.
Again, I'm not sure I understand what you're saying, I don't see your point.
--- test1.lua ---
print("1")
a = f(g).x(a)
print("2")
a = f; (g).x(a)
--- end ---
--- test2.lua ---
a = f
(g).x(a)
--- end ---
This shows that the two lines [A] and [B] in my example are OK:
 Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
 > f = function(x) return { ["x"] = function () print("hello A") end } end
 > g = { ["x"] = function () print("hello B") end }
 > dofile("test1.lua")
 1
 hello A
 2
 hello B
The following shows the "no line break before `(' for function call" rule:
> dofile("test2.lua")
test2.lua:3: ambiguous syntax (function call x new statement) near '('
stack traceback:
 [C]: in function 'dofile'
 stdin:1: in main chunk
 [C]: ?
It this rule didn't exist, Lua would print "hello A" instead of (the
"expected") "hello B", because line breaks are (otherwise) ignored.
> Lua refuses to see those two lines either way and throws a syntax error
> instead.
Well, that's the whole point of the "no line break before `('" rule.
- Ricardo

AltStyle によって変換されたページ (->オリジナル) /