I think python only has 3 unary operations, + - and ~ and only + and -
can also be binary operations.

unary + has less uses, since it normally just passes its argument, if
valid, unchanged, but can be used to validate that its argument has the
right type. I am not sure if a type could define its own unary+ to do
something special, but I thought it could.

On 4/2/21 11:19 AM, John wrote:
> True.  It gets ambiguous when doing n*(-(x + y)) i.e. n x y + - *
> (fail).  The simplest solution is n 0 x y + - *
>
> I can't actually think of any other unary operators.
>
> On Fri, Apr 2, 2021 at 10:54 AM Richard Damon <rich...@damon-family.org> 
> wrote:
>> One problem with trying to mix RPN with in-fix is that some operators,
>> like - can be either a unary or binary operation in the in-fix
>> notations, distinguished by context. In RPN you have lost that context.
>>
>> is x y - - the same as -(x-y) or is it x-(-y) ? or is it waiting for
>> another operator and be x ?? (-(-y)) or is it expecting a previous
>> operand and is ?? - (x-y)
>>
>> (same with +)
>>
>> Typical RPN systems get around this by having unary - be a different
>> symbol/key that binary -
>>
>> --
>> Richard Damon
>>
>> _______________________________________________
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-le...@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at 
>> https://mail.python.org/archives/list/python-ideas@python.org/message/LX5T33N6IU6IMDKXU4KQMA2RP6U627CG/
>> Code of Conduct: http://python.org/psf/codeofconduct/


-- 
Richard Damon

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NCAY6SMGQJBRID7AYR6JWOTJGV7CZDGW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to