Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: semantics of ** (unexpected/inconsistent?)

Reply
Thread Tools

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

 
 
Esmail
Guest
Posts: n/a
 
      11-30-2009
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 variable with its value and expect to get
> the same result from an expression. For instance, in this case, you
> need to add the parentheses.
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
>[*] http://en.wikipedia.org/wiki/Concatenative_language


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 frequently
for small calculations - otherwise I'd never have realized this)

Thanks,

Esmail

 
Reply With Quote
 
 
 
 
Gregory Ewing
Guest
Posts: n/a
 
      11-30-2009
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 different result from

print 2 + 3 * 5

--
Greg
 
Reply With Quote
 
 
 
 
inhahe
Guest
Posts: n/a
 
      11-30-2009
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 easier to
associate the exponent value with the base more than with the - before
it.

On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing
<(E-Mail Removed)> 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 it any more surprising than the fact that
>
> *a = 2 + 3
> *print a * 5
>
> gives a different result from
>
> *print 2 + 3 * 5
>
> --
> Greg
> --
> http://mail.python.org/mailman/listinfo/python-list
>

 
Reply With Quote
 
Chris Rebert
Guest
Posts: n/a
 
      11-30-2009
> On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing
> <(E-Mail Removed)> 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 it any more surprising than the fact that
>>
>> ┬*a = 2 + 3
>> ┬*print a * 5
>>
>> gives a different result from
>>
>> ┬*print 2 + 3 * 5


On Mon, Nov 30, 2009 at 3:41 AM, inhahe <(E-Mail Removed)> wrote:
> 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


Well, since source code is almost universally just plain ASCII and not
in some file format with typesetting, superscripts aren't going to
happen any time soon.
(Also, avoid top-posting in the future.)

Cheers,
Chris
--
http://blog.rebertia.com
 
Reply With Quote
 
inhahe
Guest
Posts: n/a
 
      11-30-2009
On Mon, Nov 30, 2009 at 1:53 PM, Chris Rebert <(E-Mail Removed)> wrote:
>> On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing
>> <(E-Mail Removed)> 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 it any more surprising than the fact that
>>>
>>> *a = 2 + 3
>>> *print a * 5
>>>
>>> gives a different result from
>>>
>>> *print 2 + 3 * 5

>
> On Mon, Nov 30, 2009 at 3:41 AM, inhahe <(E-Mail Removed)> wrote:
>> 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

>
> Well, since source code is almost universally just plain ASCII and not
> in some file format with typesetting, superscripts aren't going to
> happen any time soon.
> (Also, avoid top-posting in the future.)
>


i wasn't suggesting it as a feature for python, just pointing out why
it might seem counterintuitive.
 
Reply With Quote
 
Lie Ryan
Guest
Posts: n/a
 
      11-30-2009
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 post?
 
Reply With Quote
 
inhahe
Guest
Posts: n/a
 
      11-30-2009
On Mon, Nov 30, 2009 at 2:05 PM, Lie Ryan <(E-Mail Removed)> 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 -9 or both become 9. What was your expectation when you wrote that
> post?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


i think the way it works currently is the sane way..pays respect to
the standard order of operations, doesn't have to do anything special
with x = -3, just treats it as an integer, and corresponds with normal
algebra.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
it's all about semantics =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?= ASP .Net 2 07-14-2004 08:19 AM
Semantics extractor Luigi Donatello Asero HTML 5 02-14-2004 07:10 PM
Equivalency Semantics, Operator Overloading Grant Austin C++ 3 12-09-2003 05:03 PM
std::vector<>::clear semantics Stefan H÷hne C++ 10 10-17-2003 09:50 AM
destructor / semantics of delete this Alexander Stippler C++ 6 08-20-2003 03:27 PM



Advertisments