can I overload operators like "=>", "->" or something like that?

Discussion in 'Python' started by dmitrey, Apr 19, 2012.

  1. dmitrey

    dmitrey Guest

    hi all,
    can I somehow overload operators like "=>", "->" or something like
    that? (I'm searching for appropriate overload for logical implication
    "if a then b")
    Thank you in advance, D.
     
    dmitrey, Apr 19, 2012
    #1
    1. Advertising

  2. On Thursday, April 19, 2012 12:28:50 PM UTC-7, dmitrey wrote:
    > hi all,
    > can I somehow overload operators like "=>", "->" or something like
    > that? (I'm searching for appropriate overload for logical implication
    > "if a then b")
    > Thank you in advance, D.


    I don't believe that you could overload those particular operators, since to my knowledge they do not exist in Python to begin with.
     
    Jacob MacDonald, Apr 19, 2012
    #2
    1. Advertising

  3. dmitrey

    alex23 Guest

    On Apr 20, 5:54 am, Jacob MacDonald <> wrote:

    > On Thursday, April 19, 2012 12:28:50 PM UTC-7, dmitrey wrote:
    > > can I somehow overload operators like "=>", "->" or something like
    > > that?


    > I don't believe that you could overload those particular operators,
    > since to my knowledge they do not exist in Python to begin with.


    It all depends on if the operators use special methods on objects:
    http://docs.python.org/reference/datamodel.html#special-method-names

    You can overload => via object.__le__, for example.
     
    alex23, Apr 20, 2012
    #3
  4. On Thursday, April 19, 2012 11:09:52 PM UTC-7, Ben Finney wrote:
    > alex23 <> writes:
    >
    > > On Apr 20, 5:54 am, Jacob MacDonald <> wrote:
    > >
    > > > On Thursday, April 19, 2012 12:28:50 PM UTC-7, dmitrey wrote:
    > > > > can I somehow overload operators like "=>", "->" or something like
    > > > > that?
    > > > I don't believe that you could overload those particular operators,
    > > > since to my knowledge they do not exist in Python to begin with.

    >
    > There is no ‘=>’ operator, and no ‘->’ operator, in Python
    > <URL:http://docs.python.org/reference/lexical_analysis.html#operators>.
    > >
    > > It all depends on if the operators use special methods on objects:
    > > http://docs.python.org/reference/datamodel.html#special-method-names
    > >
    > > You can overload => via object.__le__, for example.

    >
    > No, ‘<=’ is the less-than-or-equal operator. There is no ‘=>’operator
    > in Python.
    >
    > --
    > \ “I knew things were changing when my Fraternity Brothers threw |
    > `\ a guy out of the house for mocking me because I'm gay.” |
    > _o__) —postsecret.com, 2010-01-19 |
    > Ben Finney


    Thought so.
     
    Jacob MacDonald, Apr 20, 2012
    #4
  5. dmitrey

    Nobody Guest

    On Thu, 19 Apr 2012 12:28:50 -0700, dmitrey wrote:

    > can I somehow overload operators like "=>", "->" or something like that?
    > (I'm searching for appropriate overload for logical implication "if a then
    > b")


    You cannot create new operators, but you can control how existing
    operators work on types which you define.

    IOW, you can't define "->" or "=>", but you could define ">=" or ">>".
     
    Nobody, Apr 20, 2012
    #5
  6. Kiuhnm writes:
    > On 4/20/2012 17:50, Nobody wrote:
    > > On Thu, 19 Apr 2012 12:28:50 -0700, dmitrey wrote:
    > >
    > >> can I somehow overload operators like "=>", "->" or something
    > >> like that? (I'm searching for appropriate overload for logical
    > >> implication "if a then b")

    > >
    > > You cannot create new operators, but you can control how existing
    > > operators work on types which you define.
    > >
    > > IOW, you can't define "->" or "=>", but you could define">=" or
    > > ">>".

    >
    > You can also "overload" '<-' ;)


    Huh. If you're thinking what you just made me think, maybe x -=1> y
    could be made to work. Think of --> but Python doesn't have -- ...

    I forget whether it is just the Java people or also the Python group
    who feel very strongly that the truth values should not really be
    ordered and it is something like a bug in the language that they are.

    Because <= already works as a material implication for the built-in
    True and False to a certain extent: not for general truth values, and
    x <= y <= z does not mean x <= (y <= z), and seen as an arrow the
    symbol does feel backwards, and probably other such issues.
     
    Jussi Piitulainen, Apr 20, 2012
    #6
    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. Piotre Ugrumov
    Replies:
    3
    Views:
    375
    Nick Hounsome
    Jan 25, 2004
  2. Jason
    Replies:
    5
    Views:
    554
    John Harrison
    Feb 12, 2004
  3. Suman
    Replies:
    5
    Views:
    2,762
    Chris Theis
    Jun 14, 2006
  4. Jonas Huckestein

    Overload Operators for referenced objects?

    Jonas Huckestein, Feb 11, 2007, in forum: C++
    Replies:
    6
    Views:
    331
    Kai-Uwe Bux
    Feb 12, 2007
  5. Ying-Chieh Liao

    function overload (not operator overload)

    Ying-Chieh Liao, Oct 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    255
    Sherm Pendley
    Oct 11, 2004
Loading...

Share This Page