[cap-talk] Last Call for ref_send API 1.0
Sandro Magi
smagi at higherlogics.com
Wed Apr 4 07:53:21 CDT 2007
Dean Tribble wrote:
> > Closure is a very common concept that is only loosely reflected it the
> > decalred interface.
> Errr.. "only loosely". Please explain.
>
>
> Closures are not generally restricted to a one argument, and generally
> contain a pair of a function and an environment.
SML functions are single-argument with multiple arguments supported via
tuples; this is more or less what ref_send does. You could define
explict tuples (Pair, Triple, ..., Nuple), but an array as in ref_send
works as well.
The environment of a closure is its private state (object's fields). So
I believe this is as close of a match as is possible in Java.
> This Closure reflects
> neither the typical closure interface (in which different closurs have
> different signatures) nor does it implement any typical closure
> behavior. All it does is define a signature for a single-argument
> function (which may or may not be implemented to close over anything).
> The concepts are related, but only loosely. Delegates in C#, for
> example, are much closure to traditional ( e.g., Scheme) closures.
Yes, C# delegates are closures, but they're only "closer" because
there's more direct compiler support/syntactic sugar:
//delegate of type Converter<int,int> for instance
int b=1;
return delegate(int a) {return a+b;}
I don't see how this is conceptually different to:
final int b=1;
return new Closure<int,int>() {
int post(int arg) { return b + arg; } };
Adding first-class functions to an OO language generally involves
defining a distinguished interface with a single 'apply' method, which
is exactly this. I don't see why Microsoft didn't take this approach
with .NET in fact; would have simplified the concepts and the VM.
Sandro
More information about the cap-talk
mailing list