« Return to Thread: Overloading comparison operators
By the way, I'd be curious to know what you have in mind?
What kind of DSL you would write with these operators?
--
On Thu, Jul 17, 2008 at 11:03 AM, Jörg Staudemeyer
<jstaudemeyer@...> wrote:
> Hi
>
> are there any plans to change handling of comparison operators in a later
> version of Groovy?
>
> Currently, comparison operators only apply to classes that implement the
> Comparable interface and are mapped to the compareTo() method. compareTo()
> method must return an integer value, as dictated by the interface, but the
> result of a comparison expression is always boolean.
>
> IMO this is not consistent with handling of other operators like + and <<
> that always map to a specific method returning an arbitrary result value. As
> a result, usage of comparison operators in DSLs is quite restricted.
>
> What I would like to have is something like this:
>
> a < b ==> a.smallerThan(b)
> a =<b ==> a.smallerThanEqualOrEqualTo(b)
> a!=b ==> a.notEqualTo(b)
>
> and so on. All this methods should normally return a boolean value, but in
> certain circumstances, like in a DSL, can also return something else.
>
> Implement this should not be particularly difficult, one could simply create
> default implementations of these methods for Comparable in
> DefaultGroovyMethods doing something constistent with current behaviour.
>
> What do you think?
>
> -Jörg
>
>
Guillaume Laforge
Groovy Project Manager
G2One, Inc. Vice-President Technology
http://www.g2one.com
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
« Return to Thread: Overloading comparison operators
| Free embeddable forum powered by Nabble | Forum Help |