[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Thoughts on optional commas
- From: Dimitris Papavasiliou <dpapavas@...>
- Date: Mon, 5 Mar 2012 14:54:50 +0200
There's also this case for example:
foo = function (a) return a end
bar = {foo (2)}
So what does this mean in the absence of commas? Does bar contain two
values, one a function and the other the number two or just the number
two returned after foo is called?
It seems more than probable that making something like a comma
optional would lead to other ambiguities similar to the one above or
the ones already mentioned and I don't think it would be in the spirit
of Lua to add complexity (e.g. 'foo(2)' is always a function call but
'foo (2)' may not be, sometimes you may need commas but sometimes
you're free to leave them out etc.) just to make things easier on
novice users (which you won't really be doing in the long run as
they'll have to learn, understand and apply more syntax rules unless
they use lua just to declare some tables in a configuration file).
Dimitris
On Mon, Mar 5, 2012 at 2:14 PM, Axel Kittenberger <axkibe@gmail.com> wrote:
>> But to keep the discussion going:
>> I know that we just removed a special newline rule for Lua 5.2, but maybe
>> commas in tables could be made optional if the elements are followed by a
>> newline ...? That seems to be the most common use case in the given
>> examples.
>
> Indeed this is the case it makes any sense. However, I wonder if this
> semi-significance of newline is more a new abscess rather than a
> patch.
>
> Consider following function in Javascript, what do you guess it returns?
>
> function test() {
> return
> [1,
> 2];
> }
>
> If you said [1, 2] you are wrong, it returns undefined. Only sense it
> makes is when you go Coffescript/MoonScript/Phyton and make it full
> significant including signifance of white space. Then
> a = [
> afunc
> "muh"
> ]
> is obviously an array with two items, a function point to print and
> the String "muh" while
> a = [
> afunc
> "muh"
> ]
> is obviously an array with one item, the result of afunc("muh")
>
> Go this way, or go that way, but don't half-ass things :-)
>