lua-users home
lua-l archive

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

On Tue, Sep 21, 2010 at 1:34 AM, Geoff Leyland
<> wrote:
> Perhaps because it's not uncommon to put a single statement on several lines?  For this very contrived example:
> call_a_function_with_a_long_name(and_a_long_argument)
>  ("and_call_the_result"):sub(and_so_on)
> Lua 5.1 would complain and I understand Lua 5.2 would interpret it as one statement.  What would Ruby do?
> In both 5.1 and 5.2 if I want it to be two statements, then I can use a semicolon, but I if I understand what you propose, I can't break my long line at that point (I know, I could break it other places) and have it be interpreted as a single statement - unless we have a continuation character like FORTRAN and VB.

I admit, that's a good point. I think Ruby manages it by virtue of not
really using () as an invocation operator. In Ruby, "" is how a
method is called, and () is incidental to that purpose. "Callable"
objects are just objects that define #call and #[] methods. So your
example is more like this in Ruby


Despite the first line being a full statement in its own right, Ruby
does treat the whole thing as a single statement (Just don't try this
in a REPL without a begin/end block around it, like I almost did...) I
had quite a bit of fun playing with a Lua implementation of a
Ruby-like object model, so I'm relatively familiar with how Ruby and
Lua differ in terms of methods. :)

As far as Lua goes, I prefer the greedy approach Lua 5.2 introduces
for the one case in 5.1 where a newline matters. Unfortunately, my
environmental-indexing suggestion goes completely against this
approach, since something like this would look sane to the developer,
yet Lua would understand it differently:

[42] = bar()