[IronPython] prefix postfix bug

Kurt Harriger kurtharriger at comcast.net
Thu Jun 8 05:40:34 CEST 2006


Okay, that makes sense.  I wouldn't normally use the prefix operator in an
expression, and I'm guessing not many people do so I wasn't all that
surprised no one had found it yet.  I just kind of stumbled on it by
accident and thought the behavior unusual; I would have expected a syntax
error if ++ wasn't supported (and I did get an error when trying postfix at
the end of the line but it didn't occur to me it was because ++ wasn't a
valid operator)!
 
Thanks,

- Kurt

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Dino Viehland
> Sent: Wednesday, June 07, 2006 8:33 PM
> To: Discussion of IronPython
> Subject: Re: [IronPython] prefix postfix bug
> 
> Have you tried this in Cpython?  ++ doesn't exist in Python.  So what
> you're really doing is:
> 
> print a + (+(+(+(+b))))
> 
> Yep, b sure is positive!
> 
> and ++b is the same thing +(+b)
> 
> and a++ of course makes no sense, because there's no right hand side to
> the plus operator.
> 
> This might make more sense if you replace b with a number, like 1, where
> might almost occasionally expect the + operator to be used in front of it,
> for some reason.
> 
> Results from CPython:
> >>> a =2 ; b = 6
> >>> print a++ + ++b
> 8
> >>> print ++b
> 6
> >>> print a++
>   File "<stdin>", line 1
>     print a++
>             ^
> SyntaxError: invalid syntax
> >>> import sys
> >>> sys.version
> '2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]'
> >>>
> ________________________________
> From: users-bounces at lists.ironpython.com On Behalf Of
> kurtharriger at comcast.net
> Sent: Wednesday, June 07, 2006 7:21 PM
> To: users at lists.ironpython.com
> Subject: [IronPython] prefix postfix bug
> 
> a = 2; b=6;
> print a++ + ++b  #prints 8
> print ++b            #prints 6
> print a++           #syntax error (at least when using console)
> 
> 
> - Kurt





More information about the Ironpython-users mailing list