<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Seeking Closures</title>
	<atom:link href="http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/</link>
	<description>Just another LosTechies site</description>
	<lastBuildDate>Wed, 16 Feb 2011 11:54:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: foo</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-95</link>
		<dc:creator>foo</dc:creator>
		<pubDate>Sat, 06 Sep 2008 07:51:35 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-95</guid>
		<description>joshua:

EVERY is a function in Common Lisp, see here:
  http://www.lispworks.com/documentation/HyperSpec/Body/f_everyc.htm

You actually don&#039;t need the variable to be introduced by LET. Any (lexical) variable will do.

Also:

(let ((a 13) (b 14))  (+ a b))

is conceptually the same as

((lambda (a b) (+ a b)) 13 14)

So you get a closure with:

(defun foo (a) (lambda (b) (+ a b)))

and (foo 13) then is a closure that you can call and will always add 13 to a number:  (funcall (foo 13) 22)

Also note that you get a closure from this:

(let ((a 10)) (flet ((add (b) (+ a b)))  (function add)))

Any function will do. Local named functions, too.

Above you see that a closure is returned.

You can also pass a closure to another function:

(let ((a 10)) (flet ((add (b) (+ a b)))   (mapcar (function add)  &#039;(1 2 3 4))))

Above will add 10 to every element of the list and return the result list.
MAPCAR gets passed a closure and calls it with every element of the list as argument.

Sure, go ahead and use the examples...


</description>
		<content:encoded><![CDATA[<p>joshua:</p>
<p>EVERY is a function in Common Lisp, see here:<br />
  <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_everyc.htm" rel="nofollow">http://www.lispworks.com/documentation/HyperSpec/Body/f_everyc.htm</a></p>
<p>You actually don&#8217;t need the variable to be introduced by LET. Any (lexical) variable will do.</p>
<p>Also:</p>
<p>(let ((a 13) (b 14))  (+ a b))</p>
<p>is conceptually the same as</p>
<p>((lambda (a b) (+ a b)) 13 14)</p>
<p>So you get a closure with:</p>
<p>(defun foo (a) (lambda (b) (+ a b)))</p>
<p>and (foo 13) then is a closure that you can call and will always add 13 to a number:  (funcall (foo 13) 22)</p>
<p>Also note that you get a closure from this:</p>
<p>(let ((a 10)) (flet ((add (b) (+ a b)))  (function add)))</p>
<p>Any function will do. Local named functions, too.</p>
<p>Above you see that a closure is returned.</p>
<p>You can also pass a closure to another function:</p>
<p>(let ((a 10)) (flet ((add (b) (+ a b)))   (mapcar (function add)  &#8216;(1 2 3 4))))</p>
<p>Above will add 10 to every element of the list and return the result list.<br />
MAPCAR gets passed a closure and calls it with every element of the list as argument.</p>
<p>Sure, go ahead and use the examples&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-94</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 05 Sep 2008 17:44:47 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-94</guid>
		<description>If you&#039;re wondering where all the anonymous commenter(s) came from, this article got linked on Reddit: http://www.reddit.com/r/programming/comments/6zkav/seeking_closures_so_whats_a_closure_and_why/</description>
		<content:encoded><![CDATA[<p>If you&#8217;re wondering where all the anonymous commenter(s) came from, this article got linked on Reddit: <a href="http://www.reddit.com/r/programming/comments/6zkav/seeking_closures_so_whats_a_closure_and_why/" rel="nofollow">http://www.reddit.com/r/programming/comments/6zkav/seeking_closures_so_whats_a_closure_and_why/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlockwood</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-93</link>
		<dc:creator>jlockwood</dc:creator>
		<pubDate>Fri, 05 Sep 2008 15:22:39 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-93</guid>
		<description>@Ramarren

Okay, I see your point.  Point taken. :)

@foo

Ah, I see what you are saying...my mistake.  Thanks for clearing things up.  As you say, &quot;make-comparison&quot; is currently used to create a chunk of code and is not truly a closure.

I&#039;ve quickly read over your example and found it useful.  I&#039;d never seen the &quot;every&quot; function before and couldn&#039;t find it in the common lisp command reference that I&#039;ve been using.  I imagine its part of common lisp...ran fine in Allegro CL. With your permission I&#039;d like to update the blog entry to reflect what you&#039;ve provided.

I appreciate the feedback.  I&#039;m but a LISP neophyte, so I&#039;m still figuring a number of things out.  I see now that I must always use &quot;let&quot; to bind a variable locally and then I can use it in a closure.  I&#039;ll have to play with this a bit.</description>
		<content:encoded><![CDATA[<p>@Ramarren</p>
<p>Okay, I see your point.  Point taken. <img src='http://lostechies.com/joshualockwood/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>@foo</p>
<p>Ah, I see what you are saying&#8230;my mistake.  Thanks for clearing things up.  As you say, &#8220;make-comparison&#8221; is currently used to create a chunk of code and is not truly a closure.</p>
<p>I&#8217;ve quickly read over your example and found it useful.  I&#8217;d never seen the &#8220;every&#8221; function before and couldn&#8217;t find it in the common lisp command reference that I&#8217;ve been using.  I imagine its part of common lisp&#8230;ran fine in Allegro CL. With your permission I&#8217;d like to update the blog entry to reflect what you&#8217;ve provided.</p>
<p>I appreciate the feedback.  I&#8217;m but a LISP neophyte, so I&#8217;m still figuring a number of things out.  I see now that I must always use &#8220;let&#8221; to bind a variable locally and then I can use it in a closure.  I&#8217;ll have to play with this a bit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Meridth</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-92</link>
		<dc:creator>Jason Meridth</dc:creator>
		<pubDate>Thu, 04 Sep 2008 18:12:16 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-92</guid>
		<description>@foo

Why not use your real name here?  You have good input.  Just curious.  Anonymous commenters drive me nuts.</description>
		<content:encoded><![CDATA[<p>@foo</p>
<p>Why not use your real name here?  You have good input.  Just curious.  Anonymous commenters drive me nuts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: foo</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-91</link>
		<dc:creator>foo</dc:creator>
		<pubDate>Thu, 04 Sep 2008 16:49:37 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-91</guid>
		<description>Here is a version that really uses closures:

http://lispm.dyndns.org/source/closures-at-work.lisp

You can see that the result of calling (where ...) is a closure - the Lisp systems (LispWorks) also tells us that. There are multiple closures involved. MAKE-COMPARISON-FUNCTION returns a closure. MAKE-COMPARISON-FUNCTIONS returns a list of closures. WHERE also returns a closure.</description>
		<content:encoded><![CDATA[<p>Here is a version that really uses closures:</p>
<p><a href="http://lispm.dyndns.org/source/closures-at-work.lisp" rel="nofollow">http://lispm.dyndns.org/source/closures-at-work.lisp</a></p>
<p>You can see that the result of calling (where &#8230;) is a closure &#8211; the Lisp systems (LispWorks) also tells us that. There are multiple closures involved. MAKE-COMPARISON-FUNCTION returns a closure. MAKE-COMPARISON-FUNCTIONS returns a list of closures. WHERE also returns a closure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ramarren</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-90</link>
		<dc:creator>Ramarren</dc:creator>
		<pubDate>Thu, 04 Sep 2008 16:12:27 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-90</guid>
		<description>Yes, I meant the case. I probably should have said that directly. But really, I wasn&#039;t even born in the seventies, so I&#039;m just nitpicking. So, while I&#039;m doing that, Common Lisp is case sensitive, and required to be so by the standard, it is just that it is by default in :upcase mode for compatibility with older LISPs. See: http://www.lispworks.com/documentation/HyperSpec/Body/23_ab.htm</description>
		<content:encoded><![CDATA[<p>Yes, I meant the case. I probably should have said that directly. But really, I wasn&#8217;t even born in the seventies, so I&#8217;m just nitpicking. So, while I&#8217;m doing that, Common Lisp is case sensitive, and required to be so by the standard, it is just that it is by default in :upcase mode for compatibility with older LISPs. See: <a href="http://www.lispworks.com/documentation/HyperSpec/Body/23_ab.htm" rel="nofollow">http://www.lispworks.com/documentation/HyperSpec/Body/23_ab.htm</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlockwood</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-89</link>
		<dc:creator>jlockwood</dc:creator>
		<pubDate>Thu, 04 Sep 2008 15:04:33 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-89</guid>
		<description>@foo

Ah, if that&#039;s the case then I misunderstood.  I still write it as LISP, even when referencing CL.  I didn&#039;t even consider case, as the language is not case sensitive (at least with the implementation I&#039;m using).  As you stated, everything is evaluated in upcase.  

@Ramarren
My apologies if I misunderstood you.</description>
		<content:encoded><![CDATA[<p>@foo</p>
<p>Ah, if that&#8217;s the case then I misunderstood.  I still write it as LISP, even when referencing CL.  I didn&#8217;t even consider case, as the language is not case sensitive (at least with the implementation I&#8217;m using).  As you stated, everything is evaluated in upcase.  </p>
<p>@Ramarren<br />
My apologies if I misunderstood you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlockwood</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-88</link>
		<dc:creator>jlockwood</dc:creator>
		<pubDate>Thu, 04 Sep 2008 14:59:51 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-88</guid>
		<description>@Dave

Nice article!  I was considering getting into JavaScript, but decided against it because -- although I love JavaScript as a language -- I thought the language syntax might have made things a little confusing.  After getting deeper into JavaScript, I began to view functions as class definitions.  Closures are central to JavaScript as they are the only means in supporting object-oriented programming in the language.  

It&#039;s interesting, I think if one views JavaScript through the eyes of a LISPer the language kind of makes more sense.  I say this because in LISP the line between code and data is kind of blurred.  JavaScript uses the same syntax to define functions as it does data constructs (similar to lisp).

I certainly agree that looking at JavaScript&#039;s implementation of closures is quite useful in developing an overall understanding of the concept.</description>
		<content:encoded><![CDATA[<p>@Dave</p>
<p>Nice article!  I was considering getting into JavaScript, but decided against it because &#8212; although I love JavaScript as a language &#8212; I thought the language syntax might have made things a little confusing.  After getting deeper into JavaScript, I began to view functions as class definitions.  Closures are central to JavaScript as they are the only means in supporting object-oriented programming in the language.  </p>
<p>It&#8217;s interesting, I think if one views JavaScript through the eyes of a LISPer the language kind of makes more sense.  I say this because in LISP the line between code and data is kind of blurred.  JavaScript uses the same syntax to define functions as it does data constructs (similar to lisp).</p>
<p>I certainly agree that looking at JavaScript&#8217;s implementation of closures is quite useful in developing an overall understanding of the concept.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: foo</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-87</link>
		<dc:creator>foo</dc:creator>
		<pubDate>Thu, 04 Sep 2008 14:52:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-87</guid>
		<description>Joshua: what Ramarren says: Lisp is nowadays called &#039;Lisp&#039;. In earlier years it was called LISP. Years ago it was all upcase. Even the programs were upcase. Common Lisp has the symbols also internally in upcase format. Nowadays when somebody sees LISP then he thinks of the older Lisp dialects from before the 70s.</description>
		<content:encoded><![CDATA[<p>Joshua: what Ramarren says: Lisp is nowadays called &#8216;Lisp&#8217;. In earlier years it was called LISP. Years ago it was all upcase. Even the programs were upcase. Common Lisp has the symbols also internally in upcase format. Nowadays when somebody sees LISP then he thinks of the older Lisp dialects from before the 70s.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlockwood</title>
		<link>http://lostechies.com/joshualockwood/2008/09/04/seeking-closures/#comment-86</link>
		<dc:creator>jlockwood</dc:creator>
		<pubDate>Thu, 04 Sep 2008 14:51:26 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshua_lockwood/archive/2008/09/03/seeking-closures.aspx#comment-86</guid>
		<description>@Justin Paston-Cooper 

Come now Justin, you must know that I joke with tounge in cheek!  I don&#039;t feel that I need to pander to anyone...nor do I try associate with many people for that matter (ask one of my handful of friends...LOL).

In truth, I know of a number of people who are adept at several languages yet still find LISP to be cryptic and even intimidating.  I wouldn&#039;t doubt that the way some universities present the language contribute to this paradigm.

&gt; I like how you feel the need to pander to the average 
&gt; programmer&#039;s thoughts of &quot;OH NO ITS NOT A C BASED 
&gt; LANGUAGE IT LOOKS DIFFERENT SO IT MUST BE BAD 
&gt; AAAAAH&quot;...
The funny things about this is that I&#039;ve found such attitudes to be more common among some Ruby developers that I&#039;ve met...they seem to think that there is no other language but theirs.  Of course, there is the VB crowd too...

The bottom line is that LISP is not a common language and is often forgotten outside of the university.  In spite of this, its influence is becomming increasingly apparent in the mainstream languages that get the most attention.  I believe that studying the language will help improve overall programming ability as well as offer clear illustrations of concepts introduced into the languages used daily in the workplace.

If I appeared to pander to one group or another I apologize.  I was simply joking about the way LISP is commonly perceived.  Its a great language and you don&#039;t have to look like the Unibomber to enjoy it!</description>
		<content:encoded><![CDATA[<p>@Justin Paston-Cooper </p>
<p>Come now Justin, you must know that I joke with tounge in cheek!  I don&#8217;t feel that I need to pander to anyone&#8230;nor do I try associate with many people for that matter (ask one of my handful of friends&#8230;LOL).</p>
<p>In truth, I know of a number of people who are adept at several languages yet still find LISP to be cryptic and even intimidating.  I wouldn&#8217;t doubt that the way some universities present the language contribute to this paradigm.</p>
<p>> I like how you feel the need to pander to the average<br />
> programmer&#8217;s thoughts of &#8220;OH NO ITS NOT A C BASED<br />
> LANGUAGE IT LOOKS DIFFERENT SO IT MUST BE BAD<br />
> AAAAAH&#8221;&#8230;<br />
The funny things about this is that I&#8217;ve found such attitudes to be more common among some Ruby developers that I&#8217;ve met&#8230;they seem to think that there is no other language but theirs.  Of course, there is the VB crowd too&#8230;</p>
<p>The bottom line is that LISP is not a common language and is often forgotten outside of the university.  In spite of this, its influence is becomming increasingly apparent in the mainstream languages that get the most attention.  I believe that studying the language will help improve overall programming ability as well as offer clear illustrations of concepts introduced into the languages used daily in the workplace.</p>
<p>If I appeared to pander to one group or another I apologize.  I was simply joking about the way LISP is commonly perceived.  Its a great language and you don&#8217;t have to look like the Unibomber to enjoy it!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
