Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 9:50:09 AM UTC-6, Steven D'Aprano wrote: PS On the topic of enums, when are we getting support for a switch statement? http://legacy.python.org/dev/peps/pep-3103/ http://legacy.python.org/dev/peps/pep-0275/ I have reviewed these peps, and I heard Guido's

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Mark H. Harris harrismh...@gmail.com: I think the real issue is about the syntax... because of python's unique indent strategy going back to ABC, a pythonized switch statement would play havoc with the many text parsers out there used for development (TestWrangler, and many others). I also

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 5:53 AM, Marko Rauhamaa ma...@pacujo.net wrote: A dict dispatch table is just awful. Really? How is that? I've used them, often. Yes, there are times when I could express something more cleanly with a C-style switch statement, but other times the dispatch table is

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: On Sat, Mar 1, 2014 at 5:53 AM, Marko Rauhamaa ma...@pacujo.net wrote: A dict dispatch table is just awful. Really? How is that? I've used them, often. Yes, there are times when I could express something more cleanly with a C-style switch statement, but

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 1:20:52 PM UTC-6, Marko Rauhamaa wrote: Which do *you* find more readable? Yep, my point exactly. nice illustration. -- https://mail.python.org/mailman/listinfo/python-list

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Mark H. Harris harrismh...@gmail.com: Yep, my point exactly. nice illustration. So now, for you and me: let's compare. if key is ast.Assign: return ' '.join(dump(t) for t in node.targets) elif key is ast.AugAssign: # Same target and same operator. return

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 28/02/2014 21:03, Marko Rauhamaa wrote: Mark H. Harris harrismh...@gmail.com: Yep, my point exactly. nice illustration. So now, for you and me: let's compare. if key is ast.Assign: return ' '.join(dump(t) for t in node.targets) elif key is ast.AugAssign: #

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 20:53:15 +0200, Marko Rauhamaa wrote: Mark H. Harris harrismh...@gmail.com: I think the real issue is about the syntax... because of python's unique indent strategy going back to ABC, a pythonized switch statement would play havoc with the many text parsers out there

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Mark Lawrence breamore...@yahoo.co.uk: http://c2.com/cgi/wiki?SwitchStatementsSmell Your brief summary, please, Mark? Anyway, the first 1000 lines or so that I managed to read from that page stated a valid principle, which however doesn't invalidate the existence of a switch statement. A

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Marko Rauhamaa ma...@pacujo.net writes: Ben Finney ben+pyt...@benfinney.id.au: First reason: This is better done by making it clear the value is an arbitrary object that won't be compared for equality. Just use ‘object()’ to creeate each value and be done with it. That's a hack, but

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 21:20:52 +0200, Marko Rauhamaa wrote: Your example: [snip] I'm not going to show the example as quoted by you, because my news client is wrapping it in ugly ways and I don't want to spend the time fixing it. I'll just say that, as given, it's a great big wall of text, a

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote: Marko ... and between me and you, here is a snip from dmath.py from the atan(x) function: if (n**2 D(1)): a = __atan__(n) elif (n == D(1)): a = gpi/4 elif (n == D(-1)): a = -(gpi/4)

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Marko Rauhamaa ma...@pacujo.net writes: Mark Lawrence breamore...@yahoo.co.uk: http://c2.com/cgi/wiki?SwitchStatementsSmell Your brief summary, please, Mark? Anyway, the first 1000 lines or so that I managed to read from that page stated a valid principle, which however doesn't

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: You can't have it both ways: you cannot claim that switch or case is more readable than a chain of if...elif, and then propose a syntax which is effectively a chain of if...elif while still claiming it is an improvement. It's not. All

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Ben Finney ben+pyt...@benfinney.id.au: As has been pointed out to you, the whole point here is that string objects often *are not* distinct, despite conceptually having distinct cretion in the source. You know full well that this initialization creates references to distinct objects:

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 14:25:54 +0200, Marko Rauhamaa wrote: Chris Angelico ros...@gmail.com: On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: a.state = a.INIT In theory, yes. If that's all people will ever do, then you can safely

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Mark H. Harris harrismh...@gmail.com: if (n**2 D(1)): a = __atan__(n) elif (n == D(1)): a = gpi/4 elif (n == D(-1)): a = -(gpi/4) elif (n D(-1)): a = __atan__Lt_neg1__(n) else: a = __atan__Gt_1__(n) Drop the outermost

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ned Batchelder
On 2/28/14 6:36 PM, Mark H. Harris wrote: On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote: Marko ... and between me and you, here is a snip from dmath.py from the atan(x) function: if (n**2 D(1)): a = __atan__(n) elif (n == D(1)): a =

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Sat, 01 Mar 2014 02:03:51 +0200, Marko Rauhamaa wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: You can't have it both ways: you cannot claim that switch or case is more readable than a chain of if...elif, and then propose a syntax which is effectively a chain of if...elif

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Marko Rauhamaa ma...@pacujo.net writes: Ben Finney ben+pyt...@benfinney.id.au: As has been pointed out to you, the whole point here is that string objects often *are not* distinct, despite conceptually having distinct cretion in the source. You know full well that this initialization

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Sat, 01 Mar 2014 02:11:53 +0200, Marko Rauhamaa wrote: Ben Finney ben+pyt...@benfinney.id.au: As has been pointed out to you, the whole point here is that string objects often *are not* distinct, despite conceptually having distinct cretion in the source. You know full well that this

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 01/03/2014 00:40, Ned Batchelder wrote: On 2/28/14 6:36 PM, Mark H. Harris wrote: On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote: Marko ... and between me and you, here is a snip from dmath.py from the atan(x) function: if (n**2 D(1)): a =

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: I can only imagine you mean something like this: class Outer: class InnerOne: ... class InnerTwo: ... class InnerThree: ... No, I mean this: class StateMachine: def __init__(self):

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote: I don't understand: you show an if/elif chain that cannot be expressed as a switch statement (because it uses ), and then conclude that Python needs a switch statement? That doesn't make any sense. Forgive me. I

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Ben Finney ben+pyt...@benfinney.id.au: From each other, of course they're distinct, because they are unequal. They are *not* necessarily distinct from other strings with equal value, defined elsewhere. That's what has been pointed out to you many times. That point is completely irrelevant.

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 01/03/2014 00:03, Marko Rauhamaa wrote: Dict dispatch tables are elegant, attractive and efficient if you are using pre-existing functions or functions you can create using lambda: I beg to differ. The dict dispatch tables are very hard to read. The fully blown-out if-else chain beats it

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 01/03/2014 01:10, Marko Rauhamaa wrote: Ben Finney ben+pyt...@benfinney.id.au: From each other, of course they're distinct, because they are unequal. They are *not* necessarily distinct from other strings with equal value, defined elsewhere. That's what has been pointed out to you many

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 7:10:49 PM UTC-6, Mark Lawrence wrote: I think you're talking nonsense. I've been happily using dict dispatch tables for years and, like Steven and presumably many others, find them dead easy to read. Perhaps you should invest in a better optician and/or

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Marko Rauhamaa ma...@pacujo.net writes: Ben Finney ben+pyt...@benfinney.id.au: They are *not* necessarily distinct from other strings with equal value, defined elsewhere. That's what has been pointed out to you many times. That point is completely irrelevant. The state objects only need

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 6:20 AM, Marko Rauhamaa ma...@pacujo.net wrote: Your example: compare_key = { # Same target(s). ast.Assign: lambda node: ' '.join(dump(t) for t in node.targets), # Same target and same operator. ast.AugAssign: lambda node:

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Sat, 01 Mar 2014 03:06:38 +0200, Marko Rauhamaa wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: I can only imagine you mean something like this: class Outer: class InnerOne: ... class InnerTwo: ... class InnerThree: ... No, I

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 10:06 AM, Marko Rauhamaa ma...@pacujo.net wrote: A colleague of mine taught me decades back that the whole point of OO was the avoidance of if and switch statements. So if your code has an if or switch statement, chances are you are doing something wrong. I agree.

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 12:08 PM, Mark H. Harris harrismh...@gmail.com wrote: On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote: I don't understand: you show an if/elif chain that cannot be expressed as a switch statement (because it uses ), and then conclude that Python

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 12:59 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: However, the example as given won't quite work. You never instantiate the Idle etc. classes, which means the methods won't work. You need to make them class methods or static methods, or perform some

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ned Batchelder
On 2/28/14 8:08 PM, Mark H. Harris wrote: On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote: I don't understand: you show an if/elif chain that cannot be expressed as a switch statement (because it uses ), and then conclude that Python needs a switch statement? That

Re: Can global variable be passed into Python function?

2014-02-28 Thread Gregory Ewing
Mark H. Harris wrote: if (n**2 D(1)): a = __atan__(n) elif (n == D(1)): a = gpi/4 elif (n == D(-1)): a = -(gpi/4) elif (n D(-1)): a = __atan__Lt_neg1__(n) else: a = __atan__Gt_1__(n) That's not a candidate for a switch statement,

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Sat, 01 Mar 2014 13:03:53 +1100, Chris Angelico wrote: On Sat, Mar 1, 2014 at 12:59 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: However, the example as given won't quite work. You never instantiate the Idle etc. classes, which means the methods won't work. You need to

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 8:15:38 PM UTC-6, Ned Batchelder wrote: Mark, if you are going to advocate for a feature, find a good use case, this one is absurd. Where did the constants GT_1 etc, come from? Not at all. Think of the C switch block... if you read about it in the K R you'll

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 8:01:45 PM UTC-6, Chris Angelico wrote: Does your switch construct have to handle the magic of GT_1 meaning 1, or do you first figure out where it falls with an if/elif tree? ChrisA hi Chris, yeah... well think again of the switch block in C... the switch

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 4:30 PM, Mark H. Harris harrismh...@gmail.com wrote: hi Chris, yeah... well think again of the switch block in C... the switch block selects a branch based on an integral number (int character) that is generally a return code from a function. The function hides all

Re: Can global variable be passed into Python function?

2014-02-27 Thread Mark H. Harris
On Friday, February 21, 2014 12:37:59 AM UTC-6, Sam wrote: I need to pass a global variable into a python function. However, the global variable does not seem to be assigned after the function ends. Is it because parameters are not passed by reference? How can I get function parameters to

Re: Can global variable be passed into Python function?

2014-02-27 Thread Ned Batchelder
On 2/27/14 8:24 AM, Mark H. Harris wrote: As others have noted, python does not have a 'variable' concept (references to objects instead) and so your question is a little ambiguous. Mark, thanks for helping to answer the OP's question. We've covered (in depth) in the rest of this thread,

Re: Can global variable be passed into Python function?

2014-02-27 Thread Mark H. Harris
On Thursday, February 27, 2014 11:54:44 AM UTC-6, Ned Batchelder wrote: Mark, thanks for helping to answer the OP's question. We've covered (in depth) in the rest of this thread, that Python *does* have the concept of a variable, it just behaves differently than some other popular

Re: Can global variable be passed into Python function?

2014-02-27 Thread Steven D'Aprano
On Thu, 27 Feb 2014 15:29:01 -0800, Mark H. Harris wrote: Knowing that A points to an int, and that B=A, now B points to the VERY SAME int... they are references pointing to the same piece of memory. And of course we want new folks to understand the issue of: A==B True A is B False

Re: Can global variable be passed into Python function?

2014-02-27 Thread Mark H. Harris
On Thursday, February 27, 2014 8:07:20 PM UTC-6, Steven D'Aprano wrote: If they point to the same piece of memory -- which, by the way, can be moved around if the garbage collector supports it -- then A is B cannot possibly return False. hi Steve, long time, yes, my whole point

References, and avoiding use of “variable” (was: Can global variable be passed into Python function?)

2014-02-27 Thread Ben Finney
Mark H. Harris harrismh...@gmail.com writes: So, yeah, thinking about variables is just not going away. Right. I would like, ideally, for the Python documentation to avoid mentioning that term entirely; and I would hope for that to promote a better understanding of Python's data model. The

Re: Can global variable be passed into Python function?

2014-02-27 Thread Chris Angelico
On Fri, Feb 28, 2014 at 1:29 PM, Mark H. Harris harrismh...@gmail.com wrote: a=1024 b=a b=1024 a is b False No no no no! They're not pointing to the same integer any more. Now, if you change the b=1024 from being a mostly-useless assignment (to another int with the same value) into being a

Re: Can global variable be passed into Python function?

2014-02-27 Thread Mark H. Harris
On Thursday, February 27, 2014 10:43:23 PM UTC-6, Chris Angelico wrote: Simple rule of thumb: Never use 'is' with strings or ints. They're immutable, their identities should be their values. Playing with 'is' will only confuse you, unless you're specifically going for introspection and such.

Re: Can global variable be passed into Python function?

2014-02-27 Thread Chris Angelico
On Fri, Feb 28, 2014 at 4:39 PM, Mark H. Harris harrismh...@gmail.com wrote: On Thursday, February 27, 2014 10:43:23 PM UTC-6, Chris Angelico wrote: Simple rule of thumb: Never use 'is' with strings or ints. They're immutable, their identities should be their values. Playing with 'is' will

Re: Can global variable be passed into Python function?

2014-02-27 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: Simple rule of thumb: Never use 'is' with strings or ints. They're immutable, their identities should be their values. Playing with 'is' will only confuse you, unless you're specifically going for introspection and such. Here's a use case for is with strings

Re: Can global variable be passed into Python function?

2014-02-26 Thread Gregory Ewing
Steven D'Aprano wrote: Standard Pascal? Who uses standard Pascal? I'm talking about MacPascal :-) Mac Pascal used @ for getting a pointer to a variable, if I remember rightly. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Can global variable be passed into Python function?

2014-02-26 Thread MRAB
On 2014-02-26 10:59, Gregory Ewing wrote: Steven D'Aprano wrote: Standard Pascal? Who uses standard Pascal? I'm talking about MacPascal :-) Mac Pascal used @ for getting a pointer to a variable, if I remember rightly. So did Turbo Pascal. Delphi, which is what Turbo Pascal became, is the

Re: Can global variable be passed into Python function?

2014-02-24 Thread Gregory Ewing
Steven D'Aprano wrote: Yes, Pascal has pointers as a first-class data type. Syntax is similar to C, ^x is a pointer to x, p^ dereferences the pointer p. Actually, the prefix ^ is only used for declaring pointer *types*. Standard Pascal has no way of getting a pointer to an arbitrary variable;

Re: Can global variable be passed into Python function?

2014-02-24 Thread wxjmfauth
Le lundi 24 février 2014 01:37:42 UTC+1, Steven D'Aprano a écrit : Performance can matter :-) timeit.timeit('abc' * 1000 + 'z') 0.991999136702321 timeit.timeit('abc' * 1000 + '\N{EURO SIGN}') 2.5462559386176444 Two points to notice - Even with utf-8, the worse performance

Re: Can global variable be passed into Python function?

2014-02-24 Thread Steven D'Aprano
On Mon, 24 Feb 2014 21:07:42 +1300, Gregory Ewing wrote: Steven D'Aprano wrote: Yes, Pascal has pointers as a first-class data type. Syntax is similar to C, ^x is a pointer to x, p^ dereferences the pointer p. Actually, the prefix ^ is only used for declaring pointer *types*. Standard

Re: Can global variable be passed into Python function?

2014-02-24 Thread j . e . haque
On Sunday, February 23, 2014 5:01:25 AM UTC-6, Marko Rauhamaa wrote: Chris Angelico ros...@gmail.com: That's the exact line of thinking that leads to problems. You are not placing a number at the address xyz, you are pointing the name xyz to the number 3. That number still exists

Re: [OT] Can global variable be passed into Python function?

2014-02-24 Thread Michael Torrie
On 02/24/2014 11:05 AM, j.e.ha...@gmail.com wrote: typedef struct { int value; } Number; Number *o; o = malloc(sizeof(*o)); o-value=3; printf(o%p, o-value%p\n, o, o-value); o0x9fe5008, o-value0x9fe5008 Is the compiler borked? Why would you think that? The address of the

Re: Can global variable be passed into Python function?

2014-02-24 Thread random832
On Mon, Feb 24, 2014, at 13:05, j.e.ha...@gmail.com wrote: typedef struct { int value; } Number; Number *o; o = malloc(sizeof(*o)); o-value=3; printf(o%p, o-value%p\n, o, o-value); o0x9fe5008, o-value0x9fe5008 Is the compiler borked? That's cheating. Try printf(o%p, o);

Re: [OT] Can global variable be passed into Python function?

2014-02-24 Thread random832
On Mon, Feb 24, 2014, at 13:19, Michael Torrie wrote: Why would you think that? The address of the start of your malloc'ed structure is the same as the address of the first element. Surely this is logical? And of course all this is quite off topic. That's not helpful - the problem, in

Re: Can global variable be passed into Python function?

2014-02-24 Thread Chris Angelico
On Tue, Feb 25, 2014 at 5:05 AM, j.e.ha...@gmail.com wrote: typedef struct { int value; } Number; Number *o; o = malloc(sizeof(*o)); o-value=3; printf(o%p, o-value%p\n, o, o-value); o0x9fe5008, o-value0x9fe5008 Is the compiler borked? No, because a structure in C is simply

Re: Can global variable be passed into Python function?

2014-02-24 Thread Chris Angelico
On Tue, Feb 25, 2014 at 5:20 AM, random...@fastmail.us wrote: On Mon, Feb 24, 2014, at 13:05, j.e.ha...@gmail.com wrote: typedef struct { int value; } Number; Number *o; o = malloc(sizeof(*o)); o-value=3; printf(o%p, o-value%p\n, o, o-value); o0x9fe5008, o-value0x9fe5008 Is

Re: Can global variable be passed into Python function?

2014-02-24 Thread Mark Lawrence
On 24/02/2014 18:05, j.e.ha...@gmail.com wrote: On Sunday, February 23, 2014 5:01:25 AM UTC-6, Marko Rauhamaa wrote: Chris Angelico ros...@gmail.com: That's the exact line of thinking that leads to problems. You are not placing a number at the address xyz, you are pointing the name xyz

Re: Can global variable be passed into Python function?

2014-02-23 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: The big difference is that in fixed location languages, it makes sense to talk about the address of a *variable*. The address could be a symbol, too. The Python statement xyz = 3 places a number in the address xyz. You can read the

Re: Can global variable be passed into Python function?

2014-02-23 Thread Chris Angelico
On Sun, Feb 23, 2014 at 8:52 PM, Marko Rauhamaa ma...@pacujo.net wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: The big difference is that in fixed location languages, it makes sense to talk about the address of a *variable*. The address could be a symbol, too. The Python

Re: Can global variable be passed into Python function?

2014-02-23 Thread Steven D'Aprano
On Sun, 23 Feb 2014 11:52:05 +0200, Marko Rauhamaa wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: The big difference is that in fixed location languages, it makes sense to talk about the address of a *variable*. The address could be a symbol, too. The Python statement

Re: Can global variable be passed into Python function?

2014-02-23 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: That's the exact line of thinking that leads to problems. You are not placing a number at the address xyz, you are pointing the name xyz to the number 3. That number still exists elsewhere. And? In C, I can say: Number *o = malloc(sizeof *o); o-value =

Re: Can global variable be passed into Python function?

2014-02-23 Thread Chris Angelico
On Sun, Feb 23, 2014 at 10:01 PM, Marko Rauhamaa ma...@pacujo.net wrote: As for Python, there's nothing in the Python specification that would prevent you from having, say, 63-bit integers as representing themselves. IOW, you could physically place such integers as themselves as the reference

Re: Can global variable be passed into Python function?

2014-02-23 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: On Sun, Feb 23, 2014 at 10:01 PM, Marko Rauhamaa ma...@pacujo.net wrote: As for Python, there's nothing in the Python specification that would prevent you from having, say, 63-bit integers as representing themselves. IOW, you could physically place such

Re: Can global variable be passed into Python function?

2014-02-23 Thread Chris Angelico
On Mon, Feb 24, 2014 at 2:24 AM, Marko Rauhamaa ma...@pacujo.net wrote: Or id(n) == 2 ** 64 + n for 63-bit integers; other objects get the RAM address of the internal ḿemory block: id(5) 18446744073709551621 id([]) 3074657068 id(id([])) 18446744076784207372 Assuming

Re: Can global variable be passed into Python function?

2014-02-23 Thread Terry Reedy
On 2/23/2014 6:01 AM, Marko Rauhamaa wrote: As for Python, there's nothing in the Python specification that would prevent you from having, say, 63-bit integers as representing themselves. IOW, you could physically place such integers as themselves as the reference and the number would not

Re: Can global variable be passed into Python function?

2014-02-23 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: id() is (if I recall correctly) supposed to return an integer in the native range That restriction seems beyond the scope of the language definition. Still, it can be trivially provided for. In any case, you'd need some way to pretend that every integer is

Re: Can global variable be passed into Python function?

2014-02-23 Thread Marko Rauhamaa
Terry Reedy tjre...@udel.edu: Special-casing ints to store the value in the reference has been proposed and rejected. I do not remember how far anyone went in trying to code the idea, but I doubt that anyone got as far as getting the test suite to pass. FWIW, elisp essentially does that.

Re: Can global variable be passed into Python function?

2014-02-23 Thread Mark Lawrence
On 23/02/2014 21:04, Marko Rauhamaa wrote: And thus, Python variables are barely distinguishable from C variables. To repeat what Terry Reedy said earlier, hogwash. Looks as if I've another member of my dream team, who can proudly sit alongside our self appointed resident unicode expert.

Re: Can global variable be passed into Python function?

2014-02-23 Thread Steven D'Aprano
On Sun, 23 Feb 2014 23:10:36 +0200, Marko Rauhamaa wrote: Terry Reedy tjre...@udel.edu: Special-casing ints to store the value in the reference has been proposed and rejected. I do not remember how far anyone went in trying to code the idea, but I doubt that anyone got as far as getting the

Re: Can global variable be passed into Python function?

2014-02-22 Thread wxjmfauth
# a swapping variant def swap(a, b): ... ab = [a, b] ... ab[1], ab[0] = ab[0], ab[1] ... return ab[0], ab[1] ... a = 111 id(a) 505627864 b = 999 id(b) 58278640 a, b = swap(a, b) a, id(a) (999, 58278640) b, id(b) (111, 505627864) jmf --

Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sat, Feb 22, 2014 at 7:02 PM, wxjmfa...@gmail.com wrote: # a swapping variant def swap(a, b): ... ab = [a, b] ... ab[1], ab[0] = ab[0], ab[1] ... return ab[0], ab[1] Provably identical to: def swap(a, b): return b, a The rest is just fluff. ChrisA --

Re: Can global variable be passed into Python function?

2014-02-22 Thread wxjmfauth
Le samedi 22 février 2014 09:10:02 UTC+1, Chris Angelico a écrit : On Sat, Feb 22, 2014 at 7:02 PM, wxjmfa...@gmail.com wrote: # a swapping variant def swap(a, b): ... ab = [a, b] ... ab[1], ab[0] = ab[0], ab[1] ... return ab[0], ab[1] Provably identical

Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 19:10:02 +1100, Chris Angelico wrote: On Sat, Feb 22, 2014 at 7:02 PM, wxjmfa...@gmail.com wrote: # a swapping variant def swap(a, b): ... ab = [a, b] ... ab[1], ab[0] = ab[0], ab[1] ... return ab[0], ab[1] Provably identical to: def swap(a, b):

Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 18:29:02 +1100, Chris Angelico wrote: On Sat, Feb 22, 2014 at 6:18 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Now I daresay that under the hood, Pascal is passing the address of foo (or bar) to the procedure plus, but inside plus you don't see that

Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sat, Feb 22, 2014 at 7:35 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Yep. I should have clarified that I wasn't talking about Pascal; I'm not fluent in the language (last time I did anything at all with Pascal was probably about ten years ago, and not much then). In C,

Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 09:28:10 +0200, Marko Rauhamaa wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: But your code doesn't succeed at doing what it sets out to do. If you try to call it like this: py x = 23 py y = 42 py swap(x, y) Traceback (most recent call last): File

Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sat, Feb 22, 2014 at 7:45 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: But why bother to write C in Python? Python makes a really bad C, and C makes a really bad Python. +1. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Can global variable be passed into Python function?

2014-02-22 Thread Mark Lawrence
On 22/02/2014 02:47, Dennis Lee Bieber wrote: BASIC, C, FORTRAN, COBOL, Assembly... A variable is synonym for an address [a box that holds things]. In C. int xyz = 1; xyz is placed in a register. What is xyz called now as it's not in memory? -- My fellow Pythonistas, ask not what

Re: Can global variable be passed into Python function?

2014-02-22 Thread Marko Rauhamaa
Mark Lawrence breamore...@yahoo.co.uk: On 22/02/2014 02:47, Dennis Lee Bieber wrote: BASIC, C, FORTRAN, COBOL, Assembly... A variable is synonym for an address [a box that holds things]. In C. int xyz = 1; xyz is placed in a register. What is xyz called now as it's not in memory?

Re: Can global variable be passed into Python function?

2014-02-22 Thread Dave Angel
Mark Lawrence breamore...@yahoo.co.uk Wrote in message: On 22/02/2014 02:47, Dennis Lee Bieber wrote: BASIC, C, FORTRAN, COBOL, Assembly... A variable is synonym for an address [a box that holds things]. In C. int xyz = 1; xyz is placed in a register. What is xyz called now as

Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 13:03:33 -0500, Dennis Lee Bieber wrote: As I recall, to handle garbage collection, Apple used to use two stage look ups... The user variable (handle) was a reference into a table of handles, and each entry in that table was a reference to the real object out in memory.

Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 14:15:22 +, Mark Lawrence wrote: On 22/02/2014 02:47, Dennis Lee Bieber wrote: BASIC, C, FORTRAN, COBOL, Assembly... A variable is synonym for an address [a box that holds things]. In C. int xyz = 1; xyz is placed in a register. What is xyz called

Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sun, Feb 23, 2014 at 12:39 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: In C or Pascal-style languages, what we might call the fixed address style of variables, a variable assignment like xyz = 1 does something like this: - associate the name 'xyz' with some fixed

Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sun, 23 Feb 2014 12:50:26 +1100, Chris Angelico wrote: On Sun, Feb 23, 2014 at 12:39 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: In C or Pascal-style languages, what we might call the fixed address style of variables, a variable assignment like xyz = 1 does something

Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sun, Feb 23, 2014 at 5:20 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The important thing here is not so much that we are disagreeing, but that we are talking about two different levels of explanation. (Gödel, Escher And Bach has an very interesting section about how

Re: Can global variable be passed into Python function?

2014-02-21 Thread Gary Herron
On 02/20/2014 10:37 PM, Sam wrote: I need to pass a global variable into a python function. However, the global variable does not seem to be assigned after the function ends. Is it because parameters are not passed by reference? How can I get function parameters to be passed by reference in

Re: Can global variable be passed into Python function?

2014-02-21 Thread Steven D'Aprano
On Thu, 20 Feb 2014 22:37:59 -0800, Sam wrote: I need to pass a global variable into a python function. However, the global variable does not seem to be assigned after the function ends. Is it because parameters are not passed by reference? How can I get function parameters to be passed by

Re: Can global variable be passed into Python function?

2014-02-21 Thread Jussi Piitulainen
dieter writes: Sam writes: I need to pass a global variable into a python function. Python does not really have the concept variable. What appears to be a variable is in fact only the binding of an object to a name. If you assign something to a variable, all you do is binding a

Re: Can global variable be passed into Python function?

2014-02-21 Thread Marko Rauhamaa
Jussi Piitulainen jpiit...@ling.helsinki.fi: In alleged contrast, the observable behaviour of languages that have variables is the same. This is not considered confusing by the people who insist that there are no variables in Python. But of course there are variables in Python: By

Re: Can global variable be passed into Python function?

2014-02-21 Thread Ned Batchelder
On 2/21/14 2:23 AM, dieter wrote: Samlightai...@gmail.com writes: I need to pass a global variable into a python function. Python does not really have the concept variable. What appears to be a variable is in fact only the binding of an object to a name. If you assign something to a

Re: Can global variable be passed into Python function?

2014-02-21 Thread Marko Rauhamaa
Ned Batchelder n...@nedbatchelder.com: Man, do I hate this idea that Python has no variables. It has variables (names associated with values, and the values can change over the course of the program), In classic functional programming, the values of variables can't change but they are still

Re: Can global variable be passed into Python function?

2014-02-21 Thread Travis Griggs
On Feb 21, 2014, at 4:13 AM, Ned Batchelder n...@nedbatchelder.com wrote: Man, do I hate this idea that Python has no variables. It has variables (names associated with values, and the values can change over the course of the program), they just don't work the same as C or Fortran

Re: Can global variable be passed into Python function?

2014-02-21 Thread Chris Angelico
On Sat, Feb 22, 2014 at 4:59 AM, Travis Griggs travisgri...@gmail.com wrote: What makes Python variables/bindings/references/aliases/namedvalues/slots/bucketsofstuff surprising to new arrivals from other language kingdoms, is that accessing is pragmatically implicit (walks the scope tree

Re: Can global variable be passed into Python function?

2014-02-21 Thread Marko Rauhamaa
On the question of how variables can be passed to functions, C, of course, has the operator and Pascal has the var keyword. An analogous thing can be achieved in Python 3 (but not in Python 2, I'm afraid). The operator corresponds to an ad hoc property class as in the program below (not

Python and variables (was: Can global variable be passed into Python function?)

2014-02-21 Thread Ben Finney
Ned Batchelder n...@nedbatchelder.com writes: On 2/21/14 2:23 AM, dieter wrote: Samlightai...@gmail.com writes: I need to pass a global variable into a python function. Python does not really have the concept variable. What appears to be a variable is in fact only the binding of an

<    1   2   3   >