[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: A bit of food for thought, hopefully. Was Re: Ambiguous Syntax
- From: "Peter Hill" <corwin@...>
- Date: Wed, 15 Jan 2003 12:48:50 +0800
> 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)
> 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
a = b (-c)
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:
although it could easily be extended to take the other atomic constants
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