<?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>Artisan Coder &#187; srfi-2</title>
	<atom:link href="http://www.artisancoder.com/tag/srfi-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artisancoder.com</link>
	<description>Software development as a craft</description>
	<lastBuildDate>Thu, 15 Dec 2011 10:57:08 +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>Equivalent of and-let*?</title>
		<link>http://www.artisancoder.com/2008/12/equivalent-of-and-let/</link>
		<comments>http://www.artisancoder.com/2008/12/equivalent-of-and-let/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 17:33:47 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[srfi-2]]></category>

		<guid isPermaLink="false">http://www.ventonegro.org/?p=64</guid>
		<description><![CDATA[By this point I believe it&#8217;s clear that I am a big fan of Scheme. Lately I have seen a sharp rise of interest in Ruby in some virtual places I attend (#lisp-br, twitter, IM with coworkers etc.). I am sure Ruby is a fine language, even in spite of several complaints I hear from [...]]]></description>
			<content:encoded><![CDATA[<p>By this point I believe it&#8217;s clear that I am a big fan of <a href="http://www.schemers.org/" title="An improper list of Scheme resources">Scheme</a>. Lately I have seen a sharp rise of interest in Ruby in some virtual places I attend (#lisp-br, twitter, IM with coworkers etc.). I am sure Ruby is a fine language, even in spite of several complaints I hear from some of its users. After all, it has symbols, metaprogramming, blocks (a sort of closures), <em>lambdas</em> and more! I&#8217;d really take the time to learn it, if it wasn&#8217;t for <a href="http://www.paulgraham.com/quotes.html" title="Lisp Quotes">Matz himself</a>:</p>
<blockquote>
<p>Some may say Ruby is a bad rip-off of Lisp or Smalltalk, and I admit that. But it is nicer to ordinary people.</p>
</blockquote>
<p>Now <em>that</em> is a demotivator. But Ruby must be evolving, and that quote may be outdated. So I have thought of a question to the Ruby-lovers, that may help me make up my mind to take the time to learn it. One of the best Scheme macros is, in my opinion, <tt>and-let*</tt>, from the <a href="http://srfi.schemers.org/srfi-2/srfi-2.html" title="AND-LET*: an AND with local bindings, a guarded LET* special form">SRFI-2</a>. How would one write the following in Ruby, a procedure that I wrote a couple of nights ago?</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="scheme"><pre class="de1"><span class="co1">;; Tries to get session from current request</span>
<span class="br0">&#40;</span><span class="kw1">define</span> <span class="br0">&#40;</span>get<span class="sy0">-</span>session request<span class="br0">&#41;</span>
  <span class="br0">&#40;</span>and<span class="sy0">-</span><span class="kw1">let*</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>cookies <span class="br0">&#40;</span>request<span class="sy0">-</span>cookies request<span class="br0">&#41;</span><span class="br0">&#41;</span>
             <span class="br0">&#40;</span>p <span class="br0">&#40;</span><span class="kw1">assoc</span> <span class="st0">&quot;session_id&quot;</span> cookies<span class="br0">&#41;</span><span class="br0">&#41;</span>
             <span class="br0">&#40;</span>sid<span class="sy0">-</span>str <span class="br0">&#40;</span><span class="kw1">cdr</span> p<span class="br0">&#41;</span><span class="br0">&#41;</span>
             <span class="br0">&#40;</span>sid <span class="br0">&#40;</span>string<span class="sy0">-&gt;</span>number sid<span class="sy0">-</span>str<span class="br0">&#41;</span><span class="br0">&#41;</span>
             <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw1">integer?</span> sid<span class="br0">&#41;</span><span class="br0">&#41;</span>
             <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw1">exact?</span> sid<span class="br0">&#41;</span><span class="br0">&#41;</span>
             <span class="br0">&#40;</span>sp <span class="br0">&#40;</span><span class="kw1">assq</span> sid <span class="sy0">*</span>sessions<span class="sy0">*</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
    <span class="br0">&#40;</span><span class="kw1">cdr</span> sp<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


<p>In the <tt>and-let*</tt> macro, the clauses are evaluated and the variables are bound sequentially, creating new scopes for the next expressions. If any of the forms evaluates to <tt>#f</tt> (false in Scheme), the computation is aborted, no other expressions are evaluated, and the whole form evaluates to <tt>#f</tt>. How would I write this in concise Ruby?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artisancoder.com/2008/12/equivalent-of-and-let/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

