<?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>Wisdom and Wonder &#187; Macros</title>
	<atom:link href="http://www.wisdomandwonder.com/tag/macros/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wisdomandwonder.com</link>
	<description>Science and Philosophy</description>
	<lastBuildDate>Wed, 25 Jan 2012 05:09:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>What are syntax-case pattern variables?</title>
		<link>http://www.wisdomandwonder.com/link/2937/what-are-syntax-case-pattern-variables</link>
		<comments>http://www.wisdomandwonder.com/link/2937/what-are-syntax-case-pattern-variables#comments</comments>
		<pubDate>Fri, 08 May 2009 02:18:47 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Link]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/?p=2937</guid>
		<description><![CDATA[I asked here: syntax-case takes a syntax object as an argument and destructures it via pattern matching into pattern variables. What are pattern variables composed of? syntax takes a template, and the pattern variables in it, to produce a syntax object that has the same lexical scoping as that of the pattern variable, so where [...]]]></description>
			<content:encoded><![CDATA[<p>I asked <a href="http://groups.google.com/group/plt-scheme/browse_thread/thread/49e07aa0cd440861/763d3b747557f4ea?lnk=gst&#038;q=What+are+syntax-case+pattern+variables%3F#763d3b747557f4ea">here</a>:</p>
<blockquote><p>syntax-case takes a syntax object as an argument and destructures it via pattern matching into pattern variables. </p>
<p>What are pattern variables composed of? </p>
<p>syntax takes a template, and the pattern variables in it, to produce a syntax object that has the same lexical scoping as that of the pattern variable, so where does that lexical scope get stored?</p></blockquote>
<p>and then Ryan explained:</p>
<blockquote><p>The short answer is that syntax objects store scoping information and<br />
that pattern variables have nothing to do with it. </p>
<p>Here&#8217;s a longer answer: </p>
<p>A pattern variable is essentially bound to an ellipsis-depth n and syntax object(s). If the pattern variable doesn&#8217;t have ellipses after it, then n is 0 and the pattern variable refers to a single syntax object. If it has one ellipsis after it, then n is 1 and there is a list of syntax objects. And so forth. </p>
<p>The &#8216;syntax&#8217; form is like &#8216;quasiquote&#8217;, except that there is no explicit &#8216;unquote&#8217;; rather, pattern variables are automatically substituted, and the rest of the template becomes syntax object literals (via &#8216;quote-syntax&#8217;) that remember the bindings in scope where they occurred. </p>
<p>So pattern variables, while convenient, are not necessary for writing macros. You could do just the same with &#8216;quote-syntax&#8217;, &#8216;syntax-e&#8217;, &#8216;datum->syntax&#8217;, &#8216;car&#8217;, etc. </p>
<p>Lexical scoping is managed by the syntax objects. The macro arguments already have their lexical contexts embedded in them, and that is preserved as the macro takes them apart and puts them together with new syntax. This new syntax mostly comes from syntax literals. </p>
<p>The essence of the algorithm is explained in &#8220;<a href="http://www.cs.indiana.edu/~dyb/pubs/LaSC-5-4-pp295-326.pdf">Syntactic Abstraction in Scheme&#8221;</a> by Dybvig et al.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/link/2937/what-are-syntax-case-pattern-variables/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Macros in Ruby</title>
		<link>http://www.wisdomandwonder.com/link/2614/macros-in-ruby</link>
		<comments>http://www.wisdomandwonder.com/link/2614/macros-in-ruby#comments</comments>
		<pubDate>Thu, 16 Apr 2009 00:26:40 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Link]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/?p=2614</guid>
		<description><![CDATA[This looks like an interesting article about writing macros in Ruby.]]></description>
			<content:encoded><![CDATA[<p><a href="http://weblog.raganwald.com/2008/06/macros-hygiene-and-call-by-name-in-ruby.html">This</a> looks like an interesting article about writing macros in Ruby.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/link/2614/macros-in-ruby/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unhygienic macros inside of unhygienic macros are difficult</title>
		<link>http://www.wisdomandwonder.com/link/1882/unhygienic-macros-inside-of-unhygienic-macros-are-difficult</link>
		<comments>http://www.wisdomandwonder.com/link/1882/unhygienic-macros-inside-of-unhygienic-macros-are-difficult#comments</comments>
		<pubDate>Sat, 21 Feb 2009 21:20:33 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Link]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[PLT]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/?p=1882</guid>
		<description><![CDATA[In this post; Ryan explains why unhygienic macros inside of unhygienic macros are often difficult. ;; the working if-it &#38; when-it &#160; &#40;define-syntax &#40;if-it stx&#41; &#40;syntax-case stx &#40;&#41; &#40;&#40;if-it test? then else&#41; &#40;with-syntax &#40;&#40;it &#40;datum-&#62;syntax #'if-it 'it&#41;&#41;&#41; #'&#40;let &#40;&#40;it test?&#41;&#41; &#40;if it then else&#41;&#41;&#41;&#41;&#41;&#41; &#160; &#40;define-syntax &#40;when-it stx&#41; &#40;syntax-case stx &#40;&#41; &#40;&#40;~ test? exp exp2 [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://list.cs.brown.edu/pipermail/plt-scheme/2009-January/029779.html">this</a> post; Ryan explains why unhygienic macros inside of unhygienic macros are often difficult.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #000000; font-style: italic; ">;; the working if-it &amp; when-it</span>
&nbsp;
<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define-syntax</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>if<span style="color: #000000; font-weight: bold; ">-</span>it stx<span style="color: #000000; font-weight: bold; ">&#41;</span>
  <span style="color: #000000; font-weight: bold; ">&#40;</span>syntax<span style="color: #000000; font-weight: bold; ">-</span><span style="color: #000000; ">case</span> stx <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>if<span style="color: #000000; font-weight: bold; ">-</span>it test? then <span style="color: #000000; ">else</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
     <span style="color: #000000; font-weight: bold; ">&#40;</span>with<span style="color: #000000; font-weight: bold; ">-</span><span style="color: #000000; ">syntax</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>it <span style="color: #000000; font-weight: bold; ">&#40;</span>datum<span style="color: #000000; font-weight: bold; ">-&gt;</span>syntax #'if<span style="color: #000000; font-weight: bold; ">-</span>it 'it<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
       #'<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">let</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>it test?<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
           <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">if</span> it then <span style="color: #000000; ">else</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define-syntax</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>when<span style="color: #000000; font-weight: bold; ">-</span>it stx<span style="color: #000000; font-weight: bold; ">&#41;</span>
  <span style="color: #000000; font-weight: bold; ">&#40;</span>syntax<span style="color: #000000; font-weight: bold; ">-</span><span style="color: #000000; ">case</span> stx <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>~ test? <span style="color: #000000; ">exp</span> exp2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span>
     <span style="color: #000000; font-weight: bold; ">&#40;</span>with<span style="color: #000000; font-weight: bold; ">-</span><span style="color: #000000; ">syntax</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>it <span style="color: #000000; font-weight: bold; ">&#40;</span>datum<span style="color: #000000; font-weight: bold; ">-&gt;</span>syntax #'~ 'it<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
       #'<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">let</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>it test?<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>when it <span style="color: #000000; ">exp</span> exp2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
&nbsp;
<span style="color: #000000; font-style: italic; ">;; the non-working cond-it </span>
<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define-syntax</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>cond<span style="color: #000000; font-weight: bold; ">-</span>it stx<span style="color: #000000; font-weight: bold; ">&#41;</span>
  <span style="color: #000000; font-weight: bold; ">&#40;</span>syntax<span style="color: #000000; font-weight: bold; ">-</span><span style="color: #000000; ">case</span> stx <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">else</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>cond<span style="color: #000000; font-weight: bold; ">-</span>it <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">else</span> <span style="color: #000000; ">exp</span> exp2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
     #'<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">begin</span> <span style="color: #000000; ">exp</span> exp2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>cond<span style="color: #000000; font-weight: bold; ">-</span>it <span style="color: #000000; font-weight: bold; ">&#40;</span>test? <span style="color: #000000; ">exp</span> exp2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
     #'<span style="color: #000000; font-weight: bold; ">&#40;</span>when<span style="color: #000000; font-weight: bold; ">-</span>it test? <span style="color: #000000; ">exp</span> exp2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>cond<span style="color: #000000; font-weight: bold; ">-</span>it <span style="color: #000000; font-weight: bold; ">&#40;</span>test? <span style="color: #000000; ">exp</span> exp2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span> cond1 cond2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span>
     #'<span style="color: #000000; font-weight: bold; ">&#40;</span>if<span style="color: #000000; font-weight: bold; ">-</span>it test? <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">begin</span> <span style="color: #000000; ">exp</span> exp2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span>
              <span style="color: #000000; font-weight: bold; ">&#40;</span>cond<span style="color: #000000; font-weight: bold; ">-</span>it cond1 cond2 ...<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span></pre></div></div>

<blockquote><p>When &#8216;cond-it&#8217; expands and produces an &#8216;if-it&#8217; expression, the &#8216;if-it&#8217; is marked by the macro expander as coming from a macro. That means its lexical context is different from the &#8216;it&#8217; variables in the branches. That means that the &#8216;it&#8217; variable binding produced by &#8216;if-it&#8217; does not capture the &#8216;it&#8217; references in the branches.</p></blockquote>
<p> &#8212; Ryan</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/link/1882/unhygienic-macros-inside-of-unhygienic-macros-are-difficult/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One reason for hygiene</title>
		<link>http://www.wisdomandwonder.com/link/1774/one-reason-for-hygiene</link>
		<comments>http://www.wisdomandwonder.com/link/1774/one-reason-for-hygiene#comments</comments>
		<pubDate>Sun, 15 Feb 2009 03:08:04 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Link]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/?p=1774</guid>
		<description><![CDATA[You need hygiene because: Only superstars on their highest alert level [while writing macros] get things right all the time. &#8211;Matthias That said, hygiene alone isn&#8217;t a cure-all for writing predictable macros. If you don&#8217;t understand what you are doing, thoroughly; you will screw up eventually. &#8220;Thar be dragons here&#8221; as someone once warned on [...]]]></description>
			<content:encoded><![CDATA[<p>You need hygiene because:</p>
<blockquote><p>Only superstars on their highest alert level [while writing macros] get things right all the time.</p></blockquote>
<p>&#8211;Matthias</p>
<p>That said, hygiene alone isn&#8217;t a cure-all for writing predictable macros. If you don&#8217;t understand what you are doing, thoroughly; you will screw up eventually. &#8220;Thar be dragons here&#8221; as someone once warned on the PLT list.</p>
<p>(via <a href="http://list.cs.brown.edu/pipermail/plt-scheme/2009-February/030376.html">PLT</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/link/1774/one-reason-for-hygiene/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Automata via Macros</title>
		<link>http://www.wisdomandwonder.com/article/1426/automata-via-macros</link>
		<comments>http://www.wisdomandwonder.com/article/1426/automata-via-macros#comments</comments>
		<pubDate>Fri, 02 Jan 2009 01:00:55 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/?p=1426</guid>
		<description><![CDATA[Last year I asked a question about Automata via Macros to the PLT Discussion List. The paper is about an extended example of a problem posed by Shriram Krishnamurthi at the Lightweight Languages 1 conference. I was trying to understand how one might use the same FSA language to generate different outputs. Many folks explained [...]]]></description>
			<content:encoded><![CDATA[<p>Last year I asked a <a href="http://list.cs.brown.edu/pipermail/plt-scheme/2007-August/019831.html">question</a> about <a href="http://www.cs.brown.edu/~sk/Publications/Papers/Published/sk-automata-macros/">Automata via Macros</a> to the <a href="http://www.plt-scheme.org/maillist/">PLT Discussion List</a>. The paper is about an extended example of a problem posed by <a href="http://www.cs.brown.edu/~sk/">Shriram Krishnamurthi</a> at the <a href="http://ll1.ai.mit.edu/">Lightweight Languages 1</a> conference. I was trying to understand how one might use the same <a href="http://en.wikipedia.org/wiki/Finite_state_machine">FSA</a> language to generate different outputs. Many folks explained how that would work and the thread finished. It didn&#8217;t finish for me, though. To say my understanding of the solution was superficial would be an overstatement. I knew I didn&#8217;t &#8220;get it&#8221;, and kept it on my list to revisit once I had a better grasp on things. That was a year and a half ago.</p>
<p>Over my holiday I revisited the paper and found, for lack of a better way to say it, that it &#8220;made sense&#8221;. In the past year I&#8217;ve tried to: read a lot, write a lot of code, read other people&#8217;s code, and most importantly do so with some <a href="http://www.wisdomandwonder.com/article/374/study-flaws-steady-flaws">discipline and attention to detail</a> that I had not applied before. That seems to have paid off; as it felt like I was reading the paper with brand new eyes. </p>
<p>This time around, I also listened to a recording of the presentation itself and watched the PowerPoint that went along with it. This was especially valuable because it drew attention to various tidbits that appeared in the paper but were much easier to delineate by virtue of Shriram pointing them out in context of the presentation. It was those comments, along with what I had learned in the past year that really got me thinking about things again.</p>
<p>In a conversation with <a href="http://www.sacrideo.us/">Aaron Hsu</a>, he once said something to the effect that &#8220;Scheme is hard because it is subtle.&#8221;, and that sort of rang true with my intuition, but I had a difficult time verbalizing exactly why I thought that to be true. Outwardly Scheme appears to be &#8220;simple&#8221;, but the more you learn about it and the deeper you dig, you start to see that it is <a href="http://www.wisdomandwonder.com/article/119/deceptively-simple"><strong>Deceptively Simple</strong></a>. </p>
<p>Scheme seems to take only a few days to learn, but a few years to master; but why? I don&#8217;t know yet, but what I do know is that some of the ideas and topics presented in this paper and presentation are surely some of the aforementioned &#8220;subtleties&#8221; that serve as landmarks on this multi-year path towards understanding Scheme. For my own reference, and for others who may be studying Scheme and wondering exactly why &#8220;Subtlety is hard&#8221;, perhaps this paper will serve to shed some light on things. </p>
<p>My advice: read <a href="http://www.wisdomandwonder.com/article/497/lambda-the-ultimate-imperative">LAMBDA: The Ultimate Imperative</a> and <a href="http://www.wisdomandwonder.com/article/509/lambda-the-ultimate-goto">LAMBDA: The Ultimate GOTO</a> first.</p>
<h3>Abstract</h3>
<blockquote><p>Lisp programmers have long used macros to extend their language. Indeed, their success has inspired macro notations for a variety of other languages, such as C and Java. There is, however, a paucity of effective pedagogic examples of macro use. This paper presents a short, non-trivial example that implements a construct not already found in mainstream languages. Furthermore, it motivates the need for tail-calls, as opposed to mere tail-recursion, and illustrates how support for tail-call optimization is crucial to support a natural style of macro-based language extension.</p></blockquote>
<h3>Key notes from the audio</h3>
<p>These are mostly my notes and summaries for some key points that rang true with me. The ideas that they represent may or may not be contained within my summary as it would be too far outside the scope of this blog post to address them. Such work is better done by other papers and presentations. </p>
<ul>
<li>09:00: Without the hidden gems, syntax, macros, and tail calls, it all falls apart.</li>
<li>11:16: What you generate must fit well into the language.</li>
<li>18:00: It is really tail-transfer (tail-calls) that matter, not tail-recursion.</li>
<li>21:00: Scheme is really an indentation based language.</li>
<li>23:00: Macro languages belong in modules; you can use your data (DSL) where you wish.</li>
<li>25:30: If you claim to be smart, leverage the work of others.</li>
<li>26:10: Scheme is subtle. Takes years to understand what is beautiful. You can look at a book but you won&#8217;t notice. The language hides it jewels.</li>
<li>26:45 If you don&#8217;t get tail calls, you don&#8217;t get it.</li>
</ul>
<h3>Key notes from the paper</h3>
<ul>
<li>P2P3: &#8220;A macro gives the programmer a consistent, representation-independent means of describing the datum<br />
while still resolving the representation before compilation.&#8221;</li>
<li>P7P4: Macros are likely to be used to optimize the abstraction that the data represents.</li>
<li>P8P3: Scheme&#8217;s macro system could be called &#8220;a lightweight compiler API&#8221;.</li>
<li>P9P2: Tail-calls ought to be called tail-transfer per Steele. I wonder why they didn&#8217;t push that definition more.</li>
<li>P9P3: Here is a good explanation of tail calls.</li>
<li>P9P5: &#8220;languages represent the ultimate form of reuse, because we get to reuse everything from the mathematical (semantics) to the practical (libraries), as well as decades of research and toil in compiler construction (Hudak, 1998).&#8221;</li>
<li>P13P2: &#8220;it shows how features that would otherwise seem orthogonal, such as macros and tail-calls, are in fact intimately wedded together; in particular, the absence of the latter would greatly complicate use of the former.&#8221;</li>
<li></li>
</ul>
<h3>The automaton language</h3>
<p></p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #000000; font-style: italic; ">; An automaton that recognizes the language c(ad)*r</span>
<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define</span> m 
  <span style="color: #000000; font-weight: bold; ">&#40;</span>automaton init
             <span style="color: #000000; font-weight: bold; ">&#40;</span>init : 
                   <span style="color: #000000; font-weight: bold; ">&#40;</span>c → more<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
             <span style="color: #000000; font-weight: bold; ">&#40;</span>more : 
                   <span style="color: #000000; font-weight: bold; ">&#40;</span>a → more<span style="color: #000000; font-weight: bold; ">&#41;</span>
                   <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">d</span> → more<span style="color: #000000; font-weight: bold; ">&#41;</span>
                   <span style="color: #000000; font-weight: bold; ">&#40;</span>r → end<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
             <span style="color: #000000; font-weight: bold; ">&#40;</span>end : accept<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/article/1426/automata-via-macros/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scheme is mysophobic</title>
		<link>http://www.wisdomandwonder.com/link/155/scheme-is-mysophobic</link>
		<comments>http://www.wisdomandwonder.com/link/155/scheme-is-mysophobic#comments</comments>
		<pubDate>Sat, 03 May 2008 14:21:21 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Link]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/link/155/scheme-is-mysophobic</guid>
		<description><![CDATA[Here is an interesting post about hygiene and its sociological impact on the two Lisp groups of Schemers and Common Lispers. While the post itself is a troll, the author: Uses a very accessible analogy. Quite clearly communicates a number of differences between Scheme and Common Lisp when it comes not only to hygiene but [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://groups.google.com/group/comp.lang.lisp/msg/07b915645de0cec7">Here</a> is an interesting post about hygiene and its sociological impact on the two Lisp groups of Schemers and Common Lispers. </p>
<p>While the post itself is a troll, the author:</p>
<ol>
<li>Uses a very accessible analogy.</li>
<li>Quite clearly communicates a number of differences between Scheme and Common Lisp when it comes not only to hygiene but also language design.</li>
</ol>
<p>The interesting thing about this post is that the only difference between this post being a troll and an educational article is how the content was delivered. If you remove the cruddy name-calling, whining, and complaining; it would have been a really good post on the difference between the languages. That is wild!</p>
<p>(reference <a href="http://en.wikipedia.org/wiki/Mysophobia">mysophobic</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/link/155/scheme-is-mysophobic/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anaphoric Macros</title>
		<link>http://www.wisdomandwonder.com/article/134/anaphoric-macros</link>
		<comments>http://www.wisdomandwonder.com/article/134/anaphoric-macros#comments</comments>
		<pubDate>Sun, 27 Apr 2008 23:03:14 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/article/134/anaphoric-macros</guid>
		<description><![CDATA[Does the convenience that anaphoric macros provide justify breaking hygiene? In that chapter of On Lisp, the author stated that: This chapter will show that variable capture can also be used constructively. There are some useful macros which couldn&#8217;t be written without it. My evaluation of that claim is that while the former is true, [...]]]></description>
			<content:encoded><![CDATA[<p>Does the convenience that <a href="http://www.bookshelf.jp/texi/onlisp/onlisp_15.html">anaphoric macros</a> provide justify breaking <a href="http://en.wikipedia.org/wiki/Hygienic_macro">hygiene</a>? In that chapter of <a href="http://www.bookshelf.jp/texi/onlisp/onlisp.html#SEC_Top">On Lisp</a>, the author stated that: </p>
<blockquote><p>This chapter will show that variable capture can also be used constructively. There are some useful macros which couldn&#8217;t be written without it.</p></blockquote>
<p>My evaluation of that claim is that while the former is true, anaphoric macros are not evidence of such a case as they only save you a variable binding. The latter claim is interesting because it begs the question of whether or not they should be written as macros at all. It made me wonder how anaphoric macros might look in Scheme, how they might look as functions, and whether one is clearly superior to the other.<br />
<span id="more-134"></span></p>
<p>I wrote two versions of aif, the first is a macro (m-aif) and the second is a function (f-aif). Both provide the same functionality albeit with a different mechanism for implementation and syntax for application:</p>
<p>m-aif</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define-syntax</span> m<span style="color: #000000; font-weight: bold; ">-</span>aif
  <span style="color: #000000; font-weight: bold; ">&#40;</span>λ <span style="color: #000000; font-weight: bold; ">&#40;</span>stx<span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span>syntax<span style="color: #000000; font-weight: bold; ">-</span><span style="color: #000000; ">case</span> stx <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
      <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>_ test<span style="color: #000000; font-weight: bold; ">-</span>form then<span style="color: #000000; font-weight: bold; ">-</span>form<span style="color: #000000; font-weight: bold; ">&#41;</span>
       <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">syntax</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>_ test<span style="color: #000000; font-weight: bold; ">-</span>form then<span style="color: #000000; font-weight: bold; ">-</span>form void<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
      <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>_ test<span style="color: #000000; font-weight: bold; ">-</span>form then<span style="color: #000000; font-weight: bold; ">-</span>form else<span style="color: #000000; font-weight: bold; ">-</span>form<span style="color: #000000; font-weight: bold; ">&#41;</span>
       <span style="color: #000000; font-weight: bold; ">&#40;</span>with<span style="color: #000000; font-weight: bold; ">-</span><span style="color: #000000; ">syntax</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>it <span style="color: #000000; font-weight: bold; ">&#40;</span>syntax<span style="color: #000000; font-weight: bold; ">-</span>local<span style="color: #000000; font-weight: bold; ">-</span>introduce <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">syntax</span> it<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
         <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">syntax</span>
          <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">let</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>it test<span style="color: #000000; font-weight: bold; ">-</span>form<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
            <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">if</span> it
                then<span style="color: #000000; font-weight: bold; ">-</span>form
                else<span style="color: #000000; font-weight: bold; ">-</span>form<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span></pre></div></div>

<p>f-aif</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define</span> f<span style="color: #000000; font-weight: bold; ">-</span>aif
  <span style="color: #000000; font-weight: bold; ">&#40;</span>λ <span style="color: #000000; font-weight: bold; ">&#40;</span>test<span style="color: #000000; font-weight: bold; ">-</span>form then<span style="color: #000000; font-weight: bold; ">-</span>form . else<span style="color: #000000; font-weight: bold; ">-</span>form<span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">let</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>it <span style="color: #000000; font-weight: bold; ">&#40;</span>test<span style="color: #000000; font-weight: bold; ">-</span>form<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
      <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">if</span> it
          <span style="color: #000000; font-weight: bold; ">&#40;</span>then<span style="color: #000000; font-weight: bold; ">-</span>form it<span style="color: #000000; font-weight: bold; ">&#41;</span>
          <span style="color: #000000; font-weight: bold; ">&#40;</span>unless <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">null?</span> else<span style="color: #000000; font-weight: bold; ">-</span>form<span style="color: #000000; font-weight: bold; ">&#41;</span>
            <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">car</span> else<span style="color: #000000; font-weight: bold; ">-</span>form<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span></pre></div></div>

<p>The difference between utilizing the two versions becomes a matter of syntactic preference:</p>
<p>m-aif</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #000000; font-weight: bold; ">&#40;</span>m<span style="color: #000000; font-weight: bold; ">-</span>aif <span style="color: #000000; font-weight: bold; ">&#40;</span>identity <span style="color: #000000; ">10</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
       <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">display</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">*</span> it <span style="color: #000000; ">23</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span></pre></div></div>

<p>f-aif</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #000000; font-weight: bold; ">&#40;</span>f<span style="color: #000000; font-weight: bold; ">-</span>aif <span style="color: #000000; font-weight: bold; ">&#40;</span>λ <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#41;</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>identity <span style="color: #000000; ">10</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
       <span style="color: #000000; font-weight: bold; ">&#40;</span>λ <span style="color: #000000; font-weight: bold; ">&#40;</span>it<span style="color: #000000; font-weight: bold; ">&#41;</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">display</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">*</span> it <span style="color: #000000; ">23</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span></pre></div></div>

<p>Which do <em>you</em> like better?</p>
<p>It should be an easy decision; with f-aif you get the desired functionality without breaking hygiene, albeit at the &#8220;cost&#8221; forcing the user to utilize lambda expressions. </p>
<p>In practice, requiring the use of lambda expressions is not an egregious demand of the user; instead, it is a pleasure. lambda is a special thing. The functionality that it provides is often more than enough to implement functionality that may initially appear to require macros (hygienic or not). </p>
<p>Macros are often times clearly the <em>only</em>, and the best, solution. This time isn&#8217;t one of them.</p>
<p><Strong>ADDENDUM: 03/04/11</strong>:</p>
<p><a href="http://3e8.org/zb/">Jim</a> asked:</p>
<blockquote><p>If you are concerned about variable capture then why don’t you write an anaphoric if macro that takes the variable name to introduce as an argument?</p></blockquote>
<p>Answer: When I wrote this I still didn&#8217;t grok hygiene.</p>
<p>Here is what I mean (and think Jim means):</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;">#<span style="color: #000000; font-weight: bold; ">!</span>r6rs
&nbsp;
<span style="color: #000000; font-weight: bold; ">&#40;</span>import <span style="color: #000000; font-weight: bold; ">&#40;</span>rnrs<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define-syntax</span> aif<span style="color: #000000; font-weight: bold; ">*</span>
  <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">syntax-rules</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>_ it test con . alt<span style="color: #000000; font-weight: bold; ">&#41;</span>
     <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">let</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>it test<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
       <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">if</span> it con . alt<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define-syntax</span> stomp?
  <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">syntax-rules</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>_ body<span style="color: #000000; font-weight: bold; ">&#41;</span>
     <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">let</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>foo <span style="color: #000000; ">0</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
       <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">begin</span>
         body
         <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">display</span> <span style="color: #000000; ">&quot;Stomp's foo: &quot;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
         <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">display</span> foo<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">newline</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold; ">&#40;</span>aif<span style="color: #000000; font-weight: bold; ">*</span> foo <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">+</span> <span style="color: #000000; ">10</span><span style="color: #000000; font-weight: bold; ">&#41;</span> 
      <span style="color: #000000; font-weight: bold; ">&#40;</span>stomp? 
       <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">begin</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">display</span> <span style="color: #000000; ">&quot;My foo: &quot;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
              <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">display</span> foo<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">newline</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span></pre></div></div>

<p>What do you think would get printed out here? At first glance you might think that stomp? will clobber foo and the user will not get the value they had expected, something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">My foo: 0
Stomp's foo: 0</pre></div></div>

<p>Here is the output though:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">My foo: 10
Stomp's foo: 0</pre></div></div>

<p>Surprised? syntax-rules retains the correct lexical binding so the user&#8217;s code and the macro&#8217;s code both referred to the correct binding of foo (foo_user==10 vs. foo_{stomp macro}==0). This is the benefit of &#8220;hygeine&#8221;. Looking back, I&#8217;m not sure why hygiene didn&#8217;t jump out as an extremely simple concept: macro bodies retain their lexical bindings.</p>
<p>Great question. Thanks for posting even after 3 years!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/article/134/anaphoric-macros/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Companies using DSLs with Functional Programming Languages</title>
		<link>http://www.wisdomandwonder.com/link/89/companies-using-dsls-with-functional-programming-languages</link>
		<comments>http://www.wisdomandwonder.com/link/89/companies-using-dsls-with-functional-programming-languages#comments</comments>
		<pubDate>Mon, 31 Mar 2008 16:31:07 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Link]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Programming Language]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/link/89/companies-using-dsls-with-functional-programming-languages</guid>
		<description><![CDATA[One of the questions that has been lingering in the back of my mind for a long time is &#8220;When should a company use a DSL?&#8221;. My stock answer has always been &#8220;When it makes sense.&#8221; Perhaps a better way is to answer that question is to look at how companies are actually using them [...]]]></description>
			<content:encoded><![CDATA[<p>One of the questions that has been lingering in the back of my mind for a long time is &#8220;When should a company use a DSL?&#8221;. My stock answer has always been &#8220;When it makes sense.&#8221;</p>
<p>Perhaps a better way is to answer that question is to look at <em>how</em> companies are actually using them today, rather then to simply guess! </p>
<p>Have a look at the &#8220;case studies&#8221; section in <a href="http://www.montages.com/presentation/20070901Stefansen.pdf">this presentation</a> on ContractML to see how companies are using DSLs today.</p>
<p>(via <a href="http://groups.google.com/group/cufp">cufp</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/link/89/companies-using-dsls-with-functional-programming-languages/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rubys Upto in a Scheme macro</title>
		<link>http://www.wisdomandwonder.com/article/21/rubys-upto-in-a-scheme-macro</link>
		<comments>http://www.wisdomandwonder.com/article/21/rubys-upto-in-a-scheme-macro#comments</comments>
		<pubDate>Thu, 27 Dec 2007 20:04:51 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/article/21/ruby%e2%80%99s-upto-with-a-scheme-macro</guid>
		<description><![CDATA[For a lot of folks, Ruby has a syntax that is really irresistible. Iteration is one of the things in particular that is described as being quite simply, fun. Here is how it works: Pass a message to the integer start index which includes both the inclusive stop index and a single argument function that [...]]]></description>
			<content:encoded><![CDATA[<p>For a lot of folks, Ruby has a syntax that is really irresistible. Iteration is one of the things in particular that is described as being quite simply, fun. Here is how it works:</p>
<p><span id="more-21"></span></p>
<p>Pass a message to the integer start index which includes both the inclusive stop index and a single argument function that is to be called with the current index in the iteration. The implementation of this feature, which can be found <a href="http://ruby-doc.org/core/classes/Integer.src/M001158.html">here</a>, is written nearly as you would imagine, albeit in C. Here is how the code looks when you call this function:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color: #000000; ">1</span>.upto<span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">3</span><span style="color: #000000; font-weight: bold; ">&#41;</span> <span style="color: #000000; font-weight: bold; ">&#123;</span><span style="color: #000000; font-weight: bold; ">|</span>x<span style="color: #000000; font-weight: bold; ">|</span> <span style="color: #000000; ">printf</span> <span style="color: #000000; ">&quot;#{x}<span style="color: #000000; ">\n</span>&quot;</span><span style="color: #000000; font-weight: bold; ">&#125;</span>
<span style="color: #000000; ">1</span>
<span style="color: #000000; ">2</span>
<span style="color: #000000; ">3</span></pre></div></div>

<p>With my programmer’s glasses on this, I would say that this syntax feels nice. In fact, it feels nice enough to think about adding a feature like this to Scheme. Here is what I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">define-syntax</span> from
  <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">syntax-rules</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>upto<span style="color: #000000; font-weight: bold; ">&#41;</span>
    <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#40;</span>from x upto y fn<span style="color: #000000; font-weight: bold; ">&#41;</span>
     <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">let</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#91;</span>finish <span style="color: #000000; font-weight: bold; ">&#40;</span>add1 y<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#93;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
       <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">let</span> loop <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">&#91;</span>cur x<span style="color: #000000; font-weight: bold; ">&#93;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
         <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">if</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">not</span> <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; font-weight: bold; ">=</span> cur finish<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
             <span style="color: #000000; font-weight: bold; ">&#40;</span><span style="color: #000000; ">begin</span>
               <span style="color: #000000; font-weight: bold; ">&#40;</span>fn cur<span style="color: #000000; font-weight: bold; ">&#41;</span>
               <span style="color: #000000; font-weight: bold; ">&#40;</span>loop <span style="color: #000000; font-weight: bold; ">&#40;</span>add1 cur<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span></pre></div></div>

<p>Here is how the Ruby sample from above looks in Scheme.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #000000; font-weight: bold; ">&#40;</span>from <span style="color: #000000; ">1</span> upto <span style="color: #000000; ">3</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>λ <span style="color: #000000; font-weight: bold; ">&#40;</span>x<span style="color: #000000; font-weight: bold; ">&#41;</span> <span style="color: #000000; font-weight: bold; ">&#40;</span>printf <span style="color: #000000; ">&quot;~a~n&quot;</span> x<span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span><span style="color: #000000; font-weight: bold; ">&#41;</span>
<span style="color: #000000; ">1</span>
<span style="color: #000000; ">2</span>
<span style="color: #000000; ">3</span></pre></div></div>

<p>What do you think? The two samples really don&#8217;t look all that different.</p>
<p>Grow-able languages are truly exciting. If you want to add a feature to the language, you add it. </p>
<p>Programming with grow-able languages takes you from “power-user” to <em>empowered-user</em>!</p>
<p>Which would you rather be?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/article/21/rubys-upto-in-a-scheme-macro/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Code Generation and DSLs in Scheme</title>
		<link>http://www.wisdomandwonder.com/article/17/code-generation-and-dsls-in-scheme</link>
		<comments>http://www.wisdomandwonder.com/article/17/code-generation-and-dsls-in-scheme#comments</comments>
		<pubDate>Tue, 18 Dec 2007 21:40:34 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[PLT]]></category>
		<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://www.wisdomandwonder.com/article/17/code-generation-and-dsls-in-scheme</guid>
		<description><![CDATA[Over the years, I have heard some pretty outrageous and tantalizing claims made about the programming language Lisp. For example, “It will change you, forever.” and “You write code that writes code.”. Sadly, no further explanation is ever provided. Perhaps it is impossible to capture the essence of that to which these statements allude? This [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years, I have heard some pretty outrageous and tantalizing claims made about the programming language Lisp. For example, “It will change you, forever.” and “You write code that writes code.”. Sadly, no further explanation is ever provided. Perhaps it is impossible to capture the essence of that to which these statements allude? This air of mystery around Lisp is both a blessing and a curse. Some folks will find this aura repugnant; others magical. For me, it was the latter. I wanted in on the secret!</p>
<p><span id="more-17"></span></p>
<p>When it comes to learning about new ideas, there is simply nothing more helpful than both great books and talking to folks knowledgeable on the topic. So, <a href="http://www.scheme.com/tspl3/">TSPL</a>, <a href="http://mitpress.mit.edu/sicp/full-text/book/book.html">SICP</a>, <a href="http://books.google.com/books?id=xyO-KLexVnMC&#038;dq=the+little+schemer&#038;pg=PP1&#038;ots=GHKOrP-RSv&#038;sig=C0WJL7pC0BB63q8fpsdqQuFJdvY&#038;prev=http://www.google.com/search?client=firefox-a&#038;rls=org.mozilla:en-US:official&#038;channel=s&#038;hl=en&#038;q=the+little+schemer&#038;btnG=Google+Search&#038;sa=X&#038;oi=print&#038;ct=title&#038;cad=one-book-with-thumbnail">TLS</a>, along with the wonderful folks in both comp.lang.scheme and the <a href="http://www.plt-scheme.org/">PLT</a> <a href="http://www.plt-scheme.org/maillist/">discussion list</a>, have really made this effort a lot of fun.</p>
<p>To capture the fruits of my labor, both for myself and for any folks interested in the same topic, I prepared a presentation on code generation and DSLs in Scheme. The presentation itself is driven by a popular Martin Fowler article on the topic of programming language tools entitled <a href="http://martinfowler.com/articles/languageWorkbench.html">&#8220;Language Workbenches: The Killer-App for Domain Specific Languages?&#8221;</a>.  The presentation is written for folks familiar with object oriented programming, my hope being that familiar territory would ease the introduction of the topic. While *numerous* code samples in Scheme are provided both in the presentation itself and in the supplementary archive, you should feel free to skip them; they are included only for folks who wish to delve further into learning Scheme. If you would like to run them, please use <a href="http://download.plt-scheme.org/drscheme/">DrScheme</a> v371 and set the language level to “Pretty Big”.</p>
<p><a href='http://www.wisdomandwonder.com/wordpress/wp-content/uploads/2007/12/code_generation_and_dsls_in_schemepdf.zip' title='Code Generation and DSLs in Scheme: The presentation'>Code Generation and DSLs in Scheme: The presentation</a></p>
<p><a href='http://www.wisdomandwonder.com/wordpress/wp-content/uploads/2007/12/code_generation_and_dsls_in_schemecode.zip' title='Code Generation and DSLs in Scheme: The code'>Code Generation and DSLs in Scheme: The code</a></p>
<p>Enjoy!</p>
<p><strong>Addendum: 8/2/8</strong></p>
<p>When I wrote this presentation, I was just beginning to scratch the surface of macros in Scheme. There is way, way too much code in it. Reflecting back on this, I see that teaching is a lot different than shoving a lot of information down someone&#8217;s throat. I will keep this here, though, for historical reference, and for anyone else who may benefit from this content.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wisdomandwonder.com/article/17/code-generation-and-dsls-in-scheme/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

