Mark Derricutt's Disturbing Thoughts

My Top Tags

                                       

My Jaiku

Chrome Division – Doomsday Rider

Thursday, 21 August 2008 5:43 A GMT+12

1 Session per VM: Another Scaling Alternative

Wednesday, 20 August 2008 9:47 P GMT+12

The BGGA myth - Functional Java | Google Groups

Wednesday, 20 August 2008 7:33 A GMT+12

Spock's Beard – On A Perfect Day (live)

Wednesday, 20 August 2008 5:57 A GMT+12

Ola Bini: JtestR 0.3.1 Released

Tuesday, 19 August 2008 10:00 P GMT+12

Enslaved – Violet Dawning

Tuesday, 19 August 2008 6:14 A GMT+12

Distributed Messaging with Jetlang and Terracotta

Monday, 18 August 2008 10:17 P GMT+12

The Music of 2008 - week 33

Monday, 18 August 2008 8:57 A GMT+12

There Can Be Only One

Monday, 18 August 2008 8:10 A GMT+12

Search Box

 

Pascal gets closures before java - why hasn't the world ended?

posted Friday, 25 July 2008

So I see Delphi now has generics and closures in its upcoming "Tiburon" release:

type
  // method reference
  TProc = reference to procedure(x: Integer);               

procedure Call(const proc: TProc);
begin
  proc(42);
end;

Use:

var
  proc: TProc;
begin
  // anonymous method
  proc := procedure(a: Integer)
  begin
    Writeln(a);
  end;               

  Call(proc);
  readln
end.

I'd have loved have had both of these features back in the day when I was still doing Delphi. As much as I no longer like the Pascal syntax, I love how cleanly the anonymous method declaration sits within the natural flow of things (although I'm not sure an inline method directly on the call to Call() would sit well).

My only question is, if Pascal can evolve why can't java?

Sure the Tiburon release can do this because the underlying .NET VM now supports the functionality, but thats not the point. Ok?

tags:      

links: digg this    del.icio.us    technorati    reddit




1. Chris Broadfoot left...
Saturday, 26 July 2008 12:17 am :: http://chrisbroadfoot.id.au

I'm sure Java will get some form of closure/anonymous function sometime. Whether it will be ghastly is a large possibility, though.

PS: This commenting system is way too complex!


2. pcdinh left...
Saturday, 26 July 2008 7:44 pm

Closure is a cool feature. It has made a way to PHP 5.3 already.


3. Shams Mahmood left...
Monday, 28 July 2008 3:58 am :: http://shamsmi.blogspot.com/

I'm skeptical about how useful closures will be after they are introduced in java. I'm afraid people will get carried away and misuse the feature, I have a similar feeling about java reflection.

P.S. What's with the red font color in the comment form?


4. Radoslav Stankov left...
Monday, 28 July 2008 8:43 am :: http://next.pixeldepo.com

As far as I know closures in JAVA are now under discussion. And for know the inner class are used as some sort of closures.


5. Charmless left...
Monday, 28 July 2008 10:34 am

That example doesn't display use of closures. No state was carried by the method object - it didn't "close around" any values.


6. Filip left...
Monday, 28 July 2008 10:59 am

It will be even better than you think. Anonymous method and generics will be added also to native Delphi (not Net version). So it is done without net vm help.


7. Chris left...
Monday, 28 July 2008 12:26 pm :: http://www.ijw.co.nz

Delphi has had inner functions that can refer to their enclosing lexical scope since at least 5.0. Unfortunately, you couldn't take the address of them.


8. Barry Kelly left...
Monday, 28 July 2008 4:43 pm :: http://barrkel.blogspot.com/

Disclosure: I'm an engineer working on the Delphi compiler, and I've been primarily responsible for the implementation of anonymous methods (as we're calling our version of closures).

To clarify: anonymous methods are supported for Win32 only, using reference counting for state management (since closures can contain captured state).

@Charmless: Our anonymous methods are indeed full closures, and they capture state - it's just that this example doesn't show that.


9. El Cy left...
Monday, 28 July 2008 7:02 pm

The new anonymous method in Delphi has no relation to the .NET since Tiburon will be a release that will entirely focus on Win32.... It seams this is the first step towards a LINQ style enabling in both Win32 & .NET Delphi ...


10. Arconan left...
Tuesday, 29 July 2008 11:08 pm :: http://www.arconan.net

I agree with Shams, and to continue I personally don't think it belongs in an OO Language like Java. I am still finding it pretty hard to figure out what benefits a closure provides over a simple private method....