More operators?

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

More operators?

Staffan Hellström
Hello,

I have a question: How can I implement "arithmetic-assignment
operators"(not sure on the exact term) like += and /= ?
For clarification, a+=b is the same as a=a+b. However I've some users which
want to be able to do += directly.

I've looked at the source, and the biggest obstacle I can see(I think) is
how to determine whether to use setglobal, setlocal, or settable for the
assignment.

Maybe anybody already has an implementation of this or knows how to do it?


Staffan Hellström

Reply | Threaded
Open this post in threaded view
|

Re: More operators?

Nick Trout-2
 
----- Original Message -----
Sent: Sunday, February 04, 2001 4:56 PM
Subject: More operators?

Hello,

I have a question: How can I implement "arithmetic-assignment
operators"(not sure on the exact term) like += and /= ?
For clarification, a+=b is the same as a=a+b. However I've some users which
want to be able to do += directly.
This is not a bad idea. Python has just added (i think they are called) augmented operators eg. +=, -=, in v2.0 after prolonged argument.
 
I believe x += 1 would be faster for Lua than x = x+1, this is one of the reasons for adding it in Python besides convenience. ie. none mutable value becomes mutable in this case.

I've looked at the source, and the biggest obstacle I can see(I think) is
how to determine whether to use setglobal, setlocal, or settable for the
assignment.
Reply | Threaded
Open this post in threaded view
|

Re: More operators?

Cary O'Brien
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> 
>   ----- Original Message ----- 
>   From: Staffan Hellstr_m 
>   To: Multiple recipients of list 
>   Sent: Sunday, February 04, 2001 4:56 PM
>   Subject: More operators?
> 
> 
>   Hello,
> 
>   I have a question: How can I implement "arithmetic-assignment
>   operators"(not sure on the exact term) like += and /= ?
>   For clarification, a+=b is the same as a=a+b. However I've some users which
>   want to be able to do += directly.
> 

I kind of miss % for modulus.  Ie.  11 % 5 = 1.  Does this conflict with the
upuvar symbol in the lexer?

-- cary

> This is not a bad idea. Python has just added (i think they are called) augmented operators eg. +=, -=, in v2.0 after prolonged argument. 
> 
> I believe x += 1 would be faster for Lua than x = x+1, this is one of the reasons for adding it in Python besides convenience. ie. none mutable value becomes mutable in this case.
> 
>   I've looked at the source, and the biggest obstacle I can see(I think) is
>   how to determine whether to use setglobal, setlocal, or settable for the
>   assignment.
> 


Reply | Threaded
Open this post in threaded view
|

Re: More operators?

Luiz Henrique de Figueiredo
In reply to this post by Staffan Hellström
>I kind of miss % for modulus.  Ie.  11 % 5 = 1.  Does this conflict with the
>upuvar symbol in the lexer?

Yes, it does confict (but that is not the reason there is no such operator).
Use mod() instead.
--lhf