Wiki

Ticket #70 (new enhancement)

Opened 16 years ago

Last modified 16 years ago

Declare operator overloads.

Reported by: Chuck Owned by:
Priority: major Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

Declare operator overloads for your own classes.

Probably makes sense to do ticket:69 (consume operator overloads) first.

Also, I haven't designed a syntax for this. And it probably makes sense to review operator overloading in various languages such as C#, Python and C++. I think Java is still lacking in this area.

Change History

Changed 16 years ago by Chuck

Also, Cobra already supports a .compareTo instance method for covering all 6 comparison operators (==, <>, <=, etc.).

And one person has effectively suggested going this route by asking if the Scala approach could be used. See  http://cobra-language.com/forums/viewtopic.php?f=4&t=202&p=1092#p1092

This could also tie into the cue idea.

Changed 16 years ago by Chuck

Cues may be the way to declare operator overloads. Of course, this still has to mesh well with .NET (and any JVM conventions adopted by 3rd party languages).

There is a user proposal here:
 http://cobra-language.com/forums/viewtopic.php?f=4&t=213

Changed 16 years ago by gauthier

I would prefer op or operator keyword rather than cue

class Foo

shared

def +operator (other as Foo) as Foo

or

def +op (other as Foo) as Foo

Changed 16 years ago by Chuck

If we had a keyword, why wouldn't it replace def as in:

op + (other Foo) as Foo
    ...

Having both def and op|operator seems strange.

Note: See TracTickets for help on using tickets.