[issue12635] use as for block scope support

2011-07-25 Thread HaiYun Yan
New submission from HaiYun Yan lyricco...@gmail.com: use as for block scope support just like mozilla javascript let extension https://developer.mozilla.org/en/new_in_javascript_1.7#Block_scope_with_let_%28Merge_into_let_Statement%29 usage: as_clause(as_declare): as NAME as_stmt: NAME as test

[issue12635] use as for block scope support

2011-07-25 Thread Ezio Melotti
Ezio Melotti ezio.melo...@gmail.com added the comment: You should propose this to the python-ideas mailing list first. It might be worth checking the archives of the ML as well -- I think I saw already something similar a while ago. -- nosy: +ezio.melotti resolution: - rejected stage:

Re: block scope?

2007-04-10 Thread Bruno Desthuilliers
Paul Rubin a écrit : [EMAIL PROTECTED] (Alex Martelli) writes: locals['x']=5 Traceback (most recent call last): File stdin, line 1, in module TypeError: 'builtin_function_or_method' object does not support item assignment Whoops, yeah, meant locals()['x'] = 5. I think that ideally

Re: block scope?

2007-04-08 Thread Alexander Schmolck
Neal Becker [EMAIL PROTECTED] writes: One thing I sometimes miss, which is common in some other languages (c++), is idea of block scope. It would be useful to have variables that did not outlive their block, primarily to avoid name clashes. This also leads to more readable code. I have

Re: block scope?

2007-04-08 Thread Paddy
On Apr 7, 4:48 am, James Stroud [EMAIL PROTECTED] wrote: Neal Becker wrote: One thing I sometimes miss, which is common in some other languages (c++), is idea of block scope. It would be useful to have variables that did not outlive their block, primarily to avoid name clashes. This also

Re: block scope?

2007-04-08 Thread Georg Brandl
Alex Martelli schrieb: Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Alex Martelli) writes: exec? option 1: that just runs the compiler a bit later ... Besides exec, there's also locals(), i.e. locals['x'] = 5 can shadow a variable. Any bad results are probably

Re: block scope?

2007-04-07 Thread James Stroud
. I think Perl did this pretty good. If you say my $i that declares $i to have block scope, and it's considered good practice to do this, but it's not required. You can say for (my $i=0; $i 5; $i++) { ... } and that gives $i the same scope as the for loop. Come to think of it you can do

Re: block scope?

2007-04-07 Thread Neal Becker
not. That works adequately. I think Perl did this pretty good. If you say my $i that declares $i to have block scope, and it's considered good practice to do this, but it's not required. You can say for (my $i=0; $i 5; $i++) { ... } and that gives $i the same scope as the for loop. Come

Re: block scope?

2007-04-07 Thread irstas
On Apr 7, 6:48 am, James Stroud [EMAIL PROTECTED] wrote: Neal Becker wrote: One thing I sometimes miss, which is common in some other languages (c++), is idea of block scope. It would be useful to have variables that did not outlive their block, primarily to avoid name clashes. This also

Re: block scope?

2007-04-07 Thread Alex Martelli
Neal Becker [EMAIL PROTECTED] wrote: ... i = 5 for my i in xrange(4): if i: # skips first when i is 0 my i = 100 if i: print i # of course 100 break print i # i is between 0 3 here print i # i is 5 here

Re: block scope?

2007-04-07 Thread Steve Holden
Alex Martelli wrote: Neal Becker [EMAIL PROTECTED] wrote: ... i = 5 for my i in xrange(4): if i: # skips first when i is 0 my i = 100 if i: print i # of course 100 break print i # i is between 0 3 here print i # i

Re: block scope?

2007-04-07 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes: Thus the following example does not compile: class Test { public static void main(String[] args) { int i; for (int i = 0; i 10; i++) I'm ok with this; at the minimum, I think such nesting should produce a

Re: block scope?

2007-04-07 Thread Alex Martelli
Steve Holden [EMAIL PROTECTED] wrote: What do you think the chances are of this being accepted for Python 3.0? It is indeed about the most rational approach, though of course it does cause problems with dynamic namespaces. What problems do you have in mind? The compiler already determines

Re: block scope?

2007-04-07 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Alex Martelli) writes: Thus the following example does not compile: class Test { public static void main(String[] args) { int i; for (int i = 0; i 10; i++) I'm ok with this; at the

Re: block scope?

2007-04-07 Thread Aahz
In article [EMAIL PROTECTED], Alex Martelli [EMAIL PROTECTED] wrote: Steve Holden [EMAIL PROTECTED] wrote: What do you think the chances are of this being accepted for Python 3.0? It is indeed about the most rational approach, though of course it does cause problems with dynamic namespaces.

Re: block scope?

2007-04-07 Thread John Nagle
. I think Perl did this pretty good. If you say my $i that declares $i to have block scope, and it's considered good practice to do this, but it's not required. You can say for (my $i=0; $i 5; $i++) { ... } and that gives $i the same scope as the for loop. Come to think of it you can do

Re: block scope?

2007-04-07 Thread Alex Martelli
Aahz [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Alex Martelli [EMAIL PROTECTED] wrote: Steve Holden [EMAIL PROTECTED] wrote: What do you think the chances are of this being accepted for Python 3.0? It is indeed about the most rational approach, though of course it does

Re: block scope?

2007-04-07 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes: exec? option 1: that just runs the compiler a bit later ... Besides exec, there's also locals(), i.e. locals['x'] = 5 can shadow a variable. Any bad results are probably deserved ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: block scope?

2007-04-07 Thread MRAB
and classes have a scope, but if and for do not. That works adequately. I think Perl did this pretty good. If you say my $i that declares $i to have block scope, and it's considered good practice to do this, but it's not required. You can say for (my $i=0; $i 5; $i++) { ... } and that gives $i

Re: block scope?

2007-04-07 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Alex Martelli) writes: exec? option 1: that just runs the compiler a bit later ... Besides exec, there's also locals(), i.e. locals['x'] = 5 can shadow a variable. Any bad results are probably deserved ;) locals['x']=5

Re: block scope?

2007-04-07 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes: locals['x']=5 Traceback (most recent call last): File stdin, line 1, in module TypeError: 'builtin_function_or_method' object does not support item assignment Whoops, yeah, meant locals()['x'] = 5. I think that ideally there should be a runtime

Re: block scope?

2007-04-07 Thread John Nagle
Paul Rubin wrote: [EMAIL PROTECTED] (Alex Martelli) writes: I have no opinion of this, locals() has always seemed like a crazy part of the language to me and I never use it. I'd be happy to see it gone since it makes compiling a lot easier. I think of that, from a compiler perspective,

block scope?

2007-04-06 Thread Neal Becker
One thing I sometimes miss, which is common in some other languages (c++), is idea of block scope. It would be useful to have variables that did not outlive their block, primarily to avoid name clashes. This also leads to more readable code. I wonder if this has been discussed? -- http

Re: block scope?

2007-04-06 Thread Steve Holden
Neal Becker wrote: One thing I sometimes miss, which is common in some other languages (c++), is idea of block scope. It would be useful to have variables that did not outlive their block, primarily to avoid name clashes. This also leads to more readable code. I wonder if this has been

Re: block scope?

2007-04-06 Thread Chris Mellon
On 4/6/07, Neal Becker [EMAIL PROTECTED] wrote: One thing I sometimes miss, which is common in some other languages (c++), is idea of block scope. It would be useful to have variables that did not outlive their block, primarily to avoid name clashes. This also leads to more readable code. I

Re: block scope?

2007-04-06 Thread Terry Reedy
Neal Becker [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | One thing I sometimes miss, which is common in some other languages (c++), | is idea of block scope. It would be useful to have variables that did not | outlive their block, primarily to avoid name clashes. This also

Re: block scope?

2007-04-06 Thread James Stroud
Neal Becker wrote: One thing I sometimes miss, which is common in some other languages (c++), is idea of block scope. It would be useful to have variables that did not outlive their block, primarily to avoid name clashes. This also leads to more readable code. I wonder if this has been

Re: block scope?

2007-04-06 Thread Paul Rubin
James Stroud [EMAIL PROTECTED] writes: Probably, with good code, block scope would be overkill, except that I would welcome list comprehensions to have a new scope: Block scope is a win because it gets rid of the uncertainty of whether the variable is used outside the block or not. The good

Re: block scope?

2007-04-06 Thread John Nagle
Paul Rubin wrote: James Stroud [EMAIL PROTECTED] writes: Probably, with good code, block scope would be overkill, except that I would welcome list comprehensions to have a new scope: Block scope is a win because it gets rid of the uncertainty of whether the variable is used outside

Re: block scope?

2007-04-06 Thread Paul Rubin
this pretty good. If you say my $i that declares $i to have block scope, and it's considered good practice to do this, but it's not required. You can say for (my $i=0; $i 5; $i++) { ... } and that gives $i the same scope as the for loop. Come to think of it you can do something similar in C