From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Tolpin Message-Id: <200403021606.i22G6vl9074244@adat.davidashen.net> To: 9fans@cse.psu.edu Subject: Re: [9fans] Re: advantages of limbo In-Reply-To: Content-Type: text/plain; charset=KOI8-R Date: Tue, 2 Mar 2004 20:06:57 +0400 Topicbox-Message-UUID: 0d0450fa-eacd-11e9-9e20-41e7f4b1d025 > From: C H Forsyth > > > Yet [Java] is more powerful in expressing algorithms. Things like closures > > or message polymorphism are natural and easy to express in Java, while > > Java has closures? > Of course it does. interface Appl {Object f(Object o);} interface List {void foreach(Appl a);} class test { void do(List l) { String s="element: "; l.foreach(new Appl() { String t=s; Object f(Object o) { System.out.println(t+o); } }); } } Untested, but the idea is simple: foreach is passed a dynamic closure with variable s inherited from the context. t=s is to show how a local binding can be explicitely created, one could simply write l.foreach(new Appl() { Object f(Object o) { System.out.println(s+o); } ... David