<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Homework for Closures</title>
	<atom:link href="http://cafe.elharo.com/blogroll/homework-for-closures/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/homework-for-closures/</link>
	<description>Longer than a blog; shorter than a book</description>
	<pubDate>Tue, 06 Jan 2009 14:46:06 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Howard Lovatt</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-77007</link>
		<dc:creator>Howard Lovatt</dc:creator>
		<pubDate>Thu, 12 Apr 2007 23:57:27 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-77007</guid>
		<description>I have posted a feature based comparison of the different closure proposals, C3s, FCM, CICE, &#38; BGGA, at:

http://www.artima.com/weblogs/viewpost.jsp?thread=202004

This comparison, hopefully, lets you choose which features are important to you and demonstrates that the proposals, other than CICE, are really a collection of features that includes new syntax for inner classes/closures.</description>
		<content:encoded><![CDATA[<p>I have posted a feature based comparison of the different closure proposals, C3s, FCM, CICE, &amp; BGGA, at:</p>
<p><a href="http://www.artima.com/weblogs/viewpost.jsp?thread=202004" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.artima.com');" rel="nofollow">http://www.artima.com/weblogs/viewpost.jsp?thread=202004</a></p>
<p>This comparison, hopefully, lets you choose which features are important to you and demonstrates that the proposals, other than CICE, are really a collection of features that includes new syntax for inner classes/closures.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pure Danger Tech &#187; Blog Archive &#187; Java Roundup (Mar 6th, 2007)</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-62663</link>
		<dc:creator>Pure Danger Tech &#187; Blog Archive &#187; Java Roundup (Mar 6th, 2007)</dc:creator>
		<pubDate>Wed, 07 Mar 2007 03:33:57 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-62663</guid>
		<description>[...] Closures continue to be a hot topic in the Java world. Last week Stephen Colebourne posted the new FCM proposal and he followed it up this week with two posts of comparison examples across the different proposals. Also in that spirit, Elliotte Rusty Harold posted on some homework we should do before deciding on a closure spec and Neal Gafter posted a closure MouseListener example. Finally, Andrew C. Oliver posted on replacing AOP with closures in some cases. [...]</description>
		<content:encoded><![CDATA[<p>[...] Closures continue to be a hot topic in the Java world. Last week Stephen Colebourne posted the new FCM proposal and he followed it up this week with two posts of comparison examples across the different proposals. Also in that spirit, Elliotte Rusty Harold posted on some homework we should do before deciding on a closure spec and Neal Gafter posted a closure MouseListener example. Finally, Andrew C. Oliver posted on replacing AOP with closures in some cases. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Szyster</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-62404</link>
		<dc:creator>Laurent Szyster</dc:creator>
		<pubDate>Tue, 06 Mar 2007 11:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-62404</guid>
		<description>Closure (and continuation) in plain old Java 1.4:

class TestContinuation {
    class Closure {
        private Object state = null; 
        public Closure(Object state) {this.state = state;}
        public Object call() {return state;}
    }
    public void continued(Closure continuation) {
        continuation.call();
    }
    public void main (String[] args) {
        continued(new Closure(null));
    }
}

If you really need the convenience of a concise syntax and the dynamism of an interpreter, use something else than Java.

I suggest CPython but you can have your way with JRuby too ;-)

Or wait for Java 1.7, although that could be a long time ...

Kind regards,</description>
		<content:encoded><![CDATA[<p>Closure (and continuation) in plain old Java 1.4:</p>
<p>class TestContinuation {<br />
    class Closure {<br />
        private Object state = null;<br />
        public Closure(Object state) {this.state = state;}<br />
        public Object call() {return state;}<br />
    }<br />
    public void continued(Closure continuation) {<br />
        continuation.call();<br />
    }<br />
    public void main (String[] args) {<br />
        continued(new Closure(null));<br />
    }<br />
}</p>
<p>If you really need the convenience of a concise syntax and the dynamism of an interpreter, use something else than Java.</p>
<p>I suggest CPython but you can have your way with JRuby too <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Or wait for Java 1.7, although that could be a long time &#8230;</p>
<p>Kind regards,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hallvard TrÃ¦tteberg</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-62369</link>
		<dc:creator>Hallvard TrÃ¦tteberg</dc:creator>
		<pubDate>Tue, 06 Mar 2007 08:05:55 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-62369</guid>
		<description>A typical example of function argument usage is traversing some data structure and returning the first occurrence (or many) matching the supplied predicate, like find-if in Common Lisp. This does not in itself require closures, only function pointers. However, almost any sensible usage of functions like find-if will use closures. E.g. write a method findNamedElement that takes a String name and returns the first object in a List that matches that name, using List's built-in findIf method. In Common Lisp that would be something like
(defun find-named-element (name list)
   (find-if #'(lambda (obj) (equal (get-name obj) name)) list)
)
In this case you need to close over the name argument, so while you don't (in this case) need heap allocated stack frames that survive the invocation of find-named-element, you need more than function pointers. Anyone having used this style of programming can tell you that. In my experience, this style mixes well with object-oriented programming. I keep reinventing interfaces for this purpose all the time, while dreaming of a future where Java has closures...

Pick up a book on functional programming (e.g. using Common Lisp) and find exercises there. There's no need to cook up new ones.</description>
		<content:encoded><![CDATA[<p>A typical example of function argument usage is traversing some data structure and returning the first occurrence (or many) matching the supplied predicate, like find-if in Common Lisp. This does not in itself require closures, only function pointers. However, almost any sensible usage of functions like find-if will use closures. E.g. write a method findNamedElement that takes a String name and returns the first object in a List that matches that name, using List&#8217;s built-in findIf method. In Common Lisp that would be something like<br />
(defun find-named-element (name list)<br />
   (find-if #&#8217;(lambda (obj) (equal (get-name obj) name)) list)<br />
)<br />
In this case you need to close over the name argument, so while you don&#8217;t (in this case) need heap allocated stack frames that survive the invocation of find-named-element, you need more than function pointers. Anyone having used this style of programming can tell you that. In my experience, this style mixes well with object-oriented programming. I keep reinventing interfaces for this purpose all the time, while dreaming of a future where Java has closures&#8230;</p>
<p>Pick up a book on functional programming (e.g. using Common Lisp) and find exercises there. There&#8217;s no need to cook up new ones.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Howard Lovatt</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-62311</link>
		<dc:creator>Howard Lovatt</dc:creator>
		<pubDate>Tue, 06 Mar 2007 03:34:26 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-62311</guid>
		<description>A while back I proposed another alternative, Clear, Consistent, and Concise Syntax (C3S) for Java (http://www.artima.com/weblogs/viewpost.jsp?thread=182412). It is closer to CICE than BGGA, in that it is based around inner classes with short syntax. An example in my proposed syntax is:

final list = Collections.sort inList, method( str1, str2 ) {
__str1.length - str2.length
};

Contrast this with Java 5+:

final Collection list = Collections.sort( inList, new Comparable() {
__public int compare( final String str1, final String str2 ) {
____return str1.length() - str2.length();
__}
});

The essence of the C3S proposal is, as the name suggests, to provide Clear, Consistent, and Concise Syntax in that order of priority. In particular Clarity and Consistency are not sacrificed in the name of conciseness. Part of the consistency aspect is not only syntax that is familiar, in particular it uses un-abbreviated keywords, but also it builds upon features already in the language, e.g. inner classes, rather than adding new features, i.e. closures with subtly different semantics than inner classes.

I would be happy to code some of your examples in my proposal, but Java 5+ versions would be easier to work with than 4.</description>
		<content:encoded><![CDATA[<p>A while back I proposed another alternative, Clear, Consistent, and Concise Syntax (C3S) for Java (http://www.artima.com/weblogs/viewpost.jsp?thread=182412). It is closer to CICE than BGGA, in that it is based around inner classes with short syntax. An example in my proposed syntax is:</p>
<p>final list = Collections.sort inList, method( str1, str2 ) {<br />
__str1.length - str2.length<br />
};</p>
<p>Contrast this with Java 5+:</p>
<p>final Collection list = Collections.sort( inList, new Comparable() {<br />
__public int compare( final String str1, final String str2 ) {<br />
____return str1.length() - str2.length();<br />
__}<br />
});</p>
<p>The essence of the C3S proposal is, as the name suggests, to provide Clear, Consistent, and Concise Syntax in that order of priority. In particular Clarity and Consistency are not sacrificed in the name of conciseness. Part of the consistency aspect is not only syntax that is familiar, in particular it uses un-abbreviated keywords, but also it builds upon features already in the language, e.g. inner classes, rather than adding new features, i.e. closures with subtly different semantics than inner classes.</p>
<p>I would be happy to code some of your examples in my proposal, but Java 5+ versions would be easier to work with than 4.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Slava Pestov</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-61952</link>
		<dc:creator>Slava Pestov</dc:creator>
		<pubDate>Mon, 05 Mar 2007 01:31:43 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-61952</guid>
		<description>Some people still wonder if having support for structured programming, and subroutine calls is necessary. After all, GOTOs might be enough. And they don't have to learn anything new to use GOTOs... always a hassle in old age.</description>
		<content:encoded><![CDATA[<p>Some people still wonder if having support for structured programming, and subroutine calls is necessary. After all, GOTOs might be enough. And they don&#8217;t have to learn anything new to use GOTOs&#8230; always a hassle in old age.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-61866</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Sun, 04 Mar 2007 19:25:20 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-61866</guid>
		<description>That may be the essence of a closure, but to my mind it's an open question whether that's necessary. I'm about 90% convinced something is necessary, but I suspect function pointers alone might be enough. What I hope to accomplish with these exercises is to see if that's true.

Please feel free to suggest practical problems that you feel might demonstrate the need for full closures as opposed to merely function pointers. They jey, though, is that they have to be phrased in terms of what we want to calculate/do rather than the algorith/technique by which we calculate/do that. 

A lot of the examples I've seen essentially bake the answer straight into the question. They're more of the form, "How do you drive a Ford Escort with standard transmission from Detroit to New York?" than "How do you travel from Detroit to New York?"</description>
		<content:encoded><![CDATA[<p>That may be the essence of a closure, but to my mind it&#8217;s an open question whether that&#8217;s necessary. I&#8217;m about 90% convinced something is necessary, but I suspect function pointers alone might be enough. What I hope to accomplish with these exercises is to see if that&#8217;s true.</p>
<p>Please feel free to suggest practical problems that you feel might demonstrate the need for full closures as opposed to merely function pointers. They jey, though, is that they have to be phrased in terms of what we want to calculate/do rather than the algorith/technique by which we calculate/do that. </p>
<p>A lot of the examples I&#8217;ve seen essentially bake the answer straight into the question. They&#8217;re more of the form, &#8220;How do you drive a Ford Escort with standard transmission from Detroit to New York?&#8221; than &#8220;How do you travel from Detroit to New York?&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Cowan</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-61854</link>
		<dc:creator>John Cowan</dc:creator>
		<pubDate>Sun, 04 Mar 2007 18:02:22 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-61854</guid>
		<description>The essence of a closure is that it captures, or closes over, the local variables in the code that lexically surrounds the closure.  These variables then survive the method's exit and are still available whenever the closure is invoked.  Note that this means that if two closures are created by a single invocation of a method, they share access to the same set of variables, but a second call of the same method will create entirely new local variables and new closures with access to them.

Currently, objects of (non-&lt;code&gt;static&lt;/code&gt;) inner classes aren't quite closures: they capture the &lt;i&gt;values&lt;/i&gt; of local variables, but not the variables themselves, because an inner-class object can only see &lt;code&gt;final&lt;/code&gt; variables, which can be copied freely since they cannot be mutated.

Examples that don't exercise the power of capturing local variables (and it's a power you probably don't feel the lack of because you've never had it) aren't really examples of closures at all; they are just syntactic sugar.</description>
		<content:encoded><![CDATA[<p>The essence of a closure is that it captures, or closes over, the local variables in the code that lexically surrounds the closure.  These variables then survive the method&#8217;s exit and are still available whenever the closure is invoked.  Note that this means that if two closures are created by a single invocation of a method, they share access to the same set of variables, but a second call of the same method will create entirely new local variables and new closures with access to them.</p>
<p>Currently, objects of (non-<code>static</code>) inner classes aren&#8217;t quite closures: they capture the <i>values</i> of local variables, but not the variables themselves, because an inner-class object can only see <code>final</code> variables, which can be copied freely since they cannot be mutated.</p>
<p>Examples that don&#8217;t exercise the power of capturing local variables (and it&#8217;s a power you probably don&#8217;t feel the lack of because you&#8217;ve never had it) aren&#8217;t really examples of closures at all; they are just syntactic sugar.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-61264</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Fri, 02 Mar 2007 16:07:10 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-61264</guid>
		<description>I'm working on Java 1.4 versions myself. I'll start posting them as soon as I get a minute. That should handle the Fibonacci details. And if anyone else would like to contribute, please drop me a line. I'm afraid I can't work on this full time just yet, and probably not till next month.</description>
		<content:encoded><![CDATA[<p>I&#8217;m working on Java 1.4 versions myself. I&#8217;ll start posting them as soon as I get a minute. That should handle the Fibonacci details. And if anyone else would like to contribute, please drop me a line. I&#8217;m afraid I can&#8217;t work on this full time just yet, and probably not till next month.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Colebourne</title>
		<link>http://cafe.elharo.com/blogroll/homework-for-closures/#comment-61247</link>
		<dc:creator>Stephen Colebourne</dc:creator>
		<pubDate>Fri, 02 Mar 2007 14:12:02 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/homework-for-closures/#comment-61247</guid>
		<description>I think that this is a good approach to comparing the proposals (I tried a couple of comparisons in my most recent blog). However, I'm concerned that each proposal writer is going to have to spend a lot of time working out the unimportant parts of the examples above, like the Fibonacci, fairness or synchronization. I would prefer to have the Java 6 code already written, and then customize the closure proposal from that. I think it would make them easier to compare too.

Also, three other ideas - (a) iterating around a map, with easy access to the key/value. (b) iterating around a collection and removing items that match some criteria. (c) Accessing a file, and ensuring it is closed afterwards.</description>
		<content:encoded><![CDATA[<p>I think that this is a good approach to comparing the proposals (I tried a couple of comparisons in my most recent blog). However, I&#8217;m concerned that each proposal writer is going to have to spend a lot of time working out the unimportant parts of the examples above, like the Fibonacci, fairness or synchronization. I would prefer to have the Java 6 code already written, and then customize the closure proposal from that. I think it would make them easier to compare too.</p>
<p>Also, three other ideas - (a) iterating around a map, with easy access to the key/value. (b) iterating around a collection and removing items that match some criteria. (c) Accessing a file, and ensuring it is closed afterwards.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
