Re: Possible constant assignment operators := and ::= for Python

2006-05-17 Thread Steve Holden
Piet van Oostrum wrote: Edward Elliott [EMAIL PROTECTED] (EE) wrote: EE Piet van Oostrum wrote: [EMAIL PROTECTED] (T) wrote: T As you can see, the constant A can be modified this easily. But if T there were an intuitive mechanism to declare a symbol to be immutable, T then there won't be

Re: Possible constant assignment operators := and ::= for Python

2006-05-15 Thread Piet van Oostrum
Edward Elliott [EMAIL PROTECTED] (EE) wrote: EE Piet van Oostrum wrote: [EMAIL PROTECTED] (T) wrote: T As you can see, the constant A can be modified this easily. But if T there were an intuitive mechanism to declare a symbol to be immutable, T then there won't be this problem. Mutability

Re: Possible constant assignment operators := and ::= for Python

2006-05-12 Thread Piet van Oostrum
[EMAIL PROTECTED] (T) wrote: T As you can see, the constant A can be modified this easily. But if T there were an intuitive mechanism to declare a symbol to be immutable, T then there won't be this problem. Mutability is not a property of symbols but of values. So it doesn't make sense to

Re: Possible constant assignment operators := and ::= for Python

2006-05-12 Thread Edward Elliott
Piet van Oostrum wrote: [EMAIL PROTECTED] (T) wrote: T As you can see, the constant A can be modified this easily. But if T there were an intuitive mechanism to declare a symbol to be immutable, T then there won't be this problem. Mutability is not a property of symbols but of values. So it

Re: Possible constant assignment operators := and ::= for Python

2006-05-09 Thread Christophe
Fredrik Lundh a écrit : Christophe wrote: I think you've made a mistake in your example. constant A = [] def foo(var): ... var.append('1') ... print var ... b = A foo(b) foo(b) and this ? constant A = [] print A

Re: Possible constant assignment operators := and ::= for Python

2006-05-05 Thread Michele Simionato
Edward Elliott wrote: Michele Simionato wrote: A = [] # let's declare a constant here b = A # and let's assign the constant here b.append('1') # OOPS! But it makes no sense to use a mutable object for a constant! The user should use a tuple, Sure. Now show me the builtin

Re: Possible constant assignment operators := and ::= for Python

2006-05-05 Thread Fredrik Lundh
Christophe wrote: I think you've made a mistake in your example. constant A = [] def foo(var): ... var.append('1') ... print var ... b = A foo(b) foo(b) and this ? constant A = [] print A is A Obviously, False. why

Re: Possible constant assignment operators := and ::= for Python

2006-05-04 Thread Fredrik Lundh
Christophe wrote: That's easy, since A is a symbolic constant know at compile time, and since it's a known mutable objet, the code once compiled will be equivalent to: b = [[]] # much later b|0].append('1') the OP talked about constants as names for immutable objects, not pre-

Re: Possible constant assignment operators := and ::= for Python

2006-05-04 Thread Christophe
Fredrik Lundh a écrit : Christophe wrote: That's easy, since A is a symbolic constant know at compile time, and since it's a known mutable objet, the code once compiled will be equivalent to: b = [[]] # much later b|0].append('1') the OP talked about constants as names for

Re: Possible constant assignment operators := and ::= for Python

2006-05-04 Thread Michele Simionato
Edward Elliott wrote: Michele Simionato wrote: Python solution is to rely on the intelligence of programmers. If they see an all caps name and then they try to change it without knowing what they are doing, then they are stupid. If you have stupid programmers there is no way the language

Re: Possible constant assignment operators := and ::= for Python

2006-05-04 Thread Edward Elliott
Michele Simionato wrote: A = [] # let's declare a constant here b = A # and let's assign the constant here b.append('1') # OOPS! But it makes no sense to use a mutable object for a constant! The user should use a tuple, Sure. Now show me the builtin immutable equivalent of a dict.

Re: Possible constant assignment operators := and ::= for Python

2006-05-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Bruno Desthuilliers wrote: [EMAIL PROTECTED] a écrit : Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing constants in Python

Re: Possible constant assignment operators := and ::= for Python

2006-05-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Yes, I know that constant A will also be modified as the b[0] points to A. Obviously the [] should be marked as immutable, as A is declared to be constant thus immutable. If somebody tries to modify this immutable object an error would occur. When I further

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: For example: A = [] # let's declare a constant here b = A # and let's assign the constant here b.append('1') # OOPS! c = A print A ['1'] print b ['1'] print c ['1'] As you can see, the constant A can be modified this easily. But if there were an

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread tsaar2003
Yes, I know that constant A will also be modified as the b[0] points to A. Obviously the [] should be marked as immutable, as A is declared to be constant thus immutable. If somebody tries to modify this immutable object an error would occur. When I further thought about this problem with

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: Yes, I know that constant A will also be modified as the b[0] points to A. Obviously the [] should be marked as immutable, as A is declared to be constant thus immutable. If somebody tries to modify this immutable object an error would occur. so a constant

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread tsaar2003
are you sure you know how Python's object model work ? if you do, please explain your proposal in terms of what needs to be changed, rather than in terms of wishful thinking. No, I do not know. As stated in my first post, I am quite newbie in Python and miss a simple and intuitive mechanism

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread Christophe
Fredrik Lundh a écrit : [EMAIL PROTECTED] wrote: For example: A = [] # let's declare a constant here b = A # and let's assign the constant here b.append('1') # OOPS! c = A print A ['1'] print b ['1'] print c ['1'] As you can see, the constant A can be modified this easily. But if

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread Michele Simionato
[EMAIL PROTECTED] wrote: As stated in my first post, I am quite newbie in Python and miss a simple and intuitive mechanism that would allow to declare something as constant and that would protect these constant objects from accidental modifications. T.S. Python solution is to rely on the

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread Edward Elliott
Michele Simionato wrote: Python solution is to rely on the intelligence of programmers. If they see an all caps name and then they try to change it without knowing what they are doing, then they are stupid. If you have stupid programmers there is no way the language can stop them for making

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread Edward Elliott
[EMAIL PROTECTED] wrote: What I'd like to see here is that b gets a copy of A so that the original A won't be modified as we play with b. However, as we assign a constant value A to b, I wouldn't want to restrict myself from playing with b. If A is a list you can take a copy-slice liek this:

Re: Possible constant assignment operators := and ::= for Python

2006-05-03 Thread Diez B. Roggisch
Edward Elliott wrote: Michele Simionato wrote: Python solution is to rely on the intelligence of programmers. If they see an all caps name and then they try to change it without knowing what they are doing, then they are stupid. If you have stupid programmers there is no way the language can

Re: Possible constant assignment operators := and ::= for Python

2006-05-02 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing constants in Python language. Why so ? I guess you're talking about

Re: Possible constant assignment operators := and ::= for Python

2006-05-02 Thread tsaar2003
Bruno Desthuilliers wrote: [EMAIL PROTECTED] a écrit : Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing constants in Python language. Why so ?

Possible constant assignment operators := and ::= for Python

2006-04-28 Thread tsaar2003
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing constants in Python language. There are some workarounds available, for example the const-module. To me,