Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-04 Thread Albert-Jan Roskam
t: Tuesday, October 4, 2016 7:00:48 AM To: python-list@python.org Subject: Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior) On Tuesday 04 October 2016 14:51, Michael Torrie wrote: > On 10/03/2016 08:21 PM, Steve D'Aprano wrote: >> On Tue, 4 Oct 2016

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-04 Thread Steven D'Aprano
On Tuesday 04 October 2016 14:51, Michael Torrie wrote: > On 10/03/2016 08:21 PM, Steve D'Aprano wrote: >> On Tue, 4 Oct 2016 05:48 am, Michael Torrie wrote: >> >>> There is that old, but false, saying that the only intuitive interface >>> is the nipple. Turns out everything, even that, is learn

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread Gregory Ewing
On Mon, 3 Oct 2016 10:57:27 -0700 (PDT), sohcahto...@gmail.com declaimed the following: > My car is similar, but the R is actually to the left of 1. It looks like this: R 1 3 5 +-+-+-+ 2 4 6 Mine is actually like that too, but it feels like you're doing the same thing in both cases -- push l

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread Michael Torrie
On 10/03/2016 08:21 PM, Steve D'Aprano wrote: > On Tue, 4 Oct 2016 05:48 am, Michael Torrie wrote: > >> There is that old, but false, saying that the only intuitive interface >> is the nipple. Turns out everything, even that, is learned > > Citation required. Sure, just ask a nursing woman. >

Re: Assignment versus binding [was Re: unintuitive for-loop behavior]

2016-10-03 Thread Rustom Mody
On Tuesday, October 4, 2016 at 8:11:41 AM UTC+5:30, Steve D'Aprano wrote: > On Mon, 3 Oct 2016 04:15 pm, Jussi Piitulainen wrote: > > > Steve D'Aprano writes: > >> Why shouldn't people say that binding and assignment are the same > >> thing in Python? What's the difference? > > > > Outside Python

Assignment versus binding [was Re: unintuitive for-loop behavior]

2016-10-03 Thread Steve D'Aprano
On Mon, 3 Oct 2016 04:15 pm, Jussi Piitulainen wrote: > Steve D'Aprano writes: >> Why shouldn't people say that binding and assignment are the same >> thing in Python? What's the difference? > > Outside Python, (lambda x : f(x)) is said to "bind" x. It's different > from assigning a new value to

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread Steve D'Aprano
On Tue, 4 Oct 2016 05:48 am, Michael Torrie wrote: > There is that old, but false, saying that the only intuitive interface > is the nipple.  Turns out everything, even that, is learned Citation required. Of course many things are intuitive/instinctive, e.g. breathing, but as far as *interfaces*

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread Gregory Ewing
BartC wrote: On 03/10/2016 12:53, Marko Rauhamaa wrote: Well, it could be worse. This layout is pretty traditional: 1 3 5 | | | +--+--+ | | | 2 4 R Yes, you get a funny grinding sound when attempting to change from 5th to '6th' at 70mph/110kph. Fortunately it doe

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread Michael Torrie
On 10/03/2016 11:57 AM, sohcahto...@gmail.com wrote: > Surprisingly, despite driving that previous car for 13 years, the switch was > incredibly easy. I've never accidentally gone to sixth gear instead of > reverse, or forgotten to shift into sixth on the highway. Also, accidentally > going in

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread Michael Torrie
On 10/03/2016 03:10 AM, Gregory Ewing wrote: > Rustom Mody wrote: >> My new car goes in reverse when I put it in first gear but only on full-moon >> nights with the tank on reserve when the left light is blinking > > OT aside: When I went to take my current car (a manual) > for a test drive, I ha

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread sohcahtoa82
On Monday, October 3, 2016 at 2:11:12 AM UTC-7, Gregory Ewing wrote: > Rustom Mody wrote: > > My new car goes in reverse when I put it in first gear but only on > > full-moon > > nights with the tank on reserve when the left light is blinking > > OT aside: When I went to take my current car (a m

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread breamoreboy
On Monday, October 3, 2016 at 5:41:23 PM UTC+1, BartC wrote: > On 03/10/2016 16:03, wrote: > > On Monday, October 3, 2016 at 12:53:55 PM UTC+1, Marko Rauhamaa wrote: > >> Gregory Ewing: > >> > >>> Turns out the only difference between first and reverse on that model > >>> is whether you lift up a l

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread BartC
On 03/10/2016 16:03, breamore...@gmail.com wrote: On Monday, October 3, 2016 at 12:53:55 PM UTC+1, Marko Rauhamaa wrote: Gregory Ewing: Turns out the only difference between first and reverse on that model is whether you lift up a little ring on the shaft of the gear lever prior to engagement.

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread breamoreboy
On Monday, October 3, 2016 at 12:53:55 PM UTC+1, Marko Rauhamaa wrote: > Gregory Ewing: > > > Turns out the only difference between first and reverse on that model > > is whether you lift up a little ring on the shaft of the gear lever > > prior to engagement. > > > > Who came up with *that* brill

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread BartC
On 03/10/2016 12:53, Marko Rauhamaa wrote: Gregory Ewing : Turns out the only difference between first and reverse on that model is whether you lift up a little ring on the shaft of the gear lever prior to engagement. Who came up with *that* brilliant piece of user interface design I don't kno

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread alister
On Mon, 03 Oct 2016 22:10:52 +1300, Gregory Ewing wrote: > Rustom Mody wrote: >> My new car goes in reverse when I put it in first gear but only on >> full-moon nights with the tank on reserve when the left light is >> blinking > > OT aside: When I went to take my current car (a manual) for a tes

Re: Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread Marko Rauhamaa
Gregory Ewing : > Turns out the only difference between first and reverse on that model > is whether you lift up a little ring on the shaft of the gear lever > prior to engagement. > > Who came up with *that* brilliant piece of user interface design I > don't know. It seems specifically designed t

Is that forwards first or backwards first? (Re: unintuitive for-loop behavior)

2016-10-03 Thread Gregory Ewing
Rustom Mody wrote: My new car goes in reverse when I put it in first gear but only on full-moon nights with the tank on reserve when the left light is blinking OT aside: When I went to take my current car (a manual) for a test drive, I had to stop and ask the dealer how to put it into reverse.

Re: unintuitive for-loop behavior

2016-10-03 Thread Gregory Ewing
Steve D'Aprano wrote: x = str = 1 assert x == 1 and str == 1 del x, str assert str # succeeds assert x # NameError x = str = 2 # create new bindings, or update existing ones? Is it our conclusion that therefore Python creates a new binding for str but not for x? Or that the evidence for x is

Re: unintuitive for-loop behavior

2016-10-03 Thread Jussi Piitulainen
Antoon Pardon writes: > Op 02-10-16 om 07:59 schreef Rustom Mody: >> >> You are explaining the mechanism behind the bug. Thanks. The bug >> remains. My new car goes in reverse when I put it in first gear but >> only on full-moon nights with the tank on reserve when the left light >> is blinking T

Re: unintuitive for-loop behavior

2016-10-03 Thread Antoon Pardon
Op 02-10-16 om 07:59 schreef Rustom Mody: > > You are explaining the mechanism behind the bug. Thanks. The bug remains. > My new car goes in reverse when I put it in first gear but only on full-moon > nights with the tank on reserve when the left light is blinking > The engineer explains the inter

Re: unintuitive for-loop behavior

2016-10-03 Thread Gregory Ewing
Chris Angelico wrote: The only way to prove that something is a new binding is to demonstrate that, when this binding is removed, a previous one becomes visible. Or capture them both with closures and show that each closure sees a different version of the binding. -- Greg -- https://mail.pytho

Re: unintuitive for-loop behavior

2016-10-03 Thread Gregory Ewing
Steve D'Aprano wrote: No it doesn't mean that at all. The result you see is compatible with *both* the "update existing slot" behaviour and "create a new slot" behavior. We're getting sidetracked talking about slots here. It's not really relevant. The point is that there is only *one* binding f

Re: unintuitive for-loop behavior

2016-10-02 Thread Jussi Piitulainen
Steve D'Aprano writes: > On Sun, 2 Oct 2016 05:35 pm, Jussi Piitulainen wrote: > > [...] >>> I'm sorry, I don't understand what you mean by "Python semantics" versus >>> "a translation". A translation of what? In what way is it "magical >>> semantics"? I see nothing magical in your code: it is Pyt

Re: Locals [was Re: unintuitive for-loop behavior]

2016-10-02 Thread Chris Angelico
On Mon, Oct 3, 2016 at 3:09 PM, Steven D'Aprano wrote: > But if it did, then just as in the similar situation in IronPython and Jython, > you would still need to convince the compiler to use LOAD_FAST or equivalent > in > order to see it. Hence: > > > x = y = 'global' > def example(): > local

Locals [was Re: unintuitive for-loop behavior]

2016-10-02 Thread Steven D'Aprano
On Monday 03 October 2016 12:42, Steve D'Aprano wrote: > Yes the local would have been created, but you wouldn't see it from an > ordinary lookup of name x. You would need to use > > locals()['x'] > > to see that it exists. For x to return it, you have to convince the compiler > to use LOAD_

Re: unintuitive for-loop behavior

2016-10-02 Thread Steve D'Aprano
On Sun, 2 Oct 2016 05:35 pm, Jussi Piitulainen wrote: [...] >> I'm sorry, I don't understand what you mean by "Python semantics" versus >> "a translation". A translation of what? In what way is it "magical >> semantics"? I see nothing magical in your code: it is Python code. > > "Python semantics

Re: unintuitive for-loop behavior

2016-10-02 Thread Steve D'Aprano
On Sun, 2 Oct 2016 09:41 pm, Chris Angelico wrote: > The only way to prove that something is a new binding is to > demonstrate that, when this binding is removed, a previous one becomes > visible. In Python, that only ever happens across namespaces, and in > CPython, the only way I can make it ha

Re: unintuitive for-loop behavior

2016-10-02 Thread Chris Angelico
On Sun, Oct 2, 2016 at 9:20 PM, Steve D'Aprano wrote: > On Sun, 2 Oct 2016 04:06 pm, Chris Angelico wrote: >> Hmm, interesting. I don't have IronPython here, but maybe you can tell >> me what this does: >> >> print(str) >> str = "demo" >> print(str) >> del str >> print(str) >> >> and the same insi

Re: unintuitive for-loop behavior

2016-10-02 Thread Steve D'Aprano
On Sun, 2 Oct 2016 04:06 pm, Chris Angelico wrote: > On Sun, Oct 2, 2016 at 3:19 PM, Steve D'Aprano > wrote: >> In IronPython, you could have the following occur in a function locals, >> just as it could happen CPython for globals: >> >> - delete the name binding "x" >> - which triggers a diction

Re: unintuitive for-loop behavior

2016-10-02 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen wrote: >> I could have just posted that yes, it *could* be done, there's >> nothing so special about variables and scope in Python. But I pretty >> much know that the response to *that* would have been yet another >> round of "You don't understand that Py

Re: unintuitive for-loop behavior

2016-10-02 Thread Jussi Piitulainen
Steve D'Aprano writes: > On Sun, 2 Oct 2016 11:44 am, Gregory Ewing wrote: > >> Steve D'Aprano wrote: >> >>> Certainly when you call a function, the local bindings need to be >>> created. Obviously they didn't exist prior to calling the function! >>> I didn't think that was the difference you were

Re: unintuitive for-loop behavior

2016-10-02 Thread Marko Rauhamaa
Jussi Piitulainen : > I could have just posted that yes, it *could* be done, there's nothing > so special about variables and scope in Python. But I pretty much know > that the response to *that* would have been yet another round of "You > don't understand that Python variables are different, they

Re: unintuitive for-loop behavior

2016-10-01 Thread Jussi Piitulainen
Steve D'Aprano writes: > On Sun, 2 Oct 2016 12:28 am, Jussi Piitulainen wrote: > >> I'm not sure any more to what message this should be a followup, but >> here is a demonstration of two different semantics of the for-loop >> variable scope/update, this time with nested loops using the same >> loo

Re: unintuitive for-loop behavior

2016-10-01 Thread Rustom Mody
On Saturday, October 1, 2016 at 11:35:31 PM UTC+5:30, Steve D'Aprano wrote: > On Sun, 2 Oct 2016 03:57 am, Rustom Mody wrote: > > > Hoo boy1 > > Thats some tour de force and makes my head spin > > I certainly agree with the second part of your sentence. > > > > Point can be made more simply wit

Re: unintuitive for-loop behavior

2016-10-01 Thread Chris Angelico
On Sun, Oct 2, 2016 at 3:19 PM, Steve D'Aprano wrote: > In IronPython, you could have the following occur in a function locals, just > as it could happen CPython for globals: > > - delete the name binding "x" > - which triggers a dictionary resize > - bind a value to x again > - because the dictio

Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 11:44 am, Gregory Ewing wrote: > Steve D'Aprano wrote: >> When you say: >> >> x = 0 >> x = 1 >> >> inside a function, and the interpreter does the name binding twice, >> there's no way of telling whether it writes to the same cell each time or >> not. > > Yes, there i

Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 12:28 am, Jussi Piitulainen wrote: > I'm not sure any more to what message this should be a followup, but > here is a demonstration of two different semantics of the for-loop > variable scope/update, this time with nested loops using the same loop > variable name. The first func

Re: unintuitive for-loop behavior

2016-10-01 Thread Gregory Ewing
Steve D'Aprano wrote: When you say: x = 0 x = 1 inside a function, and the interpreter does the name binding twice, there's no way of telling whether it writes to the same cell each time or not. Yes, there is: ... x = 0 ... f1 = lambda: x ... x = 1 ... f2 = lambda: x ... print(f

Re: unintuitive for-loop behavior

2016-10-01 Thread Terry Reedy
On 10/1/2016 8:24 AM, Rustom Mody wrote: Yeah by comprehension-variable I mean the one that sits left of the ‘in’ inside the conprehension. In other words, a 'loop variable within a comprehension'. Keep in mind that there may be multiple targets for the implicit (hidden) assignment, so ther

Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 03:57 am, Rustom Mody wrote: > Hoo boy1 > Thats some tour de force and makes my head spin I certainly agree with the second part of your sentence. > Point can be made more simply with map > ie if we *define* > [exp for cv in l] > as > map(lambda cv: exp, l) > > the problem v

Re: unintuitive for-loop behavior

2016-10-01 Thread Rustom Mody
On Saturday, October 1, 2016 at 7:02:58 PM UTC+5:30, Jussi Piitulainen wrote: > Rustom Mody writes: > > > And then define comprehensions not as now done in terms of for loops > > that mutatingly extend the list being built up but as recursive > > functions that get (re)called for every new value o

Re: unintuitive for-loop behavior

2016-10-01 Thread Jussi Piitulainen
I'm not sure any more to what message this should be a followup, but here is a demonstration of two different semantics of the for-loop variable scope/update, this time with nested loops using the same loop variable name. The first function, tabulate, uses Python semantics ("t" for true, if you lik

Re: unintuitive for-loop behavior

2016-10-01 Thread Jussi Piitulainen
Rustom Mody writes: > And then define comprehensions not as now done in terms of for loops > that mutatingly extend the list being built up but as recursive > functions that get (re)called for every new value of the comprehension > variable passed and therefore fresh-bound as parameter You'd get

Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
than accessing uninitialised memory, as a naive implementation might have done. In any case, I think this is going off on a rather wide tangent -- how is this specifically relevant to the "unintuitive for-loop behavior" the OP was surprised by? > When I said "creating a new bi

Re: unintuitive for-loop behavior

2016-10-01 Thread Rustom Mody
On Saturday, October 1, 2016 at 5:02:30 PM UTC+5:30, Steve D'Aprano wrote: > On Sat, 1 Oct 2016 01:44 pm, Rustom Mody wrote: > > > Yes one basic problem with comprehensions in python is that they are > > defined by assignment not binding to the comprehension variable > > ¿Que Mr Fawlty? > > I'm

Re: unintuitive for-loop behavior

2016-10-01 Thread Gregory Ewing
Steve D'Aprano wrote: # create a new binding x: address 1234 > [ box contains 999 ] x: address 5678 > [ a different box, containing 888 ] In the context of CPython and nested functions, replace "box" with "cell". When I said "creating a new binding" I meant that the name x refers to

Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
On Sat, 1 Oct 2016 01:44 pm, Rustom Mody wrote: > Yes one basic problem with comprehensions in python is that they are > defined by assignment not binding to the comprehension variable ¿Que Mr Fawlty? I'm sorry, I don't understand you. In Python, all assignments are name bindings. So you seem t

Re: unintuitive for-loop behavior

2016-10-01 Thread Gregory Ewing
Random832 wrote: > for a in collection: > b = some_calculation_of(a) > final b: do_something_with(lambda: ... b ...) I would prefer something like for a in collection: let b = some_calculation_of(a): do_something_with(lambda: ... b ...) -- Greg -- https://mail.python.org/ma

Re: unintuitive for-loop behavior

2016-10-01 Thread Chris Angelico
On Sat, Oct 1, 2016 at 6:35 PM, Steve D'Aprano wrote: > On Sat, 1 Oct 2016 02:39 am, Chris Angelico wrote: > >> On Sat, Oct 1, 2016 at 12:36 AM, Grant Edwards >> wrote: > >>> In C99 a for loop has its own namespac: > [...] > >> I believe that's the same semantics as C++ uses, and I agree, it's >>

Re: unintuitive for-loop behavior

2016-10-01 Thread Jussi Piitulainen
Steve D'Aprano writes: > In a language like Python, the only distinction we can make between > name bindings is, which namespace is the binding in? In other words, > what is the current block of code's scope? Python already has nested scopes. A local scope for just those variables introduced in f

Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
On Sat, 1 Oct 2016 02:39 am, Chris Angelico wrote: > On Sat, Oct 1, 2016 at 12:36 AM, Grant Edwards > wrote: >> In C99 a for loop has its own namespac: [...] > I believe that's the same semantics as C++ uses, and I agree, it's > very convenient. Among other things, it means that nested loops be

Re: unintuitive for-loop behavior

2016-10-01 Thread Chris Angelico
On Sat, Oct 1, 2016 at 5:06 PM, Steve D'Aprano wrote: > Earlier, I wrote: > >> On Sat, 1 Oct 2016 10:46 am, Gregory Ewing wrote: > [...] >>> Whenever there's binding going on, it's necessary to decide >>> whether it should be creating a new binding or updating an >>> existing one. >> >> Right. > >

Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
Earlier, I wrote: > On Sat, 1 Oct 2016 10:46 am, Gregory Ewing wrote: [...] >> Whenever there's binding going on, it's necessary to decide >> whether it should be creating a new binding or updating an >> existing one. > > Right. I changed my mind -- I don't think that's correct. I think Greg's

Re: unintuitive for-loop behavior

2016-09-30 Thread Rustom Mody
On Saturday, October 1, 2016 at 8:55:19 AM UTC+5:30, Random832 wrote: > On Fri, Sep 30, 2016, at 20:46, Gregory Ewing wrote: > > What *is* necessary and sufficient is to make each iteration > > of the for-loop create a new binding of the loop variable > > (and not any other variable!). > > I don't

Re: unintuitive for-loop behavior

2016-09-30 Thread Steve D'Aprano
On Sat, 1 Oct 2016 10:46 am, Gregory Ewing wrote: > Steve D'Aprano wrote: >> Giving for-loops their own namespace is a grossly unintuitive and a very >> weird thing to do. >> >> It would be terribly inconvenient and surprising for if...else blocks to >> be separate namespaces: > > There's an imp

Re: unintuitive for-loop behavior

2016-09-30 Thread Rustom Mody
For the most part you've taken the words out of my mouth! Some more details... On Saturday, October 1, 2016 at 6:16:32 AM UTC+5:30, Gregory Ewing wrote: > Steve D'Aprano wrote: > > Giving for-loops their own namespace is a grossly unintuitive and a very > > weird thing to do. > > > > It would be

Re: unintuitive for-loop behavior

2016-09-30 Thread Random832
On Fri, Sep 30, 2016, at 20:46, Gregory Ewing wrote: > What *is* necessary and sufficient is to make each iteration > of the for-loop create a new binding of the loop variable > (and not any other variable!). I don't think that's true. I think this is logic that is excessively tied to the toy exam

Re: unintuitive for-loop behavior

2016-09-30 Thread Gregory Ewing
Steve D'Aprano wrote: What happens if it is *not* a misfeature? Gotchas are not always misfeatures -- sometimes gotchas are gotchas because people's expectations are simply wrong, and pandering to their confused expectations does not actually help them. I haven't made up my mind about *this* spe

Re: unintuitive for-loop behavior

2016-09-30 Thread Gregory Ewing
Steve D'Aprano wrote: Giving for-loops their own namespace is a grossly unintuitive and a very weird thing to do. It would be terribly inconvenient and surprising for if...else blocks to be separate namespaces: There's an important difference between a for-loop and an if-statement that's relev

Re: unintuitive for-loop behavior

2016-09-30 Thread Steve D'Aprano
On Fri, 30 Sep 2016 11:43 pm, BartC wrote: > It can make sense for 'x' to be local to this for-loop block (everything > else is at it works now), and independent of any x's in outer blocks. It > means being able to do stuff like this: > > for x in a: > for x in b: > pass >

Re: unintuitive for-loop behavior

2016-09-30 Thread Steve D'Aprano
On Fri, 30 Sep 2016 03:06 pm, Rustom Mody wrote: > On Friday, September 30, 2016 at 10:23:31 AM UTC+5:30, Gregory Ewing > wrote: >> namenobodywants wrote: >> > can anyone help to reconcile me to this semantics? >> >> Not really. Most people agree that it's not desirable >> behaviour, but we've e

Re: unintuitive for-loop behavior

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 3:03 AM, Brendan Abel <007bren...@gmail.com> wrote: >> a = 1 > if condition: > print(a) # UnboundLocalError: local 'a' referenced before assignment > a += 1 > > > For-loops are no different. Making them their own namespace is a very > strange thing to do, it would me

Re: unintuitive for-loop behavior

2016-09-30 Thread Brendan Abel
> a = 1 if condition: print(a) # UnboundLocalError: local 'a' referenced before assignment a += 1 For-loops are no different. Making them their own namespace is a very strange thing to do, it would mean you couldn't re-bind a value inside a for-loop: count = 0 for x in sequence: cou

Re: unintuitive for-loop behavior

2016-09-30 Thread Grant Edwards
On 2016-09-30, Grant Edwards wrote: > On 2016-09-30, Steve D'Aprano wrote: > >> To me, "make for-loops be their own scope" sounds like a joke >> feature out of joke languages like INTERCAL. I'm not aware of any >> sensible language that does anything like this. > > In C99 a for loop has its own n

Re: unintuitive for-loop behavior

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 12:36 AM, Grant Edwards wrote: > On 2016-09-30, Steve D'Aprano wrote: > >> To me, "make for-loops be their own scope" sounds like a joke feature out of >> joke languages like INTERCAL. I'm not aware of any sensible language that >> does anything like this. > > In C99 a for

Re: unintuitive for-loop behavior

2016-09-30 Thread BartC
On 30/09/2016 15:01, Chris Angelico wrote: On Fri, Sep 30, 2016 at 10:33 PM, Steve D'Aprano wrote: To me, "make for-loops be their own scope" sounds like a joke feature out of joke languages like INTERCAL. I'm not aware of any sensible language that does anything like this. No, wait a minute,

Re: unintuitive for-loop behavior

2016-09-30 Thread Grant Edwards
On 2016-09-30, Steve D'Aprano wrote: > To me, "make for-loops be their own scope" sounds like a joke feature out of > joke languages like INTERCAL. I'm not aware of any sensible language that > does anything like this. In C99 a for loop has its own namespac: int main(void) { for (int i=

Re: unintuitive for-loop behavior

2016-09-30 Thread Chris Angelico
On Fri, Sep 30, 2016 at 10:33 PM, Steve D'Aprano wrote: > To me, "make for-loops be their own scope" sounds like a joke feature out of > joke languages like INTERCAL. I'm not aware of any sensible language that > does anything like this. > > No, wait a minute, I tell a lie, I recall Chris Angelico

Re: unintuitive for-loop behavior

2016-09-30 Thread BartC
On 30/09/2016 13:33, Steve D'Aprano wrote: On Fri, 30 Sep 2016 05:29 am, namenobodywa...@gmail.com wrote: i've had a nodding acquaintance with python for some time, and all along i assumed that for-loops got a namespace of their own; It would be terribly inconvenient and surprising for if..

Re: unintuitive for-loop behavior

2016-09-30 Thread Steve D'Aprano
On Fri, 30 Sep 2016 05:29 am, namenobodywa...@gmail.com wrote: > hello pythonistas > > i've had a nodding acquaintance with python for some time, and all along i > assumed that for-loops got a namespace of their own; Giving for-loops their own namespace is a grossly unintuitive and a very weird

Re: unintuitive for-loop behavior

2016-09-29 Thread Rustom Mody
On Friday, September 30, 2016 at 10:23:31 AM UTC+5:30, Gregory Ewing wrote: > namenobodywants wrote: > > can anyone help to reconcile me to this semantics? > > Not really. Most people agree that it's not desirable > behaviour, but we've ended up here due to a convoluted > history, and there doesn

Re: unintuitive for-loop behavior

2016-09-29 Thread Gregory Ewing
namenobodywa...@gmail.com wrote: > can anyone help to reconcile me to this semantics? Not really. Most people agree that it's not desirable behaviour, but we've ended up here due to a convoluted history, and there doesn't seem to be a good way to fix it without breaking a lot of existing code. C

Re: unintuitive for-loop behavior

2016-09-29 Thread Chris Angelico
On Fri, Sep 30, 2016 at 5:29 AM, wrote: > i've had a nodding acquaintance with python for some time, and all along i > assumed that for-loops got a namespace of their own; now i'm reading up on > the language and i find out that's not the case: the loop variable gets put > into the enclosing n

Re: unintuitive for-loop behavior

2016-09-29 Thread Brendan Abel
Yes, loops don't have their own scope. Indeed, very few flow elements in python -- if, with, try/except -- create a new scope. In that sense, it's fairly consistent, but can be unexpected for people that have used languages with many nested scopes. The lambda behavior is a common gotcha - there

unintuitive for-loop behavior

2016-09-29 Thread namenobodywants
hello pythonistas i've had a nodding acquaintance with python for some time, and all along i assumed that for-loops got a namespace of their own; now i'm reading up on the language and i find out that's not the case: the loop variable gets put into the enclosing namespace, overwriting any forme