Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-23 Thread Greg Ewing
Nick Coghlan wrote: > Python, however, uses a dynamic name binding system and scopes are expensive > because they require setting up all of the machinery to support nested > visibility. Scopes within a function needn't be anywhere near as expensive as scopes for nested functions are. The compil

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-23 Thread Nick Coghlan
Andrew Koenig wrote: >>Interestingly enough, not all C++ compilers (Microsoft) hid variables >>created in for loops >>(http://www.devx.com/cplus/10MinuteSolution/28908/0/page/2). > > > That's because the C++ spec changed during standardization, when the > standards committee realized the original

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-23 Thread Andrew Koenig
> Interestingly enough, not all C++ compilers (Microsoft) hid variables > created in for loops > (http://www.devx.com/cplus/10MinuteSolution/28908/0/page/2). That's because the C++ spec changed during standardization, when the standards committee realized the original idea was a mistake. One of t

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-23 Thread Gareth McCaughan
On Thursday 2005-09-22 20:00, Josiah Carlson wrote: [Alexander Myodov:] > > But for the "performance-oriented/human-friendliness" factor, Python > > is anyway not a rival to C and similar lowlevellers. C has > > pseudo-namespaces, though. > > C does not have pseudo-namespaces or variable encapsul

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Guido van Rossum
On 9/22/05, Greg Ewing <[EMAIL PROTECTED]> wrote: > Josiah Carlson wrote: > > > As for list comprehensions, they were literally meant to be a > > completely equivalent translation of a set of for loops. > > I don't think that's quite true. I doubt whether anyone > really thought about the issue whe

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Greg Ewing
Josiah Carlson wrote: > As for list comprehensions, they were literally meant to be a > completely equivalent translation of a set of for loops. I don't think that's quite true. I doubt whether anyone really thought about the issue when LCs were first being discussed. I didn't, but if I had, I wo

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Guido van Rossum
Please end this thread. It belongs in c.l.py. Nothing's going to change. -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: h

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Josiah Carlson
Alexander Myodov <[EMAIL PROTECTED]> wrote: > >> "for (int i = 0; i < 10; i++)" works fine nowadays. > JC> I'm sorry, but you are wrong. The C99 spec states that you must define > JC> the type of i before using it in the loop. Maybe you are thinking of > JC> C++, which allows such things. > "gc

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Alexander Myodov
Hello Josiah, >> i = 0 >> while i != 1: >> i += 1 >> j = 5 >> print j JC> Maybe you don't realize this, but C's while also 'leaks' internal JC> variables... JC> int i = 0, j; JC> while (i != 1) { JC> i++; JC> j = 5; JC> } JC> printf("%i %i\n", i, j); Yeah, it may *leak* it in your

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Josiah Carlson
Alexander Myodov <[EMAIL PROTECTED]> wrote: [snip Alexander Myodov complaining about how Python works] > i = 0 > while i != 1: > i += 1 > j = 5 > print j Maybe you don't realize this, but C's while also 'leaks' internal variables... int i = 0, j; while (i != 1) { i++; j = 5; } p

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Terry Reedy
"Alexander Myodov" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Why the variables defined inside "for"/"while"/"if" statements > (including loop variables for "for") are visible outside this scope? Questions about why Python is the way it is belong on comp.lang.python, the gene

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Gareth McCaughan
Alexander Myodov wrote: > Thus, your example falls to case 1: "i" variable is newly declared for > this loop. Well, we don't reuse old value of i to start the iteration > from a particular place, like below? > > i = 5 > for i in [3,4,5,6,7]: > print i, > > More general, the variables could b

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Alexander Myodov
Hello Josiah, >> Why the variables defined inside "for"/"while"/"if" statements >> (including loop variables for "for") are visible outside this scope? JC> if and while statements don't define variables, so they can't expose JC> them later in the scope. They don't. They just leak internal ones:

Re: [Python-Dev] Visibility scope for "for/while/if" statements

2005-09-22 Thread Josiah Carlson
Alexander Myodov <[EMAIL PROTECTED]> wrote: > Hello, > > Don't want to be importunate annoyingly asking the things probably > trivial for experienced community, but need to ask it anyway, after > spending about two hours trying to find well-camouflaged error caused > by it. In the future yo