It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"

Vinj Vinj
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"

VJ









Reply | Threaded
Open this post in threaded view
|

RE: It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"

Paul Hudson-2
> Am in the process of embedding python in Lua

Hmm. Why? Just curious - it sounds like one more scripting language than is
needed :)

>I cannot do the following in Lua: "200502" <= a <="200601"

While I can see the convenience, I like the minimal nature of the Lua
syntax, with minimal syntactic sugar - it makes the language very "clean".
So I'd vote against this (not that my vote should count for anything)











Reply | Threaded
Open this post in threaded view
|

Re: It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"

Luiz Henrique de Figueiredo
In reply to this post by Vinj Vinj
> I cannot do the following in Lua: "200502" <= a <="200601"
> I get the following error: cannot concatenate boolean to string.

Are you sure that's the message? I get "attempt to compare string with nil".
--lhf

Reply | Threaded
Open this post in threaded view
|

RE: It would be nice if I could do: "200502" <= a <="200601"instead of "200502" <= a and a <="200601"

Daniel Collins
>> I cannot do the following in Lua: "200502" <= a <="200601"
>> I get the following error: cannot concatenate boolean to string.
> 
> Are you sure that's the message? I get "attempt to compare string with
nil". --lhf

I get that message if a is not defined. If a is defined I get the
"attempt to compare boolean with string". I figure the boolean
expression gets parsed as ("200502" <= a) <= "200601".

- DC


Reply | Threaded
Open this post in threaded view
|

Re: It would be nice if I could do: "200502" <= a <="200601"instead of "200502" <= a and a <="200601"

Vinj Vinj
In reply to this post by Paul Hudson-2

Hmm. Why? Just curious - it sounds like one more scripting language than is
needed :)
Lua allows you to create a true sandbox for user scripts
So I'd vote against this (not that my vote should count for anything)
Most of my users, writing Lua scripts, are not programmers and they will be doing n < b < m quite often. It would be easier for the users if both ways were allowed. It seems Lua is used extensively for embedding, so my reason for allowing both would help most applications where Lua is embedded.

VJ


Reply | Threaded
Open this post in threaded view
|

Re: It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"

Mildred Ki'Lya
In reply to this post by Vinj Vinj
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:[hidden email]> <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]

Reply | Threaded
Open this post in threaded view
|

Re: It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"

Ben Sunshine-Hill
On 5/23/06, Mildred <[hidden email]> wrote:

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)

Well, heck! Why not just use standard mathematical notation?

a in ("200502", "200601"]

(Answer: Because special-case syntax for every little thing makes a
language complicated, ambiguous, and unreadable.)


Reply | Threaded
Open this post in threaded view
|

RE: It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"

Jerome Vuarand-2
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 : [hidden email] [[hidden email]] De la part de Mildred
Envoyé : 23 mai 2006 13:45
À : [hidden email]
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:[hidden email]> <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]


Reply | Threaded
Open this post in threaded view
|

Re: It would be nice if I could do: "200502" <= a <="200601" instead of "200502" <= a and a <="200601"

Taj Khattra
On 5/23/06, Jerome Vuarand <[hidden email]> wrote:
I think the real problem is that x<y<z is using a ternary operator.

depends on how you define the arity of operators...

e.g. the fortress research language from sun labs allows certain
relational operators to be "chained" together, so (x<y<=z) in fortress
means ((x<y) and (y<=z)), where < and <= are still considered binary
relational operators (and y is only evaluated once etc.)

but fortress targets high performance scientific and engineering
applications, so supporting natural mathematical notation is one of
its goals (see http://research.sun.com/projects/plrg )