logo       

RE: Overloading !=: msg#00032

lang.jython.user

Subject: RE: Overloading !=

Apologies, bitwise not is the "~" symbol.
Meaning I'll have to implement __invert__(..)
Still, are there any plans in Jython to
allow overloading of the logical operators?

This would be more intuitive to users of my exposed API e.g:

>>>CD3 = CD1 > 5 and not CD2 > 10 #better than
>>>CD3 = (CD1 > 5) & ~(CD2 > 10) #i know this can be expressed differently
;-)

Thankyou,
Ant

-----Original Message-----
From: A Bewes
Sent: Friday, February 14, 2003 1:38 PM
To: 'Oti'; A Bewes; jython-users@xxxxxxxxxxxxxxxxxxxxx
Subject: RE: [Jython-users] Overloading !=


Thanks for the "!=" == __ne__(..) pointer!

How about __and__(..) and __or__(..) and __not__(..)?
I would like to mimic the operators "and", "or" and "not",
however I've found these mimic the bitwise "&" and "|" operators
rather than the boolean ones.

I'm happy with this as my implementing class holds an arrays of
1's and 0's so the overall class would have meaning with "&" and "|".

The next obvious question is how do I provide a 'symbolic' not operator?
Is there not a bitwise one?

Yours confused,
Ant

-----Original Message-----
From: Oti [mailto:ohumbel@xxxxxxxxx]
Sent: Thursday, February 13, 2003 8:33 PM
To: A Bewes; jython-users@xxxxxxxxxxxxxxxxxxxxx
Subject: Re: [Jython-users] Overloading !=


[ A Bewes ]
> I've implemented __eq__() and __not__():
> so how come I can't evaluate != operator in Jython?
>
> public class CurveData
> {
> <...>
> public CurveData __eq__(Object obj)
> {
> return MathsAPI.eq(this,obj);
> }
> public CurveData __not__()
> {
> return MathsAPI.not(this);
> }
> }

Hello Ant,

IMHO __not__() is not a special method, i suggest implementing __ne__()
instead. Please find below some methods of an interface I use to
implement for java classes participating in rich comparisons.

/** <code><</code> */
public boolean __lt__( Object other );

/** <code><=</code> */
public boolean __le__( Object other );

/** <code>></code> */
public boolean __gt__( Object other );

/** <code>>=</code> */
public boolean __ge__( Object other );

/** <code>==</code> */
public boolean __eq__( Object other );

/** <code>!=</code> */
public boolean __ne__( Object other );

You might also want to implement __nonzero__(). JythonEssentials,
around page 100, gives you more information about special methods.
A little warning: not all special methods implemented by java classes
are called by Jython (see the thread starting here
http://aspn.activestate.com/ASPN/Mail/Message/Jython-dev/1415861 for a
discussion).

Best wishes,
Oti.

__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com


-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte
are you planning your Web Server Security? Click here to get a FREE
Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
_______________________________________________
Jython-users mailing list
Jython-users@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/jython-users


-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte
are you planning your Web Server Security? Click here to get a FREE
Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise