lua-users home
lua-l archive

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


Peter Hill:
> Probably the most 'natural' identity/no-operation operator is '+', noting
> that classically "+5" is the same as "5" (which appears in Lua as 1e+5 ==
> 1e5). I suppose that using the identity operator might be clearer in cases
> needing leading parentheses? Eg:
>       +(fred or joe)(123)

RLake@oxfam.org.uk:
> That doesn't work because + is not unambiguously unary. So:
>     a = f
>     +(b or c)(g)
>
> is still ambiguous.

No more ambiguous than the unary/binary "-" (they would have exactly the
_same_ syntax and precedence as "+", both being summing operators). Ie, is:
    a = b - c
equal to
    a = b (-c)
or to
    a = (b-c)

It's equal to "a = (b-c)" because, as I mentioned in the previous email,
Lua's authors deliberately (I assume) kept conditions (a), (b), and (c)
satisfied by restricting what syntax function composition could take.
Currently, the only allowed forms are:
    f (blah)
    f {blah}
    f "blah"
although it could easily be extended to take the other atomic constants
    f 123
    f nil
    f true
    f false
without any problem.


> In any event, I find the use of + as an identity operator a bit
> irritating, for some reason. Maybe it's my anti-Perl bias. I prefer + to
> be unambiguously binary.

I guess I chose it because APL (a language you seem to know too :-) uses it
for the null operation. It's not that pretty, true, but it is slightly
intuitive (since -b is what you use to get a-b = a + -b, then +b would get
a+b = a + +b, ie null operation). And "!" is (maybe) a little too like C's
"not" function for comfort?

And, as I mentioned before, unary "+" (in a localised sense) *is* already a
part of Lua's syntax in the "1e+5" == "1e5" sense. It already has a
precedent!

*cheers*
Peter Hill.