[2248] in java-interest
Re: interfaces are NO substitution for method pointers
daemon@ATHENA.MIT.EDU (Simon Spero)
Wed Sep 27 10:31:35 1995
Date: Tue, 26 Sep 1995 13:45:15 -0700 (PDT)
From: Simon Spero <ses@tipper.oit.unc.edu>
To: Ken Arnold - Sun Labs <arnold@cocolat.East.Sun.COM>
Cc: java-interest@java.Eng.Sun.COM
In-Reply-To: <9509261427.AA06257@cocolat.East.Sun.COM>
On Tue, 26 Sep 1995, Ken Arnold - Sun Labs wrote:
> I suppose I'm not as wise as Arthur -- I'm going to take *one* crack
> at trying to convince.
[subclassing to implement callbacks deleted]
This is all well and good, but it only covers one application for method
pointers. As any functional programmer or lisp hacker can tell you, there
are lots of problems that become much more elegant when functions,
particularly first class functions, are available.
I would very much like to see some support for anonymous functions added
to java - some ideas follow:
Syntax could be:
{
int y = 5;
List l = getAListOfInts();
List l2 = l.map(int lambda(int x) -> {return x + y;});
}
Class List {
...
List map(Function f) {
if(cdr == null) {
return cons(f.funcall(car),null);
} else {
return cons(f.funcall(car),cdr.map(f))
}
}
}
----
This would be transformed into
class Function92010 implements Function_int__int, Function_1 {
int y;
public Function92010(int y_in) {
y = y_in;
}
public int funcall(int x) {
return x + y;
}
};
{
int y = 5;
List l = getListOfInts();
List l2 = l.map( new Function92010(y));
}
class List {
List map(Function_1 f) {
if(cdr == null) {
return cons(f.funcall(car),null);
} else {
return cons(f.funcall(car),cdr.map(f))
}
}
};
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com