Re: [Flashcoders] Variable scope within for loops: reusingiteratorvariables

2008-03-28 Thread Ian Thomas
Oh.

Oh dear. *sigh*

Well, I do confess that there's nostalgic joy at the prospect of being
able to type:

let x=7

(which I don't think I've done since I last used BASIC back in I don't
know when. Around the 1800s, wasn't it?)

But I'm not sure I'd introduce a whole new keyword for it.

I'd probably make var scope work 'as commonly expected' - i.e.
block-level - in ES4 and throw in a compiler switch to turn it off for
backwards compatibility.

But I guess that could be 'as commonly expected - by me'. ;-)

Ian

On Thu, Mar 27, 2008 at 11:51 PM, Francis Cheng <[EMAIL PROTECTED]> wrote:
> Ian, help is on the way, the ECMAScript 4th edition draft specification
>  contains a new keyword, "let", that can be used in place of "var" to
>  provide block-level scoping. Details for the curious:
>
>  http://wiki.ecmascript.org/doku.php?id=proposals:block_expressions
>
>  Francis Cheng | Senior Technical Writer | Adobe Systems, Inc.
>  http://blogs.adobe.com/fcheng
>
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Variable scope within for loops: reusingiteratorvariables

2008-03-27 Thread Francis Cheng
Ian, help is on the way, the ECMAScript 4th edition draft specification
contains a new keyword, "let", that can be used in place of "var" to
provide block-level scoping. Details for the curious:

http://wiki.ecmascript.org/doku.php?id=proposals:block_expressions

Francis Cheng | Senior Technical Writer | Adobe Systems, Inc.
http://blogs.adobe.com/fcheng

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ian
Thomas
Sent: Thursday, March 27, 2008 1:23 PM
To: Flash Coders List
Subject: Re: [Flashcoders] Variable scope within for loops:
reusingiteratorvariables

AFAIK, in AS2 the Flash IDE didn't respect block level scoping, but
MTASC did, which led to some confusion. That leads some people to
think that AS2 as a language has block level scoping.

AS3 definitely doesn't respect block scopes, and I curse every time I
trip over that 'variable declared twice' issue. I wish it did.

Ian

On Thu, Mar 27, 2008 at 8:09 PM, Juan Pablo Califano
<[EMAIL PROTECTED]> wrote:
> for (var i:int = 0; i < 10; i++)
>
> {
>   if (i == 5) break;
>  }
>  trace(i);
>
>  Mmm, have you actually tested the example? Because it does trace 5,
since,
>  as it was explained earlier in this thread, there is no block level
scoping
>  in AS 3.0. In fact, and this was mentioned too, all var declarations
are
>  "moved up" to be executed as the first actions run in a function's
code (I
>  believe that was called hoisting, but I might be wrong).
>
>  Cheers
>  Juan Pablo Califano
>
>  2008/3/27, Steven Sacks <[EMAIL PROTECTED]>:
>
>
> >
>  > function doSomething
>  > > {
>  > >   var i:int;
>  > >   for(i=0;i++;i<10)
>  > >   {
>  > >   }
>  > > }
>  > >
>  > > Is functionally identical to this:
>  > >
>  > > function doSomething
>  > > {
>  > >   for(var i:int =0;i++;i<10)
>  > >   {
>  > >   }
>  > > }
>  >
>  > Wrong.  It's not.
>  >
>  > In the latter example, i is not available after the loop.  In the
first
>  > example, it is.
>  >
>  > var i:int;
>  > for (i = 0; i < 10; i++)
>  > {
>  >   if (i == 5) break;
>  > }
>  > trace(i);
>  > -- 5
>  >
>  > There are a multitude of uses for this, and I do it all the
>  > time.  Additionally, I read somewhere many moons ago (back in my
FLASM days)
>  > that declaring variables outside a for loop is less bytecode and
uses less
>  > memory.  I don't believe that applies to the counter declaration,
but I do
>  > know it applies to the comparison as well as vars declared inside
the for
>  > loop.  However, this level of optimization is only useful in a
practical way
>  > on mobile and some games.
>  >
>  > ___
>  > Flashcoders mailing list
>  > Flashcoders@chattyfig.figleaf.com
>  > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>  >
>  ___
>  Flashcoders mailing list
>  Flashcoders@chattyfig.figleaf.com
>  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Variable scope within for loops: reusingiteratorvariables

2008-03-24 Thread jonathan howe
I totally agree with your explanation, and the part that I am being pouty
about is: "Why isn't the variable's scope confined to the loop?"

a la:

for (var i:int = 0; i < limit; i ++) {  // variable is instantiated
   // scope of variable
} // variable is discarded

instead of it being what several of you have described.

-jonathan

On Mon, Mar 24, 2008 at 4:22 AM, Cor <[EMAIL PROTECTED]> wrote:

> Indeed, I was talking about AS3 too.
>
> For reasoning: Its like the real world -> every object is UNIQUE, therefor
> there can only exist ONE of it.
> You can make copies (instances) but they will have there own unique name.
> You can use it as much as you like but you can't CREATE the same object
> (within its scope) again.
>
> Does this explain it for you?
>
> -Oorspronkelijk bericht-
> Van: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Namens jonathan howe
> Verzonden: maandag 24 maart 2008 9:14
> Aan: Flash Coders List
> Onderwerp: Re: [Flashcoders] Variable scope within for loops:
> reusingiteratorvariables
>
> Hmm... it is within a class... and that's when I'm getting the warnings.
> Or
> did you mean just in general to reiterate that variables are locally
> scoped
> to functions and classes and not to for loops?
>
> I should have mentioned in my subject that this is AS3. So far everyone's
> alternatives and explanations make sense, I am just curious now as to the
> reasoning. Either this is a change from AS2 -> AS3 or since AS2 wasn't as
> strict, it let me do it before. Maybe the explanation lies in the ECMA
> guidelines somewhere. Anyway, thanks for the discussion, gang.
>
> -jonathan
>
>
> On Mon, Mar 24, 2008 at 3:53 AM, Cor <[EMAIL PROTECTED]> wrote:
>
> > Using it youre way is possible when you do it within  a function or
> > class because then they are private by default
> >
> > Other you could use it this way
> > Example 1:
> >
> > for (var i:int = 0; i < someArray.length; i ++) {
> >  // do something cool
> > }
> >
> > for (i = 0; i < someOtherArray.length; i ++) {
> >  // do something even cooler
> > }
> >
> > ---
> > Example 2:
> > var i:int; //or uint if I is never negative
> >
> > for (i = 0; i < someArray.length; i ++) {
> >  // do something cool
> > }
> >
> > for (i = 0; i < someOtherArray.length; i ++) {
> >  // do something even cooler
> > }
> >
> > No virus found in this outgoing message.
> > Checked by AVG.
> > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date:
> > 23-3-2008 18:50
> >
> >
> > ___
> > Flashcoders mailing list
> > Flashcoders@chattyfig.figleaf.com
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
>
>
>
> --
> -jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
>
> --
> No virus found in this incoming message.
> Checked by AVG.
> Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008
> 18:50
>
> No virus found in this incoming message.
> Checked by AVG.
> Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008
> 18:50
>
>
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008
> 18:50
>
>
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 
-jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Variable scope within for loops: reusingiteratorvariables

2008-03-24 Thread Cor
Indeed, I was talking about AS3 too.

For reasoning: Its like the real world -> every object is UNIQUE, therefor
there can only exist ONE of it.
You can make copies (instances) but they will have there own unique name.
You can use it as much as you like but you can't CREATE the same object
(within its scope) again.

Does this explain it for you?

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens jonathan howe
Verzonden: maandag 24 maart 2008 9:14
Aan: Flash Coders List
Onderwerp: Re: [Flashcoders] Variable scope within for loops:
reusingiteratorvariables

Hmm... it is within a class... and that's when I'm getting the warnings. Or
did you mean just in general to reiterate that variables are locally scoped
to functions and classes and not to for loops?

I should have mentioned in my subject that this is AS3. So far everyone's
alternatives and explanations make sense, I am just curious now as to the
reasoning. Either this is a change from AS2 -> AS3 or since AS2 wasn't as
strict, it let me do it before. Maybe the explanation lies in the ECMA
guidelines somewhere. Anyway, thanks for the discussion, gang.

-jonathan


On Mon, Mar 24, 2008 at 3:53 AM, Cor <[EMAIL PROTECTED]> wrote:

> Using it youre way is possible when you do it within  a function or 
> class because then they are private by default
>
> Other you could use it this way
> Example 1:
>
> for (var i:int = 0; i < someArray.length; i ++) {
>  // do something cool
> }
>
> for (i = 0; i < someOtherArray.length; i ++) {
>  // do something even cooler
> }
>
> ---
> Example 2:
> var i:int; //or uint if I is never negative
>
> for (i = 0; i < someArray.length; i ++) {
>  // do something cool
> }
>
> for (i = 0; i < someOtherArray.length; i ++) {
>  // do something even cooler
> }
>
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 
> 23-3-2008 18:50
>
>
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



--
-jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


-- 
No virus found in this incoming message.
Checked by AVG. 
Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008
18:50

No virus found in this incoming message.
Checked by AVG. 
Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008
18:50
 

No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008
18:50
 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders