atom feed13 messages in net.java.openjdk.closures-devRe: related link
FromSent OnAttachments
Neal GafterFeb 7, 2010 9:10 am 
John NilssonFeb 7, 2010 2:50 pm 
Neal GafterFeb 7, 2010 3:36 pm 
John NilssonFeb 8, 2010 9:20 am 
Neal GafterFeb 8, 2010 11:03 am 
John NilssonFeb 8, 2010 2:44 pm 
Neal GafterFeb 8, 2010 3:34 pm 
John RoseFeb 9, 2010 11:21 am 
John NilssonFeb 9, 2010 12:21 pm 
John NilssonFeb 9, 2010 12:50 pm 
Neal GafterFeb 9, 2010 1:05 pm 
John NilssonFeb 9, 2010 1:51 pm 
Neal GafterFeb 9, 2010 1:54 pm 
Subject:Re: related link
From:John Nilsson (jo@milsson.nu)
Date:Feb 8, 2010 2:44:31 pm
List:net.java.openjdk.closures-dev

On Mon, Feb 8, 2010 at 8:03 PM, Neal Gafter <ne@gafter.com> wrote:

If you want to continue this discussion, please join the closures-dev mailing list.

done

Inlining at compile-time only works for very restricted kinds of APIs, and excludes many interesting and useful APIs that could be written using transparent lambdas. See, for example, my blog post on concurrent loops < http://gafter.blogspot.com/2006/10/concurrent-loops-using-java-closures.html

,

A quick and dirty pretend syntax (didn't really spend too much time thinking about concurrency, but I'm assuming that any issues can be address within the macro construct).

I'm assuming some kind of name-mangling for the names introduced by the macro, except for the ones supplied by the caller which are simply inserted at the obvious places.

public macro <T> forEachConcurrently(T retT : Iterable<T> iter, ExecutorService threadPool) {void} block { final Collection<Callable<Object>> tasks = new ArrayList<Callable<Object>>(); final Collection<Future<Object>> futures = new ArrayList<Future<Object>(); for(final T t : iter) { tasks.add(Executors.callable(new Runnable(){public void run() { try { retT = t; block; } continue { //Noop } break { for(Future<Object> f : futures) f.cancel(); } return { for(Future<Object> f : futures) f.cancel(); } }})); } try { futures.addAll(threadPool.invokeAll(tasks)); } catch (InterruptedException ex) {} }

which has been implemented by Mark Mahieu <http://markmahieu.blogspot.com/2008/08/for-eachconcurrently.html>. That is just not possible with the approach you suggest. Inlining also undermines binary compatibility, which is one of Java's strengths.

Hmm. I don't think I see the problem.

FYI, experience with languages that support "non-local return" (Scala, Ruby, etc) has resulted in a remarkable absence of scary things happening. They're really quite boring and ordinary once you try them.

I guess you are right. But I still feel uneasy about it. The current closure semantics of java allows me to think (am I wrong?) that the stack frame and everything related to it will be completely forgotten once the method returns. What happens to stack frames to which we can return from closures that has been saved away? Is it saved away as a continuation? Are they garbage collected? Will lots of deeply nested calls pollute my heap if I don't allow the lambdas to get garbage collected? Do I need to worry about these things?

For writings about the expressive power of transparent lambdas, one

place to start would be Steele and Sussman's 1970's "Lambda the Ultimate..." papers < http://en.wikipedia.org/wiki/History_of_the_Scheme_programming_language#The_Lambda_Papers

Thanks for the pointer!

BR, John