Re: semantics of ** (unexpected/inconsistent?)

2009-12-07 Thread Albert van der Horst
In article 87eingrbh9@benfinney.id.au, Ben Finney ben+pyt...@benfinney.id.au wrote: Lie Ryan lie.1...@gmail.com writes: I generally do not expect operator precedence to be reliable at all Have another read of the thread. The OP's confusion was not over operator precedence, but over how

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Gregory Ewing
Esmail wrote: Wow .. never heard of Concatenative_languages languages before or the distinction you make. Your distinction explains the behavior, but I find it somewhat counter-intuitive. You shouldn't find it any more surprising than the fact that a = 2 + 3 print a * 5 gives a

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread inhahe
one point of confusion could be the use of ** instead of superscript. it might make things a little bit more counterintuitive-looking than with superscripts, since the issue with would only apply to exponents, as -5*4 and a = -5 a*4 return the same answer, and superscripts make it a little

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread MRAB
Lie Ryan wrote: On 11/30/2009 12:38 PM, Esmail wrote: Thanks all!! I get it now :-) It helped to have a number of different explanations, thanks for taking the time to post. Much appreciated. I generally do not expect operator precedence to be reliable at all except for: + - (binary ops,

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Chris Rebert
On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Esmail wrote: Wow .. never heard of Concatenative_languages languages before or the distinction you make. Your distinction explains the behavior, but I find it somewhat counter-intuitive. You shouldn't find

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread inhahe
On Mon, Nov 30, 2009 at 1:53 PM, Chris Rebert c...@rebertia.com wrote: On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Esmail wrote: Wow .. never heard of Concatenative_languages languages before or the distinction you make. Your distinction explains the

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Lie Ryan
On 12/1/2009 5:58 AM, inhahe wrote: i wasn't suggesting it as a feature for python, just pointing out why it might seem counterintuitive. I'm interested, what do YOU (inhahe) think the result should be? Should both become -9 or both become 9. What was your expectation when you wrote that

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Brian J Mingus
On Sun, Nov 29, 2009 at 5:58 PM, Esmail ebo...@hotmail.com wrote: Brian J Mingus wrote: I think you answered your own question. 3**2 comes first in the order of operations, followed by the negation. No, that's not the problem, I'm ok with the operator precedence of - vs ** My problem

Characters in arithmetic expressions (was: semantics of ** (unexpected/inconsistent?))

2009-11-30 Thread Ben Finney
MRAB pyt...@mrabarnett.plus.com writes: Most programming languages don't differentiate in text between the number negative 3 and the expression negated 3. APL does. The former is written as ¯3 (3 preceded by the overscore character) and the latter as -3 (3 preceded by the minus sign). Well,

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread inhahe
On Mon, Nov 30, 2009 at 2:05 PM, Lie Ryan lie.1...@gmail.com wrote: On 12/1/2009 5:58 AM, inhahe wrote: i wasn't suggesting it as a feature for python, just pointing out why it might seem counterintuitive. I'm interested, what do YOU (inhahe) think the result should be? Should both become

semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Esmail
Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. -3**2 -9 x = -3 x**2 9 I would have expected the same result in both cases. Initially I would have expected -3**2

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Brian J Mingus
On Sun, Nov 29, 2009 at 5:39 PM, Esmail ebo...@hotmail.com wrote: Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. -3**2 -9 x = -3 x**2 9 I would have

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Chris Rebert
On Sun, Nov 29, 2009 at 4:39 PM, Esmail ebo...@hotmail.com wrote: Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. -3**2 -9 x = -3 x**2 9 I would have

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Esmail
Brian J Mingus wrote: I think you answered your own question. 3**2 comes first in the order of operations, followed by the negation. No, that's not the problem, I'm ok with the operator precedence of - vs ** My problem is why I don't get the same result if I use the literal -3 or a

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Esmail
Chris Rebert wrote: _No_, because using the variable evaluates -3 as a unit separately by itself, before the exponentiation ever occurs; it's the same as the difference between (-3)**2 and -3**2. Python is not a concatenative programming language[*]; you can't directly textually replace a

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Colin W.
On 29-Nov-09 19:50 PM, Chris Rebert wrote: On Sun, Nov 29, 2009 at 4:39 PM, Esmailebo...@hotmail.com wrote: Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. -3**2 -9

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Martin v. Löwis
I think you answered your own question. 3**2 comes first in the order of operations, followed by the negation. No, that's not the problem, I'm ok with the operator precedence of - vs ** My problem is why I don't get the same result if I use the literal -3 or a variable that contains -3 (x

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread The Music Guy
It's just like in algebra. You evaluate exponents before the - which, after all, is just another way to write -1, or times-negative-one. However, a variable with a negative value is not the same as a value that is being multiplied by a negative. -3 ** 2 = (-1)(3)^(2) in algebraic terms.

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Ben Finney
Esmail ebo...@hotmail.com writes: Brian J Mingus wrote: I think you answered your own question. 3**2 comes first in the order of operations, followed by the negation. No, that's not the problem, I'm ok with the operator precedence of - vs ** My problem is why I don't get the same

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Alf P. Steinbach
* Esmail: Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. -3**2 -9 x = -3 x**2 9 I would have expected the same result in both cases. Initially I would have

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Mel
Esmail wrote: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. -3**2 -9 x = -3 x**2 9 I would have expected the same result in both cases. Initially I would have expected -3**2

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Esmail
Thanks all!! I get it now :-) It helped to have a number of different explanations, thanks for taking the time to post. Much appreciated. Cheers, Esmail -- http://mail.python.org/mailman/listinfo/python-list

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Lie Ryan
On 11/30/2009 12:38 PM, Esmail wrote: Thanks all!! I get it now :-) It helped to have a number of different explanations, thanks for taking the time to post. Much appreciated. I generally do not expect operator precedence to be reliable at all except for: + - (binary ops, not the unary) *

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Ben Finney
Lie Ryan lie.1...@gmail.com writes: I generally do not expect operator precedence to be reliable at all Have another read of the thread. The OP's confusion was not over operator precedence, but over how names resolve to values in expressions. -- \ “Life does not cease to be funny when

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread inhahe
On Sun, Nov 29, 2009 at 8:04 PM, Esmail ebo...@hotmail.com wrote: Chris Rebert wrote: Wow .. never heard of Concatenative_languages languages before or the distinction you make. Your distinction explains the behavior, but I find it somewhat counter-intuitive. (I use the Python interpreter