www.digitalmars.com         C & C++   DMDScript  

D - Proposal: Multi-methods

Proposal: Multi-methods

I propose to add multi-methods to D. Is suggest the following synthax
('dispatch' gets a new keyword).

struct Shape
{...}
struct Square : Shape
{...}
struct Circle : Shape
{...}

bool dispatch (Shape x, Shape y)
{
bool overlap (Square x, Square y)
{ ... }

bool overlap (Square x, Circle y)
{ ... }

bool overlap (Circle x, Circle y)
{ ... }
}


All handlers have to have the same name. The compiler generates a dispatching
function that  chooses at runtime the correct handler depending on the Type of
the object (reflection). If  there is no handler an exception is thrown.
Jan 17 2004