Re: nonlocal fails ?

2019-11-24 Thread Peter J. Holzer
On 2019-11-23 18:18:16 -0500, Richard Damon wrote: > On 11/23/19 4:18 PM, Peter J. Holzer wrote: > > On 2019-11-14 20:29:01 -0500, Dennis Lee Bieber wrote: > >>Instead, at a simple level (a common description invokes "Post-It" > >> notes) > >> > >>x = y > >> > >> means /find/ the

Re: nonlocal fails ?

2019-11-23 Thread Chris Angelico
On Sun, Nov 24, 2019 at 10:19 AM Richard Damon wrote: > Yes, as presented, it doesn't handle the concept of scope of variables, > but that starts to get into more complexity than you might want for a > simple model, and it is simple to extend to handle it, either every > scope gets a different

Re: nonlocal fails ?

2019-11-23 Thread Richard Damon
On 11/23/19 4:18 PM, Peter J. Holzer wrote: > On 2019-11-14 20:29:01 -0500, Dennis Lee Bieber wrote: >> Instead, at a simple level (a common description invokes "Post-It" >> notes) >> >> x = y >> >> means /find/ the object (somewhere in memory) that has a note "y" stuck to >> it.

Re: nonlocal fails ?

2019-11-23 Thread Peter J. Holzer
On 2019-11-14 20:29:01 -0500, Dennis Lee Bieber wrote: > Instead, at a simple level (a common description invokes "Post-It" > notes) > > x = y > > means /find/ the object (somewhere in memory) that has a note "y" stuck to > it. Without moving the "y" note, attach an "x" note

Re: nonlocal fails ?

2019-11-17 Thread Random832
On Sun, Nov 17, 2019, at 07:26, Richard Damon wrote: > I am not sure about C#, but in C++, a base language for C#, you can not > take the address of a variable of reference type, if you do, you get the > objected referred to, not the reference. References are essentially > constant pointers, and

Re: nonlocal fails ?

2019-11-17 Thread Richard Damon
On 11/17/19 1:33 AM, Random832 wrote: > On Fri, Nov 15, 2019, at 13:41, Dennis Lee Bieber wrote: >> C# documents those as something visible to the user at the language >> level... >> https://www.infoworld.com/article/3043992/a-deep-dive-value-and-reference-types-in-net.html >> """ >> Types in

Re: nonlocal fails ?

2019-11-16 Thread Random832
On Fri, Nov 15, 2019, at 13:41, Dennis Lee Bieber wrote: > C# documents those as something visible to the user at the language > level... > https://www.infoworld.com/article/3043992/a-deep-dive-value-and-reference-types-in-net.html > """ > Types in Microsoft .Net can be either value type or

Re: nonlocal fails ?

2019-11-15 Thread Chris Angelico
On Sat, Nov 16, 2019 at 5:41 PM Gregory Ewing wrote: > > On 16/11/19 8:22 am, Chris Angelico wrote: > > That's the typical sort of description you get from someone who mostly > > understands Python's semantics, but is hung up on the idea that > > everything is either call-by-value or

Re: nonlocal fails ?

2019-11-15 Thread Gregory Ewing
On 16/11/19 8:22 am, Chris Angelico wrote: That's the typical sort of description you get from someone who mostly understands Python's semantics, but is hung up on the idea that everything is either call-by-value or call-by-reference, and is trying to figure out which box Python fits into. Or

Re: nonlocal fails ?

2019-11-15 Thread Terry Reedy
On 11/15/2019 5:48 AM, R.Wieser wrote: Closures are standard in functional languages and are less limited than you seem to think. I was talking about the "nonlocal" method of variable inheritance, not closures. You cannot really separate the two. A 'nonlocal' declaration can only be used in

Re: nonlocal fails ?

2019-11-15 Thread Chris Angelico
On Sat, Nov 16, 2019 at 6:20 AM Luciano Ramalho wrote: > > Re: the whole pass by reference discussion. > > I've seen Python's argument passing described as "call by value, > except that all values are references". This makes sense, but is > confusing. That's the typical sort of description you

Re: nonlocal fails ?

2019-11-15 Thread Luciano Ramalho
Re: the whole pass by reference discussion. I've seen Python's argument passing described as "call by value, except that all values are references". This makes sense, but is confusing. Michael Scott, in his textbook Programming Language Pragmatics (4e) terms the Python way "call by sharing".

Re: nonlocal fails ?

2019-11-15 Thread Bev In TX
> On Nov 15, 2019, at 11:11 AM, Python wrote: > > Richard Damon wrote: > ... >> then elsewhere you could do >> foo(j) >> and after that j is 2 >> you also could do >> foo(1) >> and after that if you did >> j = 1 >> then now j might have the value 2 as the constant 1 was changed to the >> value

Re: nonlocal fails ?

2019-11-15 Thread Richard Damon
On 11/15/19 12:21 PM, Random832 wrote: > On Fri, Nov 15, 2019, at 11:47, Richard Damon wrote: >> The issue with calling it a Reference, is that part of the meaning of a >> Reference is that it refers to a Object, and in Python, Names are >> conceptually something very much different than an

Re: nonlocal fails ?

2019-11-15 Thread Random832
On Fri, Nov 15, 2019, at 11:47, Richard Damon wrote: > The issue with calling it a Reference, is that part of the meaning of a > Reference is that it refers to a Object, and in Python, Names are > conceptually something very much different than an Object. Yes, in the > implementation details, a

Re: nonlocal fails ?

2019-11-15 Thread Python
Richard Damon wrote: ... then elsewhere you could do foo(j) and after that j is 2 you also could do foo(1) and after that if you did j = 1 then now j might have the value 2 as the constant 1 was changed to the value 2 (this can cause great confusion) Wow! So fubar that such a feature

Re: nonlocal fails ?

2019-11-15 Thread Richard Damon
On 11/15/19 11:26 AM, Dennis Lee Bieber wrote: > On Fri, 15 Nov 2019 12:56:02 +0100, "R.Wieser" > declaimed the following: > >> There are quite a number of languages where /every/ type of argument >> (including values) can be transfered "by reference". Though some default to >> "by value",

Re: nonlocal fails ?

2019-11-15 Thread Richard Damon
On 11/15/19 11:04 AM, Random832 wrote: > On Fri, Nov 15, 2019, at 10:48, Richard Damon wrote: >> On 11/15/19 6:56 AM, R.Wieser wrote: >>> There are quite a number of languages where /every/ type of argument >>> (including values) can be transfered "by reference". Though some default >>> to >>>

Re: nonlocal fails ?

2019-11-15 Thread Michael Torrie
On 11/15/19 5:28 AM, R.Wieser wrote: > :-) Although that is how we humans remember the effect of what we do, there > is no reason for a programming language to do it exactly like that. And > sometimes they don't. So, in effect he's saying not all languages use the classic variable model,

Re: nonlocal fails ?

2019-11-15 Thread Random832
On Fri, Nov 15, 2019, at 10:48, Richard Damon wrote: > On 11/15/19 6:56 AM, R.Wieser wrote: > > There are quite a number of languages where /every/ type of argument > > (including values) can be transfered "by reference". Though some default > > to > > "by value", where others default to "by

Re: nonlocal fails ?

2019-11-15 Thread Michael Torrie
On 11/15/19 4:56 AM, R.Wieser wrote: >> Well I've only seen this done in languages where other mechanisms >> for returning complex types are not present. > > :-) Than you have not seen to many languages I'm afraid. Careful there. > If I would have wanted that, why would I post here with open

Re: nonlocal fails ?

2019-11-15 Thread Richard Damon
On 11/15/19 6:56 AM, R.Wieser wrote: > There are quite a number of languages where /every/ type of argument > (including values) can be transfered "by reference". Though some default to > "by value", where others default to "by reference". It seems you are stuck in a programming model

Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Pieter, > Do you mean, if Proc1() is called from Func1, it uses MyVar defined >in Func1, and if it is called from Func2, it uses MyVar from Func2? Yep. > If that is what you mean, that would be dynamic scope. Thanks for pointing that out (I've learned a new definition today! :-) ). Regards,

Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Dennis, > The first thing one needs to learn is that Python does NOT follow the > common post-office mailbox concept where > > x = y > > means the /value/ stored at location identified by "y" is /copied/ to the > location identified by "x". :-) Although that is how we humans remember the effect

Re: nonlocal fails ?

2019-11-15 Thread Chris Angelico
On Fri, Nov 15, 2019 at 11:01 PM R.Wieser wrote: > > As for "complex types" ? I don't think a(n ASCII) string can be considered > any kind of a complex type, but most all languages I know of transfer them > "by reference" only (though some fake "by value" by using a copy-on-write > mechanism).

Re: nonlocal fails ?

2019-11-15 Thread Chris Angelico
On Fri, Nov 15, 2019 at 9:16 PM R.Wieser wrote: > > Chris, > > > That doesn't really answer the question. > > The problem is that you want to solve /this/ problem, while I'm looking for > replies that are applicable to similar ones too. > > To be blunt about it: I consider solutions that only

Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Michael, > Well I've only seen this done in languages where other mechanisms >for returning complex types are not present. :-) Than you have not seen to many languages I'm afraid. There are quite a number of languages where /every/ type of argument (including values) can be transfered "by

Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Terry, > This is discouraged for anything very complex. Complex things do not exist. If you think you have something like it you've just not yet broken it down in its components yet. :-) > This is the standard way in Python and other OO languages. By 'excluded', > do you mean 'rejected', or

Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Chris, > That doesn't really answer the question. The problem is that you want to solve /this/ problem, while I'm looking for replies that are applicable to similar ones too. To be blunt about it: I consider solutions that only solve a single problem most always as a waste of my time

Re: nonlocal fails ?

2019-11-15 Thread Antoon Pardon
On 14/11/19 18:46, R.Wieser wrote: > Jan, > >> So what you want to do is dynamic scope? > No, not really.I was looking for method to let one procedure share a > variable with its caller - or callers, selectable by me. And as a "by > reference" argument does not seem to exist in Python ...

Re: nonlocal fails ?

2019-11-15 Thread Pieter van Oostrum
"R.Wieser" writes: > Jan, > >> So what you want to do is dynamic scope? > > No, not really.I was looking for method to let one procedure share a > variable with its caller - or callers, selectable by me. And as a "by > reference" argument does not seem to exist in Python ... > > And yes,

Re: nonlocal fails ?

2019-11-14 Thread Richard Damon
On 11/14/19 12:57 PM, R.Wieser wrote: > Michael, > >> nonlocal does not share or use its *caller's* variables. Rather it >> reaches into the scope of the outer function where it was defined. >> That's a very different concept than what you're proposing. > Oh blimy! You're right.Its an at

Re: nonlocal fails ?

2019-11-14 Thread Richard Damon
On 11/14/19 1:43 PM, R.Wieser wrote: > Richard, > >> Assuming that one language works like another is a danger > Abitrarily redefining words and using misnomers is another ... ("global" > and "nonlocal" respecivily if you wonder) > >> First, Python doesn't really have 'Variables' like a lot of

Re: nonlocal fails ?

2019-11-14 Thread Michael Torrie
On 11/14/19 2:16 PM, R.Wieser wrote: > I think I did - though implicitily. What do normal people use "by > reference" arguments for ? Yep, that is what I wanted too. Well I've only seen this done in languages where other mechanisms for returning complex types are not present. For example in

Re: nonlocal fails ?

2019-11-14 Thread Terry Reedy
On 11/14/2019 4:16 PM, R.Wieser wrote: If you mentioned what problem you are trying to solve 1) Have value 2) use value in procedure 1 3) use updated value in procedure 2 4) use again updated value in procedure 1, 2 or maybe 3 For the sake of learning I'm now going over all of the

Re: nonlocal fails ?

2019-11-14 Thread Chris Angelico
On Fri, Nov 15, 2019 at 8:21 AM R.Wieser wrote: > > Michael, > > > I note that you didn't answer the question, what are you trying > > to accomplish? > > I think I did - though implicitily. What do normal people use "by > reference" arguments for ? Yep, that is what I wanted too. > That

Re: nonlocal fails ?

2019-11-14 Thread R.Wieser
Michael, > I note that you didn't answer the question, what are you trying > to accomplish? I think I did - though implicitily. What do normal people use "by reference" arguments for ? Yep, that is what I wanted too. > It looks to me like you're trying to write a program in a different >

Re: nonlocal fails ?

2019-11-14 Thread Chris Angelico
On Fri, Nov 15, 2019 at 7:19 AM Michael Torrie wrote: > > On 11/14/19 10:57 AM, R.Wieser wrote: > >> I know of no sane way that a function could work with the scope of > >> any arbitrary caller. > > > > The trick seems to be to emulate a "by reference" call, by using a mutable > > object as the

Re: nonlocal fails ?

2019-11-14 Thread Michael Torrie
On 11/14/19 10:57 AM, R.Wieser wrote: > The trick seems to be to emulate a "by reference" call, by using a mutable > object as the argument and stuff the value inside of it (IIRC a tuple with a > single element). I note that you didn't answer the question, what are you trying to accomplish? In

Re: nonlocal fails ?

2019-11-14 Thread Michael Torrie
On 11/14/19 10:57 AM, R.Wieser wrote: >> I know of no sane way that a function could work with the scope of >> any arbitrary caller. > > The trick seems to be to emulate a "by reference" call, by using a mutable > object as the argument and stuff the value inside of it (IIRC a tuple with a >

Re: nonlocal fails ?

2019-11-14 Thread Terry Reedy
On 11/14/2019 12:53 PM, Richard Damon wrote: On Nov 14, 2019, at 12:20 PM, R.Wieser wrote: MRAB, 'nonlocal' is used where the function is nested in another function The problem is that that was not clear to me from the description - nor is it logical to me why it exludes the main context

Re: nonlocal fails ?

2019-11-14 Thread Chris Angelico
On Fri, Nov 15, 2019 at 5:46 AM R.Wieser wrote: > > Richard, > > > Assuming that one language works like another is a danger > > Abitrarily redefining words and using misnomers is another ... ("global" > and "nonlocal" respecivily if you wonder) Every language that has a concept of "global"

Re: nonlocal fails ?

2019-11-14 Thread R.Wieser
Richard, > Assuming that one language works like another is a danger Abitrarily redefining words and using misnomers is another ... ("global" and "nonlocal" respecivily if you wonder) > First, Python doesn't really have 'Variables' like a lot of other > languages > (they don't hold a bag of

Re: nonlocal fails ?

2019-11-14 Thread Richard Damon
> On Nov 14, 2019, at 12:56 PM, R.Wieser wrote: > > Jan, > >> So what you want to do is dynamic scope? > > No, not really.I was looking for method to let one procedure share a > variable with its caller - or callers, selectable by me. And as a "by > reference" argument does not seem

Re: nonlocal fails ?

2019-11-14 Thread Rhodri James
On 14/11/2019 17:11, R.Wieser wrote: Rhodri, MyVar is a global here, so nonlocal explicitly doesn't pick it up. I do not agree with you there (the variable being global). If it where than I would have been able to alter the variable inside the procedure without having to resort to a "global"

Re: nonlocal fails ?

2019-11-14 Thread R.Wieser
Michael, > nonlocal does not share or use its *caller's* variables. Rather it > reaches into the scope of the outer function where it was defined. > That's a very different concept than what you're proposing. Oh blimy! You're right.Its an at compile-time thing, not a runtime one. Thanks

Re: nonlocal fails ?

2019-11-14 Thread Richard Damon
> > On Nov 14, 2019, at 12:20 PM, R.Wieser wrote: > > MRAB, > >> 'nonlocal' is used where the function is nested in another function > > The problem is that that was not clear to me from the description - nor is > it logical to me why it exludes the main context from its use. > > Regards,

Re: nonlocal fails ?

2019-11-14 Thread R.Wieser
Jan, > So what you want to do is dynamic scope? No, not really.I was looking for method to let one procedure share a variable with its caller - or callers, selectable by me. And as a "by reference" argument does not seem to exist in Python ... And yes, I am a ware that procedures can

Re: nonlocal fails ?

2019-11-14 Thread Richard Damon
On Nov 14, 2019, at 12:18 PM, R.Wieser wrote: > > Rhodri, > >> MyVar is a global here, so nonlocal explicitly doesn't pick it up. > > I do not agree with you there (the variable being global). If it where than > I would have been able to alter the variable inside the procedure without >

Re: nonlocal fails ?

2019-11-14 Thread R.Wieser
MRAB, > 'nonlocal' is used where the function is nested in another function The problem is that that was not clear to me from the description - nor is it logical to me why it exludes the main context from its use. Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list

Re: nonlocal fails ?

2019-11-14 Thread R.Wieser
Rhodri, > MyVar is a global here, so nonlocal explicitly doesn't pick it up. I do not agree with you there (the variable being global). If it where than I would have been able to alter the variable inside the procedure without having to resort to a "global" override (an override which is only

Re: nonlocal fails ?

2019-11-14 Thread Michael Torrie
On 11/14/19 7:15 AM, R.Wieser wrote: > Too bad though, it means that procedures that want to share/use its callers > variables using nonlocal can never be called from main. And that a caller > of a procedure using nonlocal cannot have the variable declared as global > (just tested it).

Re: nonlocal fails ?

2019-11-14 Thread Jan Erik Moström
On 14 Nov 2019, at 15:15, R.Wieser wrote: Too bad though, it means that procedures that want to share/use its callers variables using nonlocal can never be called from main. And that a caller of a procedure using nonlocal cannot have the variable declared as global (just tested it). So

Re: nonlocal fails ?

2019-11-14 Thread R.Wieser
Jan, > The nonlocal statement causes the listed identifiers to refer to > previously bound variables in the nearest **enclosing scope excluding > globals**. I read that too, but didn't get from it that the main scope is excluded (I assumed the"excluding globals" was ment at as such

Re: nonlocal fails ?

2019-11-14 Thread Rhodri James
On 14/11/2019 13:06, R.Wieser wrote: Hello all, I've just tried to use a "nonlocal MyVar" statement in a procedure defenition, but it throws an error saying "Syntax error: no binding for nonlocal 'MyVar' found. According to platform.python_version() I'm running version 3.8.3 Why am I getting

Re: nonlocal fails ?

2019-11-14 Thread MRAB
On 2019-11-14 13:06, R.Wieser wrote: Hello all, I've just tried to use a "nonlocal MyVar" statement in a procedure defenition, but it throws an error saying "Syntax error: no binding for nonlocal 'MyVar' found. According to platform.python_version() I'm running version 3.8.3 Why am I getting

Re: nonlocal fails ?

2019-11-14 Thread Jan Erik Moström
On 14 Nov 2019, at 14:06, R.Wieser wrote: I've also tried moving "MyVar = 7" to the first line, but that doesn't change anything. Using "global MyVar" works.. Try def outer(): MyVar = 10 def Proc1(): nonlocal MyVar MyVar = 5 Proc1()

nonlocal fails ?

2019-11-14 Thread R.Wieser
Hello all, I've just tried to use a "nonlocal MyVar" statement in a procedure defenition, but it throws an error saying "Syntax error: no binding for nonlocal 'MyVar' found. According to platform.python_version() I'm running version 3.8.3 Why am I getting that error ? (already googeled