<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>So Jake Says &#187; Lisp Macros</title>
	<atom:link href="http://www.jakevoytko.com/blog/tag/lisp-macros/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jakevoytko.com/blog</link>
	<description>Ye Olde Computer Science Blogge</description>
	<lastBuildDate>Sun, 17 Jan 2010 15:16:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Explaining Lisp to my Father</title>
		<link>http://www.jakevoytko.com/blog/2008/07/21/explaining-lisp-to-my-father/</link>
		<comments>http://www.jakevoytko.com/blog/2008/07/21/explaining-lisp-to-my-father/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 04:00:55 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Quote]]></category>
		<category><![CDATA[Brevity]]></category>
		<category><![CDATA[Explaining Lisp]]></category>
		<category><![CDATA[Lambdas]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Lisp Macros]]></category>
		<category><![CDATA[Self-Modifying code]]></category>

		<guid isPermaLink="false">http://www.jakevoytko.com/blog/?p=102</guid>
		<description><![CDATA[Anyone who read my post last week knows that I&#8217;ve been trying to learn Lisp in my free time. My Dad has also noticed, and he occasionally checks on my progress. A week or two ago, he threw me a curveball: &#8220;How&#8217;s it going? Do you understand it all yet?&#8221; &#8220;No. I&#8217;m making progress, though. [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone who read my post last week knows that I&#8217;ve been trying to learn Lisp in my free time. My Dad has also noticed, and he occasionally checks on my progress.</p>
<p>A week or two ago, he threw me a curveball:</p>
<blockquote><p>&#8220;How&#8217;s it going? Do you understand it all yet?&#8221;</p>
<p>&#8220;No. I&#8217;m making progress, though. I&#8217;m probably not going to have this down for a while. It&#8217;s a completely different way of thinking from the programming I normally do.&#8221;</p>
<p>&#8220;How is it different?&#8221;</p></blockquote>
<p>I froze. He&#8217;s &#8220;Mr.-Fix-It,&#8221; and understands the rock quarry/asphault business inside and out. He&#8217;s very analytical, and it&#8217;s almost impossible to stump him with my favorite &#8220;Devil&#8217;s advocate&#8221; questions. However, aside from what I&#8217;ve told him, he just doesn&#8217;t know much about programming.</p>
<p>&#8220;Metaprogramming&#8221; and &#8220;first-class functions&#8221; wouldn&#8217;t have meant anything. &#8220;It lets you write programs faster&#8221; is a cop-out; he&#8217;s given me detailed explanations of his business. I wanted him to understand.</p>
<p>I was able to stammer out the fact that the language encourages breaking problems into smaller versions of the same problem (recursion), but that other programming languages also supported it.</p>
<p>I eventually told him that I hadn&#8217;t even thought about explaining the difference to a non-programmer.</p>
<p>&#8220;Well, if you&#8217;re ever able to come up with it, let me know.&#8221;</p>
<p>In college, I was a Computer Science tutor. I could explain most CS concepts that students saw in early C++ and Java courses to the layman on the street. However, I had <strong><span style="text-decoration: underline;"><em>nothing</em></span></strong> for explaining the difference between Lisp and C++ to him, which was a little scary. I spent some time dreaming up examples.</p>
<h2>Functions</h2>
<blockquote><p>All models are wrong, but some are useful.</p>
<p>~<a href="http://en.wikiquote.org/wiki/George_E._P._Box">George Box</a></p></blockquote>
<p>Abstract math notions are boring to most people, so I try to relate programming concepts to real-world items.</p>
<p>A fast-food restaurant is a great example of a function: An order and some money is input, and you get cheeseburgers, fries, a soda, and your change. Whether a person likes math or not, they know what a function is: you put something in, you get something out.</p>
<p>The idea is easily extensible to Object Oriented programming: all Burger Kings have orders, and you can place a specific order at an instance of a Burger King. A Burger King &#8220;is-a&#8221; fast food restaraunt.</p>
<p>I will use this metaphor to explain why Lisp is different from the programming I usually do (C++/Java/C#/Python).</p>
<h2>Lambdas</h2>
<p>Any restaraunt probably has a few different ways to order food: over the phone, at a drive-through window, at a counter, through a waiter, etc. However, there might be unofficial ways to order food: Bill Gates might write a letter requesting a buffet with a few hundreds slipped in as proof. Someone might tell the owner on his way to work that he&#8217;d like him to come back with a pizza.</p>
<p>The owner can easily define new ways to order food through a restaraunt.</p>
<p>Lisp, through &#8220;lambdas&#8221;, lets a programmer define new functions as easily as a restaraunt owner can devise new ways to order. The inputs and outputs are the same, but making new functions can have very low overhead compared to other programming languages.</p>
<h2>Brevity</h2>
<p>&#8220;Wiz Wit&#8221;.</p>
<p>This is my usual order at <a href="http://en.wikipedia.org/wiki/Pat%27s_King_of_Steaks">Pat&#8217;s</a> in Philly. With just two words, I get a cheesesteak with Cheez-Wiz and fried onions in less than 5 seconds. The system is designed to maximize the number of cheesesteaks output per hour: orders are short, and you usually get your cheesesteak before you&#8217;re done paying [and sometimes, before you're done speaking!]</p>
<p>This lesson can be applied to writing: It&#8217;s easier to convey a short thought. Unless you are Charles Dickens or Neal Stephenson, economy of language should be a goal.</p>
<p>Lisp&#8217;s syntax is very simple and short, so you can usually convey a thought in Lisp much quicker than you can convey a thought in most other programming languages.</p>
<h2>Macros</h2>
<p>An order can come in several different forms: it can be written, it can be gestured, it can be be spoken, and it can be implicit.</p>
<p>A lot of programming languages let you generalize the details of what an order can receive. Most orders are the same, so you can handle the contents the same even though the orders are different. In C++, you could even use &#8220;templates&#8221; to write code that generates code that handles this idea.</p>
<p>Lisp takes this idea all the way to its logical conclusion through &#8220;macros.&#8221; You can easily write functions that define orders. The difference is that you can easily do this at any scope!</p>
<p>If you notice that all fast food restaraunts are the same except for color scheme, specials, and slogans, it is easy to write functions that define new fast food chains. If you notice that your functions for defining fast food chains are similar to your functions for defining hardware chains, you can write functions that generate these producers.</p>
<p>Lisp lets you easily do this manufacturing on a level that is unimaginable with any other language. It may be possible, but nothing beats Lisp&#8217;s ease-of-use.</p>
<h2>Self-Modifying Code</h2>
<p>The metaphor breaks down here, and I won&#8217;t force it. However, the idea is simple when it is explained.</p>
<p>Most programming languages are designed to modify memory. They all store their information in memory, retrieve it, modify it, and write it to memory again.</p>
<p>Some programming languages try to hide the fact that they&#8217;re based on a memory-modification model, but they are extremely similar to languages that don&#8217;t hide it.</p>
<p>Lisp, however, is written to modify lists. Lisp is also written using lists, so a Lisp program can be programmed to modify itself.</p>
<h2>Conclusion</h2>
<p>This is just the tip of the iceberg! There are a lot more ideas that lay beneath the surface here, and you can bet that I&#8217;ll think about how to explain them to an educated adult. However, this should get someone with passing familiarity to programming to understand what makes Lisp stand out: ease-of-use and brevity.</p>
<img src="http://www.jakevoytko.com/blog/?ak_action=api_record_view&id=102&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.jakevoytko.com/blog/2008/07/21/explaining-lisp-to-my-father/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
