Tech Support > Computers & Technology > Programming > Multiple Dispatch and First Class Functions
Multiple Dispatch and First Class Functions
Posted by Michael Mellor on October 20th, 2004


I am currently looking at designing a language with multiple dispatch
and first class functions.

In this example what should be returned by "return bar;"?
function foo ( ) {
function bar ( int var ) {
}

function bar ( float var ) {
}

return bar;
}

If this is allowed and returns "both 'bar's" then it allows complicated
sceanarios like:

function foo ( ) {
i = 0;
function bar ( float var ) {
i = 1;
return i;
}

function foo2 ( ) {
function bar ( int var ) {
return i;
}
return bar;
}
return foo2();
}

a = foo();
a(1); // returns 0
a(1.0); // returns 1
a(1); // returns 1


Does any one know of a programming language which has this? and how it
is dealt with?

Regards,

Mike

Posted by MSCHAEF.COM on October 20th, 2004


In article <41768b2f$0$22880$cc9e4d1f@news-text.dial.pipex.com>,
Michael Mellor <news-at-@michaelmellor-dot-.com> wrote:
Off the cuff, I'd suggest a function that includes both definitions of
bar and can pick between the two appropriately.

Have you looked at Lisp/CLOS? It has a generic function mechanism,
although I don't know how it interacts with lexical scoping.

-Mike
--
http://www.mschaef.com


Similar Posts