<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:ent="http://www.purl.org/NET/ENT/1.0/" version="2.0">
  <channel>
    <title>Curiouser and Curiouser! on monads</title>
    <link>http://matt.blogs.it/</link>
    <description>RSS feed for topic monads</description>
    <copyright>Copyright 2008 Matt Mower. Some rights reserved.</copyright>
    <generator>Squib/0.5.0.382</generator>
    <managingEditor>self@mattmower.com</managingEditor>
    <webMaster>self@mattmower.com</webMaster>
    <language>en-gb</language>
    <item>
      <title>Ick</title>
      <link>http://matt.blogs.it/entries/00002812.html</link>
      <pubDate>Tue, 11 Mar 2008 15:23:55 +0000</pubDate>
      <description>&lt;p&gt;Okay suppress your gagging reflex. Ick is actually the &lt;a href="https://rubyforge.org/projects/ick/"&gt;Invocation Construction Kit&lt;/a&gt; by &lt;a href="http://weblog.raganwald.com/"&gt;Reginald Braithwaite&lt;/a&gt; which is a kit for building language abstractions like &lt;code&gt;#andand&lt;/code&gt;, &lt;code&gt;#if_not_nil&lt;/code&gt;, and &lt;code&gt;#try&lt;/code&gt; in a more structured way.&lt;/p&gt;

&lt;p&gt;For example a common pattern in code is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;x = some_expr
do_something_with( x )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There's nothing inherently wrong with this code but it leaves &lt;code&gt;x&lt;/code&gt; in scope past the point where it's needed and, implicit in that, is that it's a little harder to separate the expression using &lt;code&gt;x&lt;/code&gt; from the code around it if we want to refactor it later on.&lt;/p&gt;

&lt;p&gt;Ick defines &lt;code&gt;#let()&lt;/code&gt; for exactly this purpose:&lt;/p&gt;

&lt;p&gt;let( some&lt;em&gt;expr ) { |x| do&lt;/em&gt;something_with( x ) }&lt;/p&gt;

&lt;p&gt;In this example it's very clear what the required scope is for &lt;code&gt;x&lt;/code&gt; and that it can be moved without affecting other code (obviously taking into account if the return value for &lt;code&gt;let&lt;/code&gt; is used).&lt;/p&gt;

&lt;p&gt;Now lots of people are defining methods like &lt;code&gt;#let&lt;/code&gt; and &lt;code&gt;#maybe&lt;/code&gt;, so how is Ick different? It's different in the way &lt;code&gt;#let&lt;/code&gt; is defined:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Let &amp;lt; Base
  evaluates_in_calling_environment and returns_result
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There is some magic going on by which this &lt;code&gt;Let&lt;/code&gt; class is used through a method on &lt;code&gt;Object&lt;/code&gt; but ignoring that, the definition of &lt;code&gt;#let&lt;/code&gt; is in terms of &lt;em&gt;fundamental operations of evaluation&lt;/em&gt;. Ick has abstracted what it means to evaluate an expression.&lt;/p&gt;

&lt;p&gt;By the same means other forms such as &lt;code&gt;#try&lt;/code&gt; and &lt;code&gt;#maybe&lt;/code&gt; are built up. If you want to create a new abstraction you can build it from the building blocks like &lt;code&gt;evaluates_in_value_environment&lt;/code&gt; and create new building blocks.&lt;/p&gt;

&lt;p&gt;Ick seems to me to be a very powerful tool for Ruby programmers.&lt;/p&gt;</description>
      <guid isPermaLink="true">http://matt.blogs.it/entries/00002812.html</guid>
      <ent:cloud ent:href="http://matt.blogs.it/topics/">
      </ent:cloud>
    </item>
  </channel>
</rss>
