Just a little one: Arithmetic Increment/Decrement Operators?

Archive of the older Feature Request Forum Posts

Moderator: POL Developer

Locked
Marilla

Just a little one: Arithmetic Increment/Decrement Operators?

Post by Marilla »

Not a biggie, in all honesty, but it'd be a nice little addition :)
User avatar
taxman
Journeyman Poster
Posts: 63
Joined: Tue Apr 18, 2006 11:10 pm

Post by taxman »

Yeah! Let's use C :)
Marilla

Post by Marilla »

And while I'm at it, compound assignment, too :P
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

far far far far far easier requested than granted, let me tell you..
took me a full morning just to get the >> << bit shift operators in POL.
Marilla

Post by Marilla »

That is what I would have guessed, which is why I was careful to say it's not a big thing.. not at all. What's a few keystrokes here and there, to instead get really useful, cool features?

:)
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

Im just starting to get += to work...
I am testing it with RunECL

I can do

var i := 5;
i+=3;
Print ("->"+i);

and get 8

if I do i += 5+3; I get a compiler error (for now)
but i += (5+3) will work just fine..

Good things.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

Okay got this to all work properly in runecl

Code: Select all


program MathTest()
	var i := 5;
	i += 3+4;
	
	var j := array;
	j[1] := 3;
	j[1] += 5;
	
	Print("->"+i);
	Print("->"+j[1]);
	
	var temp := "Aust";
	temp += "in";
	
	Print("->"+temp);
	
	return 1;
endprogram

So += -= and such could be a very real possibility in 097.
Gimme some other stuff you would throw at it (only += is in right now) to test...!
Marilla

Post by Marilla »

Schweet lookin'...

Only other things I could think of to test out would be:

Code: Select all

program Test(who)
  var s := struct;
  s.+z := 0;
  s.+z_mod := 5;

  s.z += 5;
  s.z += s.z_mod;

  s.z += "what will this do?";
  s.z += who; // this, too, just to know.
  
  who.color += 1;
endprogram
So, just basically making sure it would all work as expected with structs (and dictionaries, of course), and object members, and also to make sure that adding different types of data doesn't throw monkey wrenches into things. :)
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

Okay heres what I tested in the first code block.
The second is the output given.

Code: Select all


program MathTest()
	PlusEqualTests();
	MinusEqualTests();
endprogram

function PlusEqualTests()
	Print("\nPlusEqual Tests()");
	var a := 1;
	a += 2;
	Print("A->"+a);
	
	var b := 1;
	b+= 4+3;
	Print("B->"+b);
	
	var c := array{1};
	c[1] += 3;
	Print("C->"+c);
	
	var d := array{"A"};
	var e := array{"B"};
	d+=e;
	Print("D->"+d);
	
	var f := struct;
	f.+A := 1;
	f.A+=3;
	Print("F.A->"+f.A);
	
	var g := "PO";
	g+="L";
	Print("G->"+g);
	
	var h;
	for ( h:=0; h<=2; h+=1 )
		print("H->"+h);
	endfor
	
	var i := dictionary;
	i["A"] := 1;
	i["A"] += 3;
	Print("i['A']->"+i["A"]);
	
	return 1;
endfunction

function MinusEqualTests()
	Print("\nMinusEqual Tests()");
	var a := 3;
	a -= 2;
	Print("A->"+a);
	
	var b := 4;
	b-= 3-1;
	Print("B->"+b);
	
	var c := array{5};
	c[1] -= 3;
	Print("C->"+c);
	
	var d := array{"A", {"B"}};
	var e := array{"B"};
	d-=e;
	Print("D->"+d);
	
	var f := struct;
	f.+A := 7;
	f.A-=3;
	Print("F.A->"+f.A);
	
	var g := "POLLL";
	g-="LL";
	Print("G->"+g);
	
	var h;
	for ( h:=3; h>=0; h-=1 )
		print("H->"+h);
	endfor
	
	var i := dictionary;
	i["A"] := 4;
	i["A"] -= 3;
	Print("i['A']->"+i["A"]);
	
	return 1;
endfunction

Code: Select all

PlusEqual Tests()
A->3
B->8
C->{ 4 }
D->{ A, { B } }
F.A->4
G->POL
H->0
H->1
H->2
i['A']->4

MinusEqual Tests()
A->1
B->2
C->{ 2 }
D->{ A, { B } }
F.A->4
G->POL
H->3
H->2
H->1
H->0
i['A']->1
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

Okay your wish was granted, we got += -= *= /= and %=
Note: No one ask for i++ ++i i-- --i for a while, thats a whole 'nother story.

Also I went into POL ( I did most my testing in RunECL ) I disabled all the packages except for what was required.. and then did two for loops that started at 0 and counted to 10000

i := i+1 took 30 ms
i += 1 took 20 ms.
Marilla

Post by Marilla »

Well, now; isn't that peachy!

:D
Locked