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

Discussion in 'Python' started by Esmail, Nov 30, 2009.

  1. Esmail

    Esmail Guest

    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
     
    Esmail, Nov 30, 2009
    #1
    1. Advertising

  2. 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
     
    Gregory Ewing, Nov 30, 2009
    #2
    1. Advertising

  3. Esmail

    inhahe Guest

    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
    <> 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
    >
     
    inhahe, Nov 30, 2009
    #3
  4. Esmail

    Chris Rebert Guest

    > On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing
    > <> 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 <> 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
     
    Chris Rebert, Nov 30, 2009
    #4
  5. Esmail

    inhahe Guest

    On Mon, Nov 30, 2009 at 1:53 PM, Chris Rebert <> wrote:
    >> On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing
    >> <> 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 <> 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.
     
    inhahe, Nov 30, 2009
    #5
  6. Esmail

    Lie Ryan Guest

    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?
     
    Lie Ryan, Nov 30, 2009
    #6
  7. Esmail

    inhahe Guest

    On Mon, Nov 30, 2009 at 2:05 PM, Lie Ryan <> 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.
     
    inhahe, Nov 30, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=

    it's all about semantics

    =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=, Jul 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    343
    =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=
    Jul 14, 2004
  2. Luigi Donatello Asero

    Semantics extractor

    Luigi Donatello Asero, Feb 14, 2004, in forum: HTML
    Replies:
    5
    Views:
    553
    Eric Bohlman
    Feb 14, 2004
  3. Esmail
    Replies:
    2
    Views:
    294
  4. Esmail
    Replies:
    3
    Views:
    311
    Albert van der Horst
    Dec 6, 2009
  5. Jon
    Replies:
    3
    Views:
    230
    Ray at
    Oct 29, 2003
Loading...

Share This Page