<?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: Two Criteria for Closures</title>
	<atom:link href="http://cafe.elharo.com/blogroll/two-criteria-for-closures/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/two-criteria-for-closures/</link>
	<description>Longer than a blog; shorter than a book</description>
	<pubDate>Wed, 07 Jan 2009 00:09:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Alvaro</title>
		<link>http://cafe.elharo.com/blogroll/two-criteria-for-closures/#comment-148519</link>
		<dc:creator>Alvaro</dc:creator>
		<pubDate>Mon, 29 Oct 2007 21:32:42 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/two-criteria-for-closures/#comment-148519</guid>
		<description>I'm totally agree with you. Don't add closures to Java!!</description>
		<content:encoded><![CDATA[<p>I&#8217;m totally agree with you. Don&#8217;t add closures to Java!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Howard Lovatt</title>
		<link>http://cafe.elharo.com/blogroll/two-criteria-for-closures/#comment-77005</link>
		<dc:creator>Howard Lovatt</dc:creator>
		<pubDate>Thu, 12 Apr 2007 23:51:18 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/two-criteria-for-closures/#comment-77005</guid>
		<description>I have posted a comparison of C3S, FCM, CICE, and BGGA - see URL - that splits out the different concerns addressed by these proposals</description>
		<content:encoded><![CDATA[<p>I have posted a comparison of C3S, FCM, CICE, and BGGA - see URL - that splits out the different concerns addressed by these proposals</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Colebourne</title>
		<link>http://cafe.elharo.com/blogroll/two-criteria-for-closures/#comment-60491</link>
		<dc:creator>Stephen Colebourne</dc:creator>
		<pubDate>Tue, 27 Feb 2007 00:35:31 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/two-criteria-for-closures/#comment-60491</guid>
		<description>And hot off the press is the third closure proposal - First-class methods: Java-style closures.

http://jroller.com/page/scolebourne?entry=first_class_methods_java_style

FCM is located between CICE and BGGA, and we believe that it address most of your concerns listed above. We'd love to receive your feedback.</description>
		<content:encoded><![CDATA[<p>And hot off the press is the third closure proposal - First-class methods: Java-style closures.</p>
<p><a href="http://jroller.com/page/scolebourne?entry=first_class_methods_java_style" onclick="javascript:pageTracker._trackPageview('/outbound/comment/jroller.com');" rel="nofollow">http://jroller.com/page/scolebourne?entry=first_class_methods_java_style</a></p>
<p>FCM is located between CICE and BGGA, and we believe that it address most of your concerns listed above. We&#8217;d love to receive your feedback.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hallvard TrÃ¦tteberg</title>
		<link>http://cafe.elharo.com/blogroll/two-criteria-for-closures/#comment-56788</link>
		<dc:creator>Hallvard TrÃ¦tteberg</dc:creator>
		<pubDate>Fri, 16 Feb 2007 08:39:45 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/two-criteria-for-closures/#comment-56788</guid>
		<description>I'd like to comment on your syntax criteria: "I really, really want the syntax to be simple and have no surprises or significant learning curve." Syntax goes hand in hand with semantics, it's not that easy to say which is surprising or complex. Anonymous interface implementations (new ActionListener() { .., }) are often criticized for being ugly. However, my students have no problem reading them when they're simple, e.g. just call a method of the enclosing class, although they really don't understand the mechanism. When I begin passing them around they're confused, not because the syntax is suprising, but because their usage is (at least to them). I think this will be true for closures too: simple use cases will be easy to read, complex ones will be complex. People who are already comfortable using them, will have no problems, while people who are learning them for the first time will have problems anyhow. Of course the syntax can do harm, but I think that once you understand why something needs to be expressed (like explicit typing), you accept the syntax, too.

As to what is surprising I agree with John. I was surprised when I read about how break and continue could be used within closures (BGGA), as this is something I'm not used to from Lisp. After having understood their usage, I think I would be even more surprised if was allowed to use break and continue after the loop context had exited. It doesn't have a meaning, it's like a control flow analogy to a following a null pointer: it makes no sense and we should be made aware of the error.</description>
		<content:encoded><![CDATA[<p>I&#8217;d like to comment on your syntax criteria: &#8220;I really, really want the syntax to be simple and have no surprises or significant learning curve.&#8221; Syntax goes hand in hand with semantics, it&#8217;s not that easy to say which is surprising or complex. Anonymous interface implementations (new ActionListener() { .., }) are often criticized for being ugly. However, my students have no problem reading them when they&#8217;re simple, e.g. just call a method of the enclosing class, although they really don&#8217;t understand the mechanism. When I begin passing them around they&#8217;re confused, not because the syntax is suprising, but because their usage is (at least to them). I think this will be true for closures too: simple use cases will be easy to read, complex ones will be complex. People who are already comfortable using them, will have no problems, while people who are learning them for the first time will have problems anyhow. Of course the syntax can do harm, but I think that once you understand why something needs to be expressed (like explicit typing), you accept the syntax, too.</p>
<p>As to what is surprising I agree with John. I was surprised when I read about how break and continue could be used within closures (BGGA), as this is something I&#8217;m not used to from Lisp. After having understood their usage, I think I would be even more surprised if was allowed to use break and continue after the loop context had exited. It doesn&#8217;t have a meaning, it&#8217;s like a control flow analogy to a following a null pointer: it makes no sense and we should be made aware of the error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lordpixel</title>
		<link>http://cafe.elharo.com/blogroll/two-criteria-for-closures/#comment-56639</link>
		<dc:creator>lordpixel</dc:creator>
		<pubDate>Thu, 15 Feb 2007 20:06:09 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/two-criteria-for-closures/#comment-56639</guid>
		<description>Firstly, John Cowan is right about #4. I want an error message if I continue or break a loop that no longer exists. Silently ignoring a return value isn't always an error. Code trying to break or continue when there's no longer a loop in existence is an error, and I want to be informed.

I believe the currentl proposal requires the compiler to refuse to compile code where it can tell that this will happen. Specifically, if closure's type extends RestrictedClosure (e.g. because it is intended to handle asynchronous closures like the Runnable interface) I think you will not be able to compile any code featuring a break or continue that would cause a loop *outside* the closure itself to terminate.

I'd be interested in seeing some cases where the compiler can't tell this, then we'll know how common this exception will be.

Rusty, you say:
"First of all, Iâ€™m not sure I like that return returns from the enclosing scope rather than from the closure itself. Thatâ€™s a surprise."

Well, that's a consequence one of Neal's initial design goals. The idea was specifically to avoid a different kind of surprise :) The idea is if you take code that is not inside a closure and move it into a closure, it should mean the same thing. He blogged about it here, Tennent's Correspondence principal, which explains the reasoning better than I can:

http://gafter.blogspot.com/2006/08/tennents-correspondence-principle-and.html

That page also contains a proposal for a yield syntax ( ^value ) but they have since dropped that - I am not sure why.

If you want to understand the proposal in more depth, I recommend reading Neal's blog in chronological order. I've been following along and it has been enlightening.</description>
		<content:encoded><![CDATA[<p>Firstly, John Cowan is right about #4. I want an error message if I continue or break a loop that no longer exists. Silently ignoring a return value isn&#8217;t always an error. Code trying to break or continue when there&#8217;s no longer a loop in existence is an error, and I want to be informed.</p>
<p>I believe the currentl proposal requires the compiler to refuse to compile code where it can tell that this will happen. Specifically, if closure&#8217;s type extends RestrictedClosure (e.g. because it is intended to handle asynchronous closures like the Runnable interface) I think you will not be able to compile any code featuring a break or continue that would cause a loop *outside* the closure itself to terminate.</p>
<p>I&#8217;d be interested in seeing some cases where the compiler can&#8217;t tell this, then we&#8217;ll know how common this exception will be.</p>
<p>Rusty, you say:<br />
&#8220;First of all, Iâ€™m not sure I like that return returns from the enclosing scope rather than from the closure itself. Thatâ€™s a surprise.&#8221;</p>
<p>Well, that&#8217;s a consequence one of Neal&#8217;s initial design goals. The idea was specifically to avoid a different kind of surprise <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> The idea is if you take code that is not inside a closure and move it into a closure, it should mean the same thing. He blogged about it here, Tennent&#8217;s Correspondence principal, which explains the reasoning better than I can:</p>
<p><a href="http://gafter.blogspot.com/2006/08/tennents-correspondence-principle-and.html" onclick="javascript:pageTracker._trackPageview('/outbound/comment/gafter.blogspot.com');" rel="nofollow">http://gafter.blogspot.com/2006/08/tennents-correspondence-principle-and.html</a></p>
<p>That page also contains a proposal for a yield syntax ( ^value ) but they have since dropped that - I am not sure why.</p>
<p>If you want to understand the proposal in more depth, I recommend reading Neal&#8217;s blog in chronological order. I&#8217;ve been following along and it has been enlightening.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Slava Pestov</title>
		<link>http://cafe.elharo.com/blogroll/two-criteria-for-closures/#comment-56636</link>
		<dc:creator>Slava Pestov</dc:creator>
		<pubDate>Thu, 15 Feb 2007 19:54:43 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/two-criteria-for-closures/#comment-56636</guid>
		<description>Closures were first invented and various implications understood in the 70's. Statically typed languages have had closures since the 80's. Many use-cases have been demonstrated. Pretty much any new high level language being designed today has closures. Is there anything left to discuss?</description>
		<content:encoded><![CDATA[<p>Closures were first invented and various implications understood in the 70&#8217;s. Statically typed languages have had closures since the 80&#8217;s. Many use-cases have been demonstrated. Pretty much any new high level language being designed today has closures. Is there anything left to discuss?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Cowan</title>
		<link>http://cafe.elharo.com/blogroll/two-criteria-for-closures/#comment-56613</link>
		<dc:creator>John Cowan</dc:creator>
		<pubDate>Thu, 15 Feb 2007 17:31:35 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/two-criteria-for-closures/#comment-56613</guid>
		<description>I'm addressing several unrelated points in this comment, so I'll number them.

#1: When I first read about Java inner classes, the restriction that a (non-static) inner class can only refer to final variables in the enclosing scope outraged me.  "Either do lexical scoping right or leave it out!" I thought, coming as I do from a Lisp background where lexical scoping works for both mutable and immutable variables, and the compiler figures out which are which and how to manage the implementation.

Now I shrug and live with the restriction; the compiler complains when I break it, and I work around the problem.  (The general workaround is to have a trivial "box class" that contains just one public instance variable, which is more or less what Lisp compilers do when they decide they have to.)

#2:  &lt;code&gt;public&lt;/code&gt; means "accessible out of the obvious scope".  It's meaningless to attach the normal out-of-class semantics to local variables anyhow, so attaching them here is not really a Big Deal.  We already have multiple meanings of &lt;code&gt;final&lt;/code&gt; without too much problem.

#3: Strong static typing has nothing to do with whether your language has type inference.  Java versions up to 1.4 didn't do type inference; you had to write out every type name explicitly.  Generics require the compiler to do a modest amount of type inference, and there are strongly statically typed languages where the compiler does &lt;i&gt;all&lt;/i&gt; the type inference; in ML, you never need to mention an explicit type within a structure (the analogue of a class) except where you are doing ad-hoc overloading of operators, as with floating-point &lt;code&gt;+&lt;/code&gt; vs. integer &lt;code&gt;+&lt;/code&gt;.  And ML is even more statically strongly typed than Java is, as it doesn't have the &lt;code&gt;null&lt;/code&gt; hole.

#4: The non-local-transfer exception is really quite unavoidable.  Remember that beside being functions, closures are first-class objects, so they can be preserved in global variables or inside other objects (indeed, this is one of their common uses).  When a closure created within a loop does a &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt;, and the loop is already complete, there really is no non-surprising thing to do, but silently returning (with what value, anyhow?) is much more surprising than throwing an error.</description>
		<content:encoded><![CDATA[<p>I&#8217;m addressing several unrelated points in this comment, so I&#8217;ll number them.</p>
<p>#1: When I first read about Java inner classes, the restriction that a (non-static) inner class can only refer to final variables in the enclosing scope outraged me.  &#8220;Either do lexical scoping right or leave it out!&#8221; I thought, coming as I do from a Lisp background where lexical scoping works for both mutable and immutable variables, and the compiler figures out which are which and how to manage the implementation.</p>
<p>Now I shrug and live with the restriction; the compiler complains when I break it, and I work around the problem.  (The general workaround is to have a trivial &#8220;box class&#8221; that contains just one public instance variable, which is more or less what Lisp compilers do when they decide they have to.)</p>
<p>#2:  <code>public</code> means &#8220;accessible out of the obvious scope&#8221;.  It&#8217;s meaningless to attach the normal out-of-class semantics to local variables anyhow, so attaching them here is not really a Big Deal.  We already have multiple meanings of <code>final</code> without too much problem.</p>
<p>#3: Strong static typing has nothing to do with whether your language has type inference.  Java versions up to 1.4 didn&#8217;t do type inference; you had to write out every type name explicitly.  Generics require the compiler to do a modest amount of type inference, and there are strongly statically typed languages where the compiler does <i>all</i> the type inference; in ML, you never need to mention an explicit type within a structure (the analogue of a class) except where you are doing ad-hoc overloading of operators, as with floating-point <code>+</code> vs. integer <code>+</code>.  And ML is even more statically strongly typed than Java is, as it doesn&#8217;t have the <code>null</code> hole.</p>
<p>#4: The non-local-transfer exception is really quite unavoidable.  Remember that beside being functions, closures are first-class objects, so they can be preserved in global variables or inside other objects (indeed, this is one of their common uses).  When a closure created within a loop does a <code>break</code> or <code>continue</code>, and the loop is already complete, there really is no non-surprising thing to do, but silently returning (with what value, anyhow?) is much more surprising than throwing an error.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
