[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Tue, 23 May 2006 14:42:16 -0400
I think the real problem is that x<y<z is using a ternary operator. If you extend the problem, it is a n-ary operator with alternatives for each part of the operator : mixed < <= and > >= (if w < w <= y < z then end). Lua only support binary operators as most typed imperative languages (the notable exception would be C ternary operator). The typing and the "binarity" of the oprator associativity prevent from chaining binary comparison operators.
To implement that natively I guess it would require a major rewriting of the expression evaluation engine. Binary operators (and to some extent ternary operators with fixed operator symbols) are really easy to parse even with infixed notation. To allow n-ary operators in most languages you have to fall back to prefixed notation (that is function call notation), which is not as eye-candy for non functionnal programmers.
An easier alternative is to use string-embedded arithmetics instead of true number arithmetics. IIRC think that's the way it's done in tcl and sh. Something like eval("x<y<z"). Some syntactic sugar could even remove the need for eval. Reuse of [] characters would be possible I think: if [x<y<z] then end. Note that as you need to extract upvalues from the string you can't do that in pure Lua without debug module (if x is a local value of the caller it's not accessible through getfenv). That method is totally feasible and not very difficult to implement (and with the [] syntactic sugar it would be a nice addition to future versions of Lua).
My 2 cents :-)
-----Message d'origine-----
De : lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] De la part de Mildred
Envoyé : 23 mai 2006 13:45
À : lua@bazar2.conectiva.com.br
Objet : Re: It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"
On Sun, 21 May 2006 12:11:42 -0400 Vineet Jain wrote:
> Am in the process of embedding python in Lua:
>
> I cannot do the following in Lua: "200502" <= a <="200601"
> I get the following error: cannot concatenate boolean to string. So I
> have to type the above as:
>
> "200502" <= a and a <="200601"
Why not something like :
a in "200502", "200601"
The main problen is you can't make the difference between < (less
than) and <= (less or equal)
--
Mildred <xmpp:mildred@jabber.fr> <http://mildred632.free.fr/>
Clef GPG : <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]