[Flashcoders] Weird?? increment behavior..

2006-08-13 Thread Bernard Visscher
Hi all,

Just tested a simple function to check if the increments are done correctly.
I found the following a bit od.
Maybe some can shed a light on this..

base code:

//code
function test(myName:String,myNumber:Number):Void
{
trace(myName +  :  + myNumber);
}
var depth:Number = 1;
test('name' + depth, depth++); //traces name2 : 1
depth = 1;
test('name' + depth, ++depth); //traces name2 : 2
depth = 1;
test('name' + depth++, depth); //traces name1 : 1
depth = 1;
test('name' + ++depth, depth); //traces name2 : 1
//end code

I believe only the last 2 have the correct behavior, the first 2 don't.

when I test, test('name' + depth, depth++); I expect a trace like: name1 : 1
when I test, test('name' + depth, ++depth); I expect a trace like: name1 : 2

Is it my mind that's letting me down, or is it really a bug ?

Greetz,

Bernard

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Weird?? increment behavior..

2006-08-13 Thread Mark Winterhalder

test('name' + depth, depth++); //traces name2 : 1


Yes, arguments of functions are pushed on the VM's stack in reverse
order, right-to-left. It's counterintuitive, something you just have
to come across once to notice, a nice bit of ActionScript trivia :)

Mark


On 8/13/06, Bernard Visscher [EMAIL PROTECTED] wrote:

Hi all,

Just tested a simple function to check if the increments are done correctly.
I found the following a bit od.
Maybe some can shed a light on this..

base code:

//code
function test(myName:String,myNumber:Number):Void
{
trace(myName +  :  + myNumber);
}
var depth:Number = 1;
test('name' + depth, depth++); //traces name2 : 1
depth = 1;
test('name' + depth, ++depth); //traces name2 : 2
depth = 1;
test('name' + depth++, depth); //traces name1 : 1
depth = 1;
test('name' + ++depth, depth); //traces name2 : 1
//end code

I believe only the last 2 have the correct behavior, the first 2 don't.

when I test, test('name' + depth, depth++); I expect a trace like: name1 : 1
when I test, test('name' + depth, ++depth); I expect a trace like: name1 : 2

Is it my mind that's letting me down, or is it really a bug ?

Greetz,

Bernard

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Weird?? increment behavior..

2006-08-13 Thread Bernard Visscher
Thanks Mark!
Didn't know that :) 

 -Oorspronkelijk bericht-
 Van: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] Namens 
 Mark Winterhalder
 Verzonden: maandag 14 augustus 2006 0:03
 Aan: Flashcoders mailing list
 Onderwerp: Re: [Flashcoders] Weird?? increment behavior..
 
  test('name' + depth, depth++); //traces name2 : 1
 
 Yes, arguments of functions are pushed on the VM's stack in 
 reverse order, right-to-left. It's counterintuitive, 
 something you just have to come across once to notice, a nice 
 bit of ActionScript trivia :)
 
 Mark
 
 
 On 8/13/06, Bernard Visscher [EMAIL PROTECTED] wrote:
  Hi all,
 
  Just tested a simple function to check if the increments 
 are done correctly.
  I found the following a bit od.
  Maybe some can shed a light on this..
 
  base code:
 
  //code
  function test(myName:String,myNumber:Number):Void
  {
  trace(myName +  :  + myNumber); } var depth:Number = 1; 
  test('name' + depth, depth++); //traces name2 : 1 depth = 1; 
  test('name' + depth, ++depth); //traces name2 : 2 depth = 1; 
  test('name' + depth++, depth); //traces name1 : 1 depth = 1; 
  test('name' + ++depth, depth); //traces name2 : 1 //end code
 
  I believe only the last 2 have the correct behavior, the 
 first 2 don't.
 
  when I test, test('name' + depth, depth++); I expect a trace like: 
  name1 : 1 when I test, test('name' + depth, ++depth); I 
 expect a trace 
  like: name1 : 2
 
  Is it my mind that's letting me down, or is it really a bug ?
 
  Greetz,
 
  Bernard
 
  ___
  Flashcoders@chattyfig.figleaf.com
  To change your subscription options or search the archive:
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
  Brought to you by Fig Leaf Software
  Premier Authorized Adobe Consulting and Training 
  http://www.figleaf.com http://training.figleaf.com
 
 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training 
 http://www.figleaf.com http://training.figleaf.com
 

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com