<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6115154198867082591</id><updated>2011-07-12T17:51:12.199-07:00</updated><category term='nopants'/><category term='dispatch'/><category term='scala'/><category term='ant'/><category term='facelets'/><category term='implicit'/><category term='jsf'/><category term='jug'/><category term='clojure'/><category term='glassfish'/><category term='scalacheck'/><category term='multimethods'/><category term='methodology'/><category term='eclipse'/><category term='hudson'/><category term='parser'/><category term='emoticon'/><category term='erasure'/><category term='netbeans'/><title type='text'>Cleverly Titled Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-5444166336751212551</id><published>2010-03-05T10:18:00.001-08:00</published><updated>2010-03-05T10:50:21.386-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='nopants'/><category scheme='http://www.blogger.com/atom/ns#' term='methodology'/><title type='text'>NoPANTS</title><content type='html'>I'm normally pretty narrowly focused on technical subjects on this blog, and don't stray into matters of methodology or process.  Besides a general lack of competence in this area, it is also to avoid the incessant back-and-forth religious type wars you get into when discussing anything remotely related to methodology.  However, I would like to put a plug in for the burgeoning NoPANTS movement.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What is NoPANTS?&lt;/span&gt;&lt;br /&gt;Before you jump in with counter-examples pointing out all the benefits of pants, please keep in mind that NoPANTS stands for "Not Only PANTS" (kilts?  chaps?), and does not mean your should &lt;span style="font-style:italic;"&gt;never&lt;/span&gt; wear pants.  Use the right tool for the job. Having said that, it is clear that most development efforts would benefit from a lack of pants.  Convincing you of the superiority of NoPANTS is something I'll save for a future blog post.  Instead, I'll focus on how you can implement NoPANTS at your workplace.&lt;br /&gt;&lt;br /&gt;First, you will need to have a safe NoPANTS environment within which you can operate.  If you work in a company where your management or HR department is clueless enough to attempt to specify pant-wearing for all employees, I suggest you begin looking for a new job.  For those of us lucky enough to work in a supportive atmosphere, a pants-optional conference room is a must.&lt;br /&gt;&lt;br /&gt;The cost of making changes to a project increase dramatically as you progress from the design through implementation, deployment, and maintenance stages.  It is important that you have a place where you can be completely open with each other during the initial design stages.  The pants-optional conference room fulfills this need.  Besides the obligatory whiteboards and large computer screen, it is important that you do not have a conference table that occludes the pantless aspects of the interaction.  My solution is to have rolling, freestanding trays for the necessary equipment, and populate the rest of the room with comfortable chairs, preferably leather or other easily-cleanable covering.&lt;br /&gt;&lt;br /&gt;Here are a couple of pictures of our Pants-Optional conference room:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_INwNDL0-MCk/S5FQGGPldXI/AAAAAAAAAIE/AbO8dfLotIg/s1600-h/conf1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 300px;" src="http://1.bp.blogspot.com/_INwNDL0-MCk/S5FQGGPldXI/AAAAAAAAAIE/AbO8dfLotIg/s400/conf1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5445221490153059698" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_INwNDL0-MCk/S5FQYF4Qx-I/AAAAAAAAAIM/PKfG77gO5Tg/s1600-h/conf2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 300px;" src="http://4.bp.blogspot.com/_INwNDL0-MCk/S5FQYF4Qx-I/AAAAAAAAAIM/PKfG77gO5Tg/s400/conf2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5445221799292880866" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For inspiration, sometimes it is useful to have a focusing picture.  We have used a picture of &lt;a href="http://twitter.com/sherod"&gt;Steven Herod&lt;/a&gt;, one of the pioneers in the NoPANTS movement.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_INwNDL0-MCk/S5FRF-AvMQI/AAAAAAAAAIU/YNmhILt084A/s1600-h/conf3.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 300px;" src="http://2.bp.blogspot.com/_INwNDL0-MCk/S5FRF-AvMQI/AAAAAAAAAIU/YNmhILt084A/s400/conf3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5445222587454927106" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_INwNDL0-MCk/S5FRNw_6YpI/AAAAAAAAAIc/0CGcGh6rdx8/s1600-h/conf4.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 300px;" src="http://1.bp.blogspot.com/_INwNDL0-MCk/S5FRNw_6YpI/AAAAAAAAAIc/0CGcGh6rdx8/s400/conf4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5445222721400758930" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you have a NoPANTS success story, please share it in the comments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-5444166336751212551?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/5444166336751212551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=5444166336751212551' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/5444166336751212551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/5444166336751212551'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2010/03/nopants.html' title='NoPANTS'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_INwNDL0-MCk/S5FQGGPldXI/AAAAAAAAAIE/AbO8dfLotIg/s72-c/conf1.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-2894577371434770924</id><published>2010-01-06T12:56:00.000-08:00</published><updated>2010-01-07T14:43:27.136-08:00</updated><title type='text'>Dynamic Method Interceptors in Scala</title><content type='html'>In my &lt;a href="http://cleverlytitled.blogspot.com/2010/01/dynamic-dispatch-in-scala.html"&gt;previous post&lt;/a&gt; I showed a rough simulation of Clojure's multimethods implemented in Scala.  What if we wanted to extend that to allow dynamic interceptors on these methods?&lt;br /&gt;&lt;br /&gt;Here's example usage showing how they stack on each other:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;  val numToString = DynDispatch.defMulti { i: Int =&gt;&lt;br /&gt;    i match {&lt;br /&gt;      case 1 =&amp;gt; &amp;quot;one&amp;quot;&lt;br /&gt;      case 2 =&amp;gt; &amp;quot;two&amp;quot;&lt;br /&gt;      case 3 =&amp;gt; &amp;quot;three&amp;quot;&lt;br /&gt;      case _ =&amp;gt; &amp;quot;bignumber&amp;quot;&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  numToString(2) // &amp;quot;two&amp;quot;&lt;br /&gt;  &lt;br /&gt;  // add logging?&lt;br /&gt;  numToString.onMethod { (i, s) =&amp;gt;&lt;br /&gt;    println(&amp;quot;called numToString(&amp;quot; + i + &amp;quot;) and returned: &amp;quot; + s)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  numToString(3) // called numToString(3) and returned: three&lt;br /&gt;  &lt;br /&gt;  numToString.beforeMethod { _-1 } // evil... subtract one from input&lt;br /&gt;  &lt;br /&gt;  numToString(3) // called numToString(3) and returned: two&lt;br /&gt;  &lt;br /&gt;  numToString.afterMethod { _ toUpperCase }&lt;br /&gt;  &lt;br /&gt;  numToString(2) // called numToString(2) and returned: ONE&lt;br /&gt;  &lt;br /&gt;  numToString.afterMethod { _.substring(1) }&lt;br /&gt;  &lt;br /&gt;  numToString(2) // called numToString(2) and returned: NE&lt;br /&gt;  &lt;br /&gt;  numToString.aroundMethod { f =&amp;gt;&lt;br /&gt;    { i: Int =&amp;gt; f(i+1).reverse }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  numToString(2) // called numToString(2) and returned: OW&lt;br /&gt;  &lt;br /&gt;  numToString.aroundMethod { f =&amp;gt;&lt;br /&gt;    { i: Int =&amp;gt; &amp;quot;hello&amp;quot; }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  numToString(2) // called numToString(2) and returned: hello&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Our dispatcher definition looks like this:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;object DynDispatch {&lt;br /&gt;  class DynMethod[A,R] {&lt;br /&gt;    import scala.collection.mutable.ListBuffer&lt;br /&gt;    private[this] val methods = ListBuffer[PartialFunction[A,R]]()&lt;br /&gt;    private[this] val around = ListBuffer[(A=&amp;gt;R) =&amp;gt; (A=&amp;gt;R)]()&lt;br /&gt;    private[this] val on = ListBuffer[(A,R)=&amp;gt; Unit]()&lt;br /&gt;    &lt;br /&gt;    def defMethod(m: PartialFunction[A,R]) = methods += m&lt;br /&gt;    def beforeMethod(b: A =&amp;gt; A) = around += { f =&amp;gt; { x =&amp;gt; f(b(x)) } }&lt;br /&gt;    def afterMethod(a: R =&amp;gt; R) = around += { f =&amp;gt; { x =&amp;gt; a(f(x)) } }&lt;br /&gt;    def aroundMethod(a: (A=&amp;gt;R) =&amp;gt; (A=&amp;gt;R)) = around += a&lt;br /&gt;    def onMethod(o: (A,R) =&amp;gt; Unit) = on += o&lt;br /&gt;    &lt;br /&gt;    def apply(args: A): R = {&lt;br /&gt;      def applyChain[X,Y] = { ( x: X, f: X =&amp;gt; Y) =&amp;gt; f(x) }&lt;br /&gt;      def innerApply: A =&amp;gt; R = { a: A =&amp;gt;&lt;br /&gt;        methods.reverse.find(_.isDefinedAt(a)) match {&lt;br /&gt;          case Some(f) =&amp;gt; f(a)&lt;br /&gt;          case None =&amp;gt; throw new Exception(&amp;quot;Method not defined for: &amp;quot; + a)&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;      val result = (around.foldLeft(innerApply)(applyChain))(args)&lt;br /&gt;      on foreach { _(args: A, result: R) }&lt;br /&gt;      result&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def defMulti[A,R] = new DynMethod[A,R]&lt;br /&gt;  def defMulti[A,R](f: A =&amp;gt; R) = {&lt;br /&gt;    val dm = new DynMethod[A,R]&lt;br /&gt;    dm.defMethod { case a =&amp;gt; f(a) }&lt;br /&gt;    dm&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And, here is an example class hierarchy showing some usage:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;trait Comedian {&lt;br /&gt;  def perform(props: Props) = "Generic performance"&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// comedic props&lt;br /&gt;trait Props&lt;br /&gt;case class NoProps extends Props&lt;br /&gt;case class SledgeHammer extends Props&lt;br /&gt;case class MultipleProps extends Props&lt;br /&gt;&lt;br /&gt;trait DynamicComedian extends Comedian { &lt;br /&gt;  // make perform dynamic&lt;br /&gt;  val perform = DynDispatch.defMulti(super.perform _)&lt;br /&gt;  override def perform(props: Props) = perform.apply(props)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Gallagher extends DynamicComedian {&lt;br /&gt;  perform.defMethod { case p: MultipleProps =&gt;&lt;br /&gt;    "Lots of stuff"&lt;br /&gt;  }&lt;br /&gt;  perform.defMethod { case p: SledgeHammer =&gt;&lt;br /&gt;    "Somebody is getting messy"&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class ChrisRock extends DynamicComedian {&lt;br /&gt;  perform.defMethod { case p: Props =&gt;&lt;br /&gt;    "Tell black jokes"&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class GeorgeLopez extends ChrisRock {&lt;br /&gt;  perform.afterMethod { result =&gt;&lt;br /&gt;    result.replaceAll("black", "latino")&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class GeorgeCarlin extends DynamicComedian {&lt;br /&gt;  perform.defMethod { case p: Props =&gt;&lt;br /&gt;    "I don't need any fuckin' props... shit!"&lt;br /&gt;  }&lt;br /&gt;  perform.defMethod { case p: NoProps =&gt;&lt;br /&gt;    "Let me tell you about swear words"&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;trait LoggingComedian {&lt;br /&gt;  self: DynamicComedian =&gt;&lt;br /&gt;  perform.onMethod { (props, result) =&gt;&lt;br /&gt;    println("result: " + result)&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;trait UnpaidComedian {&lt;br /&gt;  self: DynamicComedian =&gt;&lt;br /&gt;  perform.aroundMethod { perf =&gt;&lt;br /&gt;    (props) =&gt; "Whatever, I'm not performing"&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;object App extends Application {&lt;br /&gt;  &lt;br /&gt;  val gl = new GeorgeLopez with LoggingComedian&lt;br /&gt;  gl.perform(NoProps()) // result: Tell latino jokes&lt;br /&gt;  &lt;br /&gt;  val gc = new GeorgeCarlin with LoggingComedian&lt;br /&gt;  gc.perform(NoProps()) // result: Let me tell you about swear words&lt;br /&gt;  &lt;br /&gt;  val g = new Gallagher with LoggingComedian&lt;br /&gt;  g.perform(SledgeHammer()) // result: Somebody is getting messy&lt;br /&gt;  &lt;br /&gt;  val gu = new Gallagher with LoggingComedian with UnpaidComedian&lt;br /&gt;  gu.perform(SledgeHammer()) // result: Whatever, I'm not performing&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, if you haven't fallen asleep by now, you are probably wondering why we would go through this trouble?  The Comedian class hierarchy with mixin traits could be more clearly and performantly defined statically using standard method overrides.&lt;br /&gt;&lt;br /&gt;For example, the LoggingComedian trait could be defined like:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;trait Comedian {&lt;br /&gt;  def perform(props: Props) = &amp;quot;Generic performance&amp;quot;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// comedic props&lt;br /&gt;trait Props&lt;br /&gt;case class NoProps extends Props&lt;br /&gt;case class SledgeHammer extends Props&lt;br /&gt;case class MultipleProps extends Props&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class Gallagher extends Comedian {&lt;br /&gt;  def perform(p: MultipleProps) = {&lt;br /&gt;    &amp;quot;Lots of stuff&amp;quot;&lt;br /&gt;  }&lt;br /&gt;  def perform(p: SledgeHammer) = {&lt;br /&gt;    &amp;quot;Somebody is getting messy&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class ChrisRock extends Comedian {&lt;br /&gt;  override def perform(p: Props) = {&lt;br /&gt;    &amp;quot;Tell black jokes&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class GeorgeLopez extends ChrisRock {&lt;br /&gt;  override def perform(p: Props) = {&lt;br /&gt;    super.perform(p).replaceAll(&amp;quot;black&amp;quot;, &amp;quot;latino&amp;quot;)&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class GeorgeCarlin extends Comedian {&lt;br /&gt;  override def perform(props: Props) = {&lt;br /&gt;    props match {&lt;br /&gt;      case p: NoProps =&amp;gt; &amp;quot;Let me tell you about swear words&amp;quot;&lt;br /&gt;      case _ =&amp;gt; &amp;quot;I don't need any fuckin' props... shit!&amp;quot;&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;trait LoggingComedian extends Comedian {&lt;br /&gt;  override def perform(props: Props) = {&lt;br /&gt;    val result = super.perform(props)&lt;br /&gt;    println(&amp;quot;result: &amp;quot; + result)&lt;br /&gt;    result&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;trait UnpaidComedian extends Comedian {&lt;br /&gt;  override def perform(props: Props) = {&lt;br /&gt;    &amp;quot;Whatever, I'm not performing&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So, unless you need the runtime argument specialization that defMulti provides, there is no need for the interceptors, right?&lt;br /&gt;&lt;br /&gt;Let's run it:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;object App2 extends Application {&lt;br /&gt;  &lt;br /&gt;  val gl = new GeorgeLopez with LoggingComedian&lt;br /&gt;  gl.perform(NoProps()) // result: Tell latino jokes&lt;br /&gt;  &lt;br /&gt;  val gc = new GeorgeCarlin with LoggingComedian&lt;br /&gt;  gc.perform(NoProps()) // result: Let me tell you about swear words&lt;br /&gt;  &lt;br /&gt;  val g = new Gallagher with LoggingComedian&lt;br /&gt;  g.perform(SledgeHammer()) // no output!!&lt;br /&gt;  &lt;br /&gt;  val gu = new Gallagher with LoggingComedian with UnpaidComedian&lt;br /&gt;  gu.perform(SledgeHammer()) // no output!!&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;What happened?  Why is Gallagher not logging?  Well, if you want to override a method in a trait, you need to override each combination of the arguments (here, SledgeHammer in addition to the generic Props).&lt;br /&gt;&lt;br /&gt;Another useful property of the dynamic interceptors for this usage pattern is that you can use a class in the self type of the mixin, and not just a trait (what if Comedian was concrete?).&lt;br /&gt;&lt;br /&gt;But, the most dramatic effect of these dynamic interceptors is that you can now get non-lexical, dynamic scoping.  You can attach interceptors to individual instances of Comedian and send them down the call stack.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;  val georgeCarlin = comedianService.get(&amp;quot;George Carlin&amp;quot;)&lt;br /&gt;  &lt;br /&gt;  georgeCarlin.perform.aroundMethod { f =&amp;gt;&lt;br /&gt;    (props) =&amp;gt; {&lt;br /&gt;      myCallBack(props)&lt;br /&gt;      &amp;quot;Hear the one about the observer pattern?\n&amp;quot; + f(props)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  myOtherService(georgeCarlin)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Any other uses?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-2894577371434770924?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/2894577371434770924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=2894577371434770924' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/2894577371434770924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/2894577371434770924'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2010/01/dynamic-method-interceptors-in-scala.html' title='Dynamic Method Interceptors in Scala'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-5868859188178752281</id><published>2010-01-03T01:19:00.000-08:00</published><updated>2010-01-03T11:02:22.166-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='multimethods'/><category scheme='http://www.blogger.com/atom/ns#' term='clojure'/><category scheme='http://www.blogger.com/atom/ns#' term='dispatch'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Dynamic Dispatch in Scala</title><content type='html'>Clojure has &lt;a href="http://clojure.org/runtime_polymorphism"&gt;runtime polymorphism&lt;/a&gt; that goes beyond the single, receiver-based dispatch that you find in Java or Scala.  You can dispatch based not only on the type of all objects involved (&lt;a href="http://en.wikipedia.org/wiki/Multiple_dispatch"&gt;multiple dispatch&lt;/a&gt;), but also on the result of an arbitrary function (&lt;a href="http://www.cs.ucla.edu/%7Etodd/research/jpred.html"&gt;predicate dispatch&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;Why should I care?  Let's explore this in Scala using the Bunny/Lion example &lt;a href="http://clojure.org/runtime_polymorphism"&gt;as shown&lt;/a&gt; on Clojure site.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;trait Animal {&lt;br /&gt; def encounter(a: Animal) = "Generic animal encounter"&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Bunny extends Animal {&lt;br /&gt; override def encounter(a: Animal) = "Generic Bunny encounter"&lt;br /&gt; def encounter(b: Bunny) = "Mate"&lt;br /&gt; def encounter(l: Lion) = "Run away" &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Lion extends Animal {&lt;br /&gt; override def encounter(a: Animal) = "Generic Lion encounter"&lt;br /&gt; def encounter(b: Bunny) = "Eat"&lt;br /&gt; def encounter(l: Lion) = "Fight"&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This does what we want in a straight-forward example:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt; val bunny = new Bunny&lt;br /&gt; val lion = new Lion&lt;br /&gt; bunny encounter lion // Run away&lt;br /&gt; bunny encounter bunny // Mate&lt;br /&gt; lion encounter lion  // Fight&lt;br /&gt; lion encounter bunny  // Eat&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But, what happens if we are dealing with a List[Animal]? Or, we have some convenience function like this:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt; def printEncounter(a1: Animal, a2: Animal) = {&lt;br /&gt;   def s(a: Animal) = a.getClass.toString.split("\\.").last&lt;br /&gt;   println(s(a1) + " vs " + s(a2) + ": " + (a1 encounter a2))&lt;br /&gt; }&lt;br /&gt; val bunny = new Bunny&lt;br /&gt; val lion = new Lion&lt;br /&gt;&lt;br /&gt; printEncounter(bunny, lion)&lt;br /&gt; printEncounter(bunny, bunny)&lt;br /&gt; printEncounter(lion, lion)&lt;br /&gt; printEncounter(lion, bunny)&lt;br /&gt;&lt;br /&gt; /* Output:&lt;br /&gt;  * Bunny vs Lion: Generic Bunny encounter&lt;br /&gt;  * Bunny vs Bunny: Generic Bunny encounter&lt;br /&gt;  * Lion vs Lion: Generic Lion encounter&lt;br /&gt;  * Lion vs Bunny: Generic Lion encounter&lt;br /&gt;  */&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Oh, my!  We seem to have dynamically determined which method definition to use based on the runtime type of the receiver object, but not on any of the objects in the argument list.  This is the standard functionality you get with Java or Scala.&lt;br /&gt;&lt;br /&gt;How would we fix this in Scala?  A first pass might look like this:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;trait Animal {&lt;br /&gt;  def encounter(a: Animal) = &amp;quot;Generic animal encounter&amp;quot;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Bunny extends Animal {&lt;br /&gt;  override def encounter(a: Animal) = a match {&lt;br /&gt;    case b: Bunny =&amp;gt; &amp;quot;Mate&amp;quot;&lt;br /&gt;    case l: Lion =&amp;gt; &amp;quot;Run away&amp;quot;&lt;br /&gt;    case _ =&amp;gt; &amp;quot;Generic Bunny encounter&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Lion extends Animal {&lt;br /&gt;  override def encounter(a: Animal) = a match {&lt;br /&gt;    case b: Bunny =&amp;gt; &amp;quot;Eat&amp;quot;&lt;br /&gt;    case l: Lion =&amp;gt; &amp;quot;Fight&amp;quot;&lt;br /&gt;    case _ =&amp;gt; &amp;quot;Generic Lion encounter&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Of course, like Clojure's multimethods, pattern matching in Scala is not limited to just type information, but can also look at dynamic runtime information.  You could easily imagine a lazy rabbit that only ran from lions that had been identified as hungry at the time:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;class Bunny extends Animal {&lt;br /&gt;  override def encounter(a: Animal) = a match {&lt;br /&gt;    case b: Bunny =&amp;gt; &amp;quot;Mate&amp;quot;&lt;br /&gt;    case l: Lion if (l.isHungry) =&amp;gt; &amp;quot;Run away&amp;quot;&lt;br /&gt;    case l: Lion =&amp;gt; &amp;quot;Ignore&amp;quot;&lt;br /&gt;    case _ =&amp;gt; &amp;quot;Generic Bunny encounter&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So, how is this different from the Clojure approach?  Rich Hickey &lt;a href="http://sadekdrobi.com/2009/05/27/multimethod-in-clojure-should-i-call-it-first-class-pattern-matching-or-pattern-matching-in-disguise/#comment-15412"&gt;commented on this&lt;/a&gt;, which I'll quote here:&lt;br /&gt;&lt;blockquote&gt;Multimethods differ from pattern matching in a number of ways. Two that matter (to me) are:&lt;br /&gt;&lt;br /&gt;Pattern matching is usually ‘closed’, in the sense that all possibilities must be enumerated in a single scope.&lt;br /&gt;&lt;br /&gt;Pattern matches are usually declaration order dependent.&lt;br /&gt;&lt;br /&gt;Multimethods, OTOH, are an open set. You can define a new method any time, anywhere – they need not be lexically co-located. Multimethod operation is independent of definition order. They are very dynamic, and thus a good fit for Clojure.&lt;br /&gt;&lt;br /&gt;There are other differences, of course, e.g. pattern matching usually has sugar for structural and type matches, and often exhaustiveness checking. I’m still waiting for someone to contribute a pattern-matching macro for Clojure, as I don’t think one makes the other redundant.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;What could we do in Scala to address some of the deficiencies that Rich is pointing out?  A dispatch mechanism could be defined like this:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;object DynDispatch {&lt;br /&gt;  class DynMethod[A,R] {&lt;br /&gt;    val methods = scala.collection.mutable.ListBuffer[PartialFunction[A,R]]()&lt;br /&gt;    def defMethod(m: PartialFunction[A,R]) = {&lt;br /&gt;      methods += m&lt;br /&gt;    }&lt;br /&gt;    def apply(args: A): R = {&lt;br /&gt;      methods.reverse.find(_.isDefinedAt(args)) match {&lt;br /&gt;        case Some(f) =&amp;gt; f(args)&lt;br /&gt;        case None =&amp;gt; throw new Exception(&amp;quot;huh?&amp;quot;)&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  def defMulti[A,R] = new DynMethod[A,R]&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Class and method definition would then look like this:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;trait Animal {&lt;br /&gt;  val encounter = DynDispatch.defMulti[Animal, String]&lt;br /&gt;  encounter.defMethod { case a: Animal =&amp;gt;&lt;br /&gt;    &amp;quot;Generic Encounter&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Bunny extends Animal {&lt;br /&gt;  encounter.defMethod { case a =&amp;gt;&lt;br /&gt;    &amp;quot;Generic Bunny Encounter&amp;quot;&lt;br /&gt;  }&lt;br /&gt;  encounter.defMethod { case b: Bunny =&amp;gt;&lt;br /&gt;    &amp;quot;Mate&amp;quot;&lt;br /&gt;  }&lt;br /&gt;  encounter.defMethod { case l: Lion =&amp;gt;&lt;br /&gt;    &amp;quot;Run away&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Lion extends Animal {&lt;br /&gt;  encounter.defMethod { case a =&amp;gt;&lt;br /&gt;    &amp;quot;Generic Lion encounter&amp;quot;&lt;br /&gt;  }&lt;br /&gt;  encounter.defMethod { case b: Bunny =&amp;gt;&lt;br /&gt;    &amp;quot;Eat&amp;quot;&lt;br /&gt;  }&lt;br /&gt;  encounter.defMethod { case l: Lion =&amp;gt;&lt;br /&gt;    &amp;quot;Fight&amp;quot;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Calling syntax is the same as with the traditionally-defined methods, but the methods are dispatched dynamically.  This seems to address the "closed"  issue of needing to enumerate all the possibilities within a single scope.  Heck, you can even add or redefine methods for individual instances of objects:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;  val lion = new Lion&lt;br /&gt;  val bunny = new Bunny&lt;br /&gt;  bunny.encounter.defMethod { case l: Lion if (!l.isHungry) =&amp;gt;&lt;br /&gt;    &amp;quot;Ignore&amp;quot;&lt;br /&gt;  }&lt;br /&gt;  bunny encounter lion // depends on if the lion is hungry&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that the methods are still type-safe, as the type of the argument list is required to be declared in the DynDispatch.defMulti[A,R] method.  For methods that have differing arities or disjoint types, you lose some type safety, but the syntax is still convenient:&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;class TigerWoods {&lt;br /&gt;  val tryst = DynDispatch.defMulti[AnyRef,Alimony]&lt;br /&gt;  tryst.defMethod { case m: Mistress =&amp;gt;&lt;br /&gt;    Alimony(1000000)&lt;br /&gt;  }&lt;br /&gt;  tryst.defMethod { case (m1: Mistress, m2: Mistress) =&amp;gt;&lt;br /&gt;    Alimony(5000000)&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;  // ...&lt;br /&gt;&lt;br /&gt;  val t = new TigerWoods&lt;br /&gt;  t.tryst(Mistress(&amp;quot;Diane&amp;quot;))&lt;br /&gt;  t.tryst(Mistress(&amp;quot;Emily&amp;quot;), Mistress(&amp;quot;Sara&amp;quot;))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;One big disadvantage of this implementation is the runtime overhead of method definition and queuing with each object instantiation.  I don't know to what extent this could be minimized with some magical combination of caching and laziness.&lt;br /&gt;&lt;br /&gt;We are also still dependent on order of definition to resolve any ambiguities within the method definitions.  This naive implementation takes the easiest path and matches from bottom to top within a scope, with scopes from instance -&gt; subclass -&gt; superclass.  A more sophisticated approach would find the "most specific" combination of the receiver and argument list, with ambiguities resolved with runtime exceptions or some other approach (like order dependence).&lt;br /&gt;&lt;br /&gt;I like the order dependence of pattern matching within Scala, where the different cases are all present within the same block.  However, for this application, with methods defined in multiple places, I can see it as a source of confusion.  But, I'm also not a big fan of discovering ambiguities at runtime.&lt;br /&gt;&lt;br /&gt;What is your favorite way to dispatch?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-5868859188178752281?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/5868859188178752281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=5868859188178752281' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/5868859188178752281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/5868859188178752281'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2010/01/dynamic-dispatch-in-scala.html' title='Dynamic Dispatch in Scala'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-8859885613683777811</id><published>2009-11-09T16:05:00.000-08:00</published><updated>2009-11-09T16:07:12.929-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jug'/><category scheme='http://www.blogger.com/atom/ns#' term='scalacheck'/><title type='text'>OKCJUG Lightning Talks</title><content type='html'>This month, we will have lightning presentations... 5 minutes and 20 slides set on auto-timer.  I'll do some TDD and ScalaCheck directly through powerpoint!  Get it &lt;a href="http://sites.google.com/site/okcjugfiles/Home/05-Blevins-Automatictestdatageneration.pdf?attredirects=0&amp;d=1"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-8859885613683777811?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/8859885613683777811/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=8859885613683777811' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/8859885613683777811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/8859885613683777811'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/11/okcjug-lightning-talks.html' title='OKCJUG Lightning Talks'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-7109321181220719465</id><published>2009-10-29T21:00:00.000-07:00</published><updated>2009-10-30T09:21:19.804-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scalacheck'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>ScalaCheck is Neat-o!</title><content type='html'>&lt;a href="http://code.google.com/p/scalacheck/"&gt;ScalaCheck&lt;/a&gt; is a testing library for Scala (and Java!).  It is a step beyond just writing tests, you actually assert properties of some code and it generates a number of tests dynamically to test it.&lt;br /&gt;&lt;br /&gt;A recent example of using this came from &lt;a href="http://stackoverflow.com/questions/1645260/can-i-construct-a-bigint-with-any-byte-array-scala"&gt;this StackOverflow question&lt;/a&gt;.  It required a largish number of test cases, so it seemed a perfect fit to try out ScalaCheck.&lt;br /&gt;&lt;br /&gt;The code to test was:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;package blevins.example&lt;br /&gt;&lt;br /&gt;object BigIntEncoder {&lt;br /&gt;  val radix = 36&lt;br /&gt;  &lt;br /&gt;  implicit def byteArrayToString(ba: Array[Byte]): String = {&lt;br /&gt;    new java.math.BigInteger(ba).toString(radix)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  implicit def stringToByteArray(s: String): Array[Byte] = {&lt;br /&gt;    new java.math.BigInteger(s, radix).toByteArray&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To test, you write something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;package blevins.example&lt;br /&gt;&lt;br /&gt;import org.scalacheck._&lt;br /&gt;&lt;br /&gt;object BigIntEncoderSpecification extends Properties(&amp;quot;BigIntEncoder&amp;quot;) {&lt;br /&gt;  import Prop._&lt;br /&gt;  import Gen._&lt;br /&gt;  &lt;br /&gt;  def genArray( fill: Array[Byte] =&amp;gt; Unit) = Gen.sized { size =&amp;gt; &lt;br /&gt;    val bytes: Array[Byte] = new Array[Byte](size)&lt;br /&gt;    fill(bytes)&lt;br /&gt;    bytes&lt;br /&gt;  } suchThat (_.size &amp;gt; 0)&lt;br /&gt;&lt;br /&gt;  def filledByteArray( i: int ) = genArray(bytes =&amp;gt;&lt;br /&gt;    for (i &amp;lt;- 0 to bytes.length - 1) { bytes(i) = i.asInstanceOf[Byte] }&lt;br /&gt;  )&lt;br /&gt;  &lt;br /&gt;  val arbByteArray = genArray(bytes =&amp;gt; scala.util.Random.nextBytes(bytes))&lt;br /&gt;&lt;br /&gt;  val zeroByteArray = filledByteArray( 0x00 )&lt;br /&gt;  &lt;br /&gt;  val fullByteArray = filledByteArray( 0xff )&lt;br /&gt;  &lt;br /&gt;  def checkEncodingRoundTrip = { (ba: Array[Byte]) =&amp;gt; &lt;br /&gt;    import BigIntEncoder._&lt;br /&gt;    ba deepEquals stringToByteArray(byteArrayToString(ba))&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  property(&amp;quot;random&amp;quot;) = forAll(arbByteArray)(checkEncodingRoundTrip)&lt;br /&gt;  property(&amp;quot;zero&amp;quot;) = forAll(zeroByteArray)(checkEncodingRoundTrip)&lt;br /&gt;  property(&amp;quot;full&amp;quot;) = forAll(fullByteArray)(checkEncodingRoundTrip)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This code will generate random, all-zero, and all-binary-ones (0xff) arrays and test their equality using the checkEncodingRoundTrip method, which exercises the code to be tested.  It failed sometimes for the random array, and failed all the time for the other two types.  I also noticed that the random array failed when the first byte of the arrays was either 0x00 or 0xff.  I assumed that this was a side effect of BigInteger taking the two-complement of the byte array, so I padded it like so:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;package blevins.example&lt;br /&gt;&lt;br /&gt;object BigIntEncoder {&lt;br /&gt;  val radix = 36&lt;br /&gt;  &lt;br /&gt;  implicit def byteArrayToString(ba: Array[Byte]): String = {&lt;br /&gt;    new java.math.BigInteger(addByte(ba)).toString(radix)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  implicit def stringToByteArray(s: String): Array[Byte] = {&lt;br /&gt;    stripByte(new java.math.BigInteger(s, radix).toByteArray)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def addByte(ba: Array[Byte]): Array[Byte] = {&lt;br /&gt;    val h = new Array[Byte](1)&lt;br /&gt;    h(0) = 0x01&lt;br /&gt;    h ++ ba&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def stripByte(ba: Array[Byte]): Array[Byte] = {&lt;br /&gt;    ba.slice(1,ba.size)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This produced the desired results (all passing), but a large amount of output.  I wrote my own output-generator like this:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;package blevins.example&lt;br /&gt;&lt;br /&gt;object Test extends Application {&lt;br /&gt;  import org.scalacheck._&lt;br /&gt;  import org.scalacheck.Test._&lt;br /&gt;  &lt;br /&gt;  val params = Params(5000, 10, 1, 100, new java.util.Random(), 1, 1)&lt;br /&gt;  val props = checkProperties(BigIntEncoderSpecification, params)&lt;br /&gt;  for ((name, result) &amp;lt;- props) {&lt;br /&gt;    println(name + &amp;quot;: &amp;quot; + result.status)&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This also increased the number of tests-per-property from 100 to 5000.&lt;br /&gt;My output was:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;BigIntEncoder.random: Passed&lt;br /&gt;BigIntEncoder.zero: Passed&lt;br /&gt;BigIntEncoder.full: Passed&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Yay!  Now go watch TV.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-7109321181220719465?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/7109321181220719465/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=7109321181220719465' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/7109321181220719465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/7109321181220719465'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/10/scalacheck.html' title='ScalaCheck is Neat-o!'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-501508750227193907</id><published>2009-10-29T09:25:00.000-07:00</published><updated>2010-01-06T11:02:41.437-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Reflective Calls in Scala</title><content type='html'>Scala 2.8 contains two experimental features to reflectively invoke methods.  Are these cool?&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="scala"&gt;&lt;br /&gt;  import scala.reflect.RichClass._&lt;br /&gt;  &lt;br /&gt;  val hello = "hello"   &lt;br /&gt;  val helloStartsWith = classOf[String].reflectiveCall(hello, "startsWith")&lt;br /&gt;  val b1: Boolean = helloStartsWith("hell")&lt;br /&gt;  val b2: String = helloStartsWith("heaven") // ClassCastException (Boolean-&gt;String)&lt;br /&gt;  val b3 = helloStartsWith("blah") // ClassCastException (Boolean-&gt;Nothing)&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  import scala.reflect.Invocation._&lt;br /&gt;  &lt;br /&gt;  val team: AnyRef = "team"&lt;br /&gt;  val any = team o 'contains("I") // returns 'Any'&lt;br /&gt;  val b4: Boolean = team oo 'contains("I") // ok&lt;br /&gt;  val b5 = team oo 'contain("I") // ClassCastException (Boolean-&gt;Nothing)&lt;br /&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The methods called using "o" return "Any".  Both reflectiveCall(...) and the "oo" version return the inferred type.  Note that this doesn't relieve you from knowing the expected result type, or further reflecting it and casting.  This is shown in the runtime errors with b2, b3, and b5.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;EDIT:&lt;/span&gt; This post was accurate for the nightly 2.8 release when it was written, but this code appears to have been removed from the latest 2.8 betas.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-501508750227193907?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/501508750227193907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=501508750227193907' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/501508750227193907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/501508750227193907'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/10/reflective-calls-in-scala.html' title='Reflective Calls in Scala'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-1749015862184832531</id><published>2009-08-13T14:20:00.000-07:00</published><updated>2009-08-13T17:57:54.397-07:00</updated><title type='text'>BOM Differences</title><content type='html'>&lt;blockquote&gt;Sometimes it helps me think about my work if I write it out on virtual paper.  So, be warned that this post will probably not be very entertaining or educational.  But, I do promise that there is an obscure reference to the movie "Kung-Fu Panda" hidden within.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Here's an interesting project I'm working on.  The goal of the project is to effectively visualize the differences between two Bills of Materials (BOMs) from our ERP system.  For those unfamiliar with BOMs, they are just a hierarchical structure of the components that make up a product being manufactured.  A real nerd might call it an acyclic, directed, weighted (weights are the quantities) graph.  But, it is easier to just think of it as a tree.&lt;br /&gt;&lt;br /&gt;Turns out that it is pretty useful to be able to easily see what the differences are between two different bills of materials, especially for people who like to scratch their heads and figure out how to make the product cheaper, or what price to sell it for, or assign costs to products, etc.&lt;br /&gt;&lt;br /&gt;The first thought I hatched when thinking about how to implement this was to see how close my needs were to the Java Structure Comparison tool in Eclipse.  I have put many hours into driving this particular IDE, and it seems similar to what I wanted.&lt;br /&gt;&lt;br /&gt;For those unfamiliar with it, you can take a class that is similar to this:&lt;br /&gt;&lt;pre name="code" class="Java"&gt;&lt;br /&gt;package com.iecokc.cooking;&lt;br /&gt;&lt;br /&gt;public class CakeRecipe {&lt;br /&gt; public String flour;&lt;br /&gt; public String eggs;&lt;br /&gt; public String frosting;&lt;br /&gt; public void beatEggs() {}&lt;br /&gt; public void stir() {}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And another class like this:&lt;br /&gt;&lt;pre name="code" class="Java"&gt;&lt;br /&gt;package com.iecokc.baking;&lt;br /&gt;&lt;br /&gt;public class CakeRecipe {&lt;br /&gt; public String flour;&lt;br /&gt; public String eggs;&lt;br /&gt; public void beatEggs() {}&lt;br /&gt; public void stirBriskly() {}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and you end up with a navigable tree that shows only the differences, like this:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_INwNDL0-MCk/SoSjykw9yuI/AAAAAAAAAG0/hsOI0-855ow/s1600-h/bomdiffjava.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 221px; height: 147px;" src="http://2.bp.blogspot.com/_INwNDL0-MCk/SoSjykw9yuI/AAAAAAAAAG0/hsOI0-855ow/s400/bomdiffjava.jpg" border="0" alt="Java Structure Compare" id="BLOGGER_PHOTO_ID_5369596744990313186" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The problem with the comparison implemented in Eclipse is that it uses a strict definition of node identity in the trees that is compares.  For example, if I had renamed the one of the classes from "CakeRecipe" to "BundtCakeRecipe", Eclipse would have refused to even consider that these might be similar in structure and therefore should be compared.  Nope, different class name or method signature means that it is a completely different thing.&lt;br /&gt;&lt;br /&gt;Instead, I needed to have my comparison consider the concept of something being "mostly equal", or "mequal" (trademark pending).  If I can pin down this slippery concept of "mequals", I can then make a comparison structure that shows more than just adds and removes, but also edits of a particular node.  It might look like the mock-up below (courtesy of &lt;a href="http://twitter.com/vaughnmb"&gt;Brent&lt;/a&gt;).&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_INwNDL0-MCk/SoSMNXlsiHI/AAAAAAAAAGs/i-EpSJmWFDY/s1600-h/bomdiff2.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 236px;" src="http://4.bp.blogspot.com/_INwNDL0-MCk/SoSMNXlsiHI/AAAAAAAAAGs/i-EpSJmWFDY/s320/bomdiff2.jpg" border="0" alt="BOM Difference Mockup"id="BLOGGER_PHOTO_ID_5369570817030785138" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the tree above, two BOMs (say, "A" and "B") are compared.  The green nodes with a "+" next to them represent nodes that were added (in "B" but not in "A") and the red nodes with a "-" represent nodes that were removed (in "A" but not in "B").  The blue nodes with the pencil represent nodes that are in both BOMs, but are different in some way (a.k.a. - mequal).&lt;br /&gt;&lt;br /&gt;Now, there are many nodes that are exactly equals in both BOMs.  It might sometimes be useful to show them, and it would look like the gray nodes below:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_INwNDL0-MCk/SoSLKKditVI/AAAAAAAAAGc/c6pHEpNGbzM/s1600-h/bomdiff1.jpg"&gt;&lt;img style="cursor: pointer; width: 313px; height: 400px;" src="http://1.bp.blogspot.com/_INwNDL0-MCk/SoSLKKditVI/AAAAAAAAAGc/c6pHEpNGbzM/s400/bomdiff1.jpg" alt="Full BOM structure comparison" id="BLOGGER_PHOTO_ID_5369569662455690578" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So, how do I go about identifying the nodes that are mequal to each other between the two BOMs?  Well, it is not just a function of the two nodes in consideration, but also a function of the structure that they contain, and the structure that they are contained in.  For example, if there is a panel (however these are identified) in the top-level of each BOM, then these would probably be considered to be mequal.  But, if there are two panels in BOM "A" and only one in BOM "B", then there is a choice to be made: which panel in "A" is more mequal to the one in "B"?  Answering this question may need to consider the structure (child nodes) of the panels being analyzed.&lt;br /&gt;&lt;br /&gt;Whew!  This seems like it will be hard work.  So, I'll search for libraries that already implement it.  Since a BOM is a tree structure that could be represented in XML, maybe an XMLDiff library exists that I can leverage.  Let me search... yup!  There are about a thousand and one XML diff libraries, but I couldn't find a maintained one that worked on unsorted nodes and didn't rely on strict node identity.&lt;br /&gt;&lt;br /&gt;So, I search the research publications.  I particularly like some of the ideas from &lt;a href="http://www.seas.upenn.edu/~zives/03s/cis650/P026.PDF"&gt;this paper&lt;/a&gt;.  I'll charge blindly forward and try to implement it.  The next few blog posts will be about the implementation (if successful).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-1749015862184832531?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/1749015862184832531/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=1749015862184832531' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/1749015862184832531'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/1749015862184832531'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/08/bom-differences.html' title='BOM Differences'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_INwNDL0-MCk/SoSjykw9yuI/AAAAAAAAAG0/hsOI0-855ow/s72-c/bomdiffjava.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-6928908764369773583</id><published>2009-07-28T20:39:00.000-07:00</published><updated>2009-07-29T09:08:20.532-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Fuggin Programming</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_JvLtUi5aDZc/SnBxZsvZZQI/AAAAAAAAAA4/93n5d8VhuSs/s1600-h/pg13.gif"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 200px; height: 41px;" src="http://2.bp.blogspot.com/_JvLtUi5aDZc/SnBxZsvZZQI/AAAAAAAAAA4/93n5d8VhuSs/s200/pg13.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5363911842518885634" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_JvLtUi5aDZc/Sm_E6LDpVJI/AAAAAAAAAAw/xzCJZfTCf2o/s1600-h/blago.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 176px; height: 200px;" src="http://3.bp.blogspot.com/_JvLtUi5aDZc/Sm_E6LDpVJI/AAAAAAAAAAw/xzCJZfTCf2o/s200/blago.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5363722184901088402" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;WARNING: STRONG LANGUAGE AND BAD CODE&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Hey, Folks!  Blago here.&lt;br /&gt;I'm programmin now!  What, you didn't know I was doin that?  Well, fuck you.  I don't have much know-how under my belt yet, but I'm learnin this Scala shit that all the kids seem to be playin with.  It's fuckin great.  I mean, where else can I make a method name of &amp;quot;?&amp;lt;!#%^&amp;amp;*&amp;quot; and get away with it?  The syntax looks just like I talk.&lt;br /&gt;&lt;br /&gt;So, what can I code?  What I know about is governing, so let me distill this knowledge down to a mini-quick how-to-govern trait:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt; &lt;br /&gt;trait Governance {&lt;br /&gt;&lt;br /&gt;  type Favor&lt;br /&gt;  type Promise&lt;br /&gt;  type ShitIWant&lt;br /&gt;  type Lobbyist&lt;br /&gt;  type Bribe&lt;br /&gt;  &lt;br /&gt;  def solicit(favor: Favor)(lobbyist: Lobbyist): Bribe&lt;br /&gt;  def pickBest(bribes: Seq[Bribe]): Bribe&lt;br /&gt;  def accept(bribe: Bribe): Promise&lt;br /&gt;  def collect(promise: Promise): ShitIWant&lt;br /&gt;  &lt;br /&gt;  def govern(lobbyists: List[Lobbyist], power: Seq[Favor]) = {&lt;br /&gt;    for (favor &amp;lt;- power) yield&lt;br /&gt;     collect(accept(pickBest(lobbyists.map(solicit(favor)))))&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I make it look easy, huh?  Let's break it down now.  The world of politics is made up of Lobbyists, Favors, Promises, and Bribes.  Oh, and also shit-I-want.  The whole point of all the other stuff is to get more shit-I-want.&lt;br /&gt;&lt;br /&gt;So, let's look at the govern method.  The inputs needed to govern are Lobbyists and Power.  The Power gives you a steady stream of Favors that you can do for people, and you can keep that power as long as you *ahem* stay in office.  Then, you got the Lobbyists.  These fuckin pricks just want to get you to do favors for them for free.  Don't be a dumbass, if you got somethin golden, make'em pay up the ass for it.&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;  def govern(lobbyists: List[Lobbyist], power: Seq[Favor]) = { ... }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;How can you get the best deal for your Favors?  Well, you can't just give it to the first asshole that comes along.  You gotta shop it around.  Get out your little black book and make some calls.  This is illustrated in the solicit method&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;  def solicit(favor: Favor)(lobbyist: Lobbyist): Bribe&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So you solicit your current Favor to every fuggin lobbyist you know, and try to get a Bribe from each of them.  Then, you can compare them all to get the best one.&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;  def pickBest(bribes: Seq[Bribe]): Bribe&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The best Bribe you can then accept, getting a Promise to pay up.  You then collect on that Promise to get the ShitIWant, which is usually in the form of small unmarked bills (but not /that/ small).&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;  def accept(bribe: Bribe): Promise&lt;br /&gt;  def collect(promise: Promise): ShitIWant&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice that I'm usin what they call &amp;quot;abstract types&amp;quot; in this trait.  That means that a type like &amp;quot;ShitIWant&amp;quot; could really be anything (like money), and needs to be defined by the implementing class.&lt;br /&gt;&lt;br /&gt;What?  You thought I was gonna implement the class myself and do all the work for you?  Why don't you fuck yourself in the ear.  Then, when you're done with that, go fuck yourself in the other ear.  Then, come back and ask nicely, cause I'm not your fuckin jump-to-it kid.&lt;br /&gt;&lt;br /&gt;Oh, all right.  Since I'm such a nice guy, here's what a class might look like that extends my Governance trait.&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt; &lt;br /&gt;object MyGovernance extends Governance {&lt;br /&gt;  &lt;br /&gt;  type Lobbyist = { def bribe(f: Favor): Bribe }&lt;br /&gt;  type Favor = String&lt;br /&gt;  case class Bribe(favor: Favor, amount: BigDecimal)&lt;br /&gt;  case class Promise(bribe: Bribe)&lt;br /&gt;  case class ShitIWant(amount: BigDecimal)&lt;br /&gt;  &lt;br /&gt;  def solicit(favor: Favor)(lobbyist: Lobbyist) = {&lt;br /&gt;    lobbyist.bribe(favor)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def pickBest(bs: Seq[Bribe]) = {&lt;br /&gt;    bs.foldLeft(Bribe(&amp;quot;Nothing&amp;quot;,0))((a,b)=&amp;gt; if(a.amount &amp;gt;= b.amount) a else b)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def accept(bribe: Bribe) = {&lt;br /&gt;    Promise(bribe)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def collect(promise: Promise) = {&lt;br /&gt;    ShitIWant(promise.bribe.amount)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice that all those abstract types used to really be nothin more than names just floatin in space.  But I had to tie them to something to implement the class.  So, the &amp;quot;Favor&amp;quot; type is now just a type-alias for a String, so it could be something like &amp;quot;Pardon a rich man&amp;quot; or &amp;quot;Direct money to Project X&amp;quot;.  Other types, like Bribe, I defined directly.&lt;br /&gt;&lt;br /&gt;So the jagoff implementing this  class only needs to implement the component methods solicit, pickBest, accept, and collect.  The basic structure of governing is already defined by me in the govern method, and it doesn't need any improvement.  I heard some asshole talking about &amp;quot;idiomatic scala&amp;quot; and he said my code don't have it.  Well, I told him that he must be an idiomatic because he didn't get any oxygen to his brain when he was in the womb and his mother was a whore.&lt;br /&gt;&lt;br /&gt;But anyway, I can take constructive criticism.  And, I started hearin about this shit called &amp;quot;composable functions&amp;quot;.  What's that?  You just take some of these methods and plugem together to make new ones.  You don't even need to define arguments and return types and shit like that, although the compiler will make sure you don't do anything stupid.  Like, the place where I cherry-pick the best bribe and follow-through on it.  In scala, I can define something like this:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;  def cherryPick = pickBest _ andThen accept andThen collect&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Lookit that.  Now I got a new method that combines all those other methods together, but I can treat it like a single thing.  Also, I can plug in the pieces of this thing in other ways to into other methods and treat them like lego building blocks.  I love legos.  Then, my govern method becomes more compact.&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;  def govern(lobbyists: List[Lobbyist], power: Seq[Favor]) = {&lt;br /&gt;    for (favor &amp;lt;- power) yield&lt;br /&gt;     cherryPick(lobbyists.map(solicit(favor)))&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you were payin attention, you might be thinking that I could've saved a lot of trouble in defining all of those methods to plug together if I just would've defined the combined function from the start to implement at once:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;  def cherryPick(bribes: Seq[Bribe]): ShitIWant&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then, you can implement it all at once and skip those pesky pickBest, accept, and collect methods:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;  def cherryPick(bribes: Seq[Bribe]): ShitIWant = {&lt;br /&gt;    val amt = bribes&lt;br /&gt;      .foldLeft(Bribe(&amp;quot;Nothing&amp;quot;,0))((a,b)=&amp;gt; if(a.amount &amp;gt;= b.amount) a else b)&lt;br /&gt;      .amount&lt;br /&gt;    ShitIWant(amt)&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Whoah... slow down there, brother.  I could have also just stubbed out the &amp;quot;govern&amp;quot; method and made you implement the whole fuckin thing.  But, I'm tryin to supply a structure for you to base you implementation on.  If you want to learn how to govern you better shuddup and pay attention.  Not just the structure of the code I'm givin you is important, but also the semantics of the code.  I took painstaking effort to name the types and variables so that you can understand the subtle meanings of all the players in this dance.&lt;br /&gt;&lt;br /&gt;As a side note, the type names can (and should) be changed to reflect new meanings and realities.  They are a communication tools just like code comments.  But, also like comments, they can lie to you if you're lazy and let your code drift.  For example, I recently found out that Lobbyists are not the only entity from which I can extract bribes.  So, I should have refactored my code to include some super or genric type that includes Congressmen.  So, if type/method/variable names are like comments and can lie to you.  Maybe we should all just be using one-character variable names to at least limit the damage they can do.  Then, the structure of the code pops out at you, unhindered by the story told by the names.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.nabble.com/Re%3A--scala--creating-new-ClassDefs-in-compiler-plugins--p23199126.html"&gt;This guy&lt;/a&gt; obviously has mental problems:&lt;br /&gt;&lt;blockquote&gt;After you have spent a certain amount of time in the compiler, you will&lt;br /&gt;come to feel angry resentment at every comment you encounter, because it&lt;br /&gt;might be trying to mislead you! I have modified my editor not to show me&lt;br /&gt;any comments in scala sources so they cannot tempt me with their siren&lt;br /&gt;songs of reasons and explanations.  AH THE LIMITLESS SERENITY&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://michaelfeathers.typepad.com/"&gt;Michael Feathers&lt;/a&gt; is all over this topic today on Tweeter.  See if you can &lt;a href="http://search.twitter.com/search?q=&amp;ands=&amp;phrase=&amp;ors=&amp;nots=&amp;tag=&amp;lang=all&amp;from=mfeathers&amp;to=&amp;ref=&amp;near=&amp;within=15&amp;units=mi&amp;since=2009-07-27&amp;until=2009-07-27&amp;rpp=50"&gt;pick out the posts that matter&lt;/a&gt; from all of the other crap on there.  I swear, people join Twatter because they think other people like the smell of their farts, then they stay because they start to like the fart-smell themselves.  Fuggidaboutit.&lt;br /&gt;&lt;br /&gt;The trade-off between names and structure appears to be constrained by ease-of-comprehension on one end and the need for reuse/composability on the other.  Feathers considers that there are certain classes of code that are better understood in terms of their structure, effectively bridging the comprehension/composability divide.&lt;br /&gt;&lt;br /&gt;Ha!  He'll never get anything done if he keeps jackin around thinkin useless thoughts like that.  Meanwhile, I just automated the entire process of executive governing.  I'm ready for my next challenge to help the world... I think I'll make a web-framework in Java.  That'll be fuckin Golden!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-6928908764369773583?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/6928908764369773583/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=6928908764369773583' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/6928908764369773583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/6928908764369773583'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/07/fuggin-programming.html' title='Fuggin Programming'/><author><name>Rod Blagojevich</name><uri>http://www.blogger.com/profile/03827272700567262461</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://2.bp.blogspot.com/_JvLtUi5aDZc/Sm_CqBk4V3I/AAAAAAAAAAM/lMUAWZGhJ6w/S220/blago.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_JvLtUi5aDZc/SnBxZsvZZQI/AAAAAAAAAA4/93n5d8VhuSs/s72-c/pg13.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-571375645142685437</id><published>2009-07-17T16:36:00.001-07:00</published><updated>2009-07-28T20:38:05.830-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='emoticon'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Stupid Emoticon Tricks</title><content type='html'>Just for giggles, I decided to see if could get emoticons to compile in Scala.  Randomly picking from the Wikipedia page for &lt;a href="http://en.wikipedia.org/wiki/Emoticon#Common_eastern_examples"&gt;Eastern-style emoticons&lt;/a&gt;, I find I can compile the following code:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package blevins.emoticon&lt;br /&gt;&lt;br /&gt;object App extends Application {&lt;br /&gt;  import Emoticon._&lt;br /&gt;  &lt;br /&gt;  val emoticons: List[Emoticon] =&lt;br /&gt;    List( &lt;br /&gt;      ( ^ _ ^ ) ,&lt;br /&gt;      ( ^ o ^ ) ,&lt;br /&gt;      d ( ^ _ ^ ) b ,&lt;br /&gt;      ( T _ T ) ,&lt;br /&gt;      ( Z . Z )&lt;br /&gt;    )&lt;br /&gt; &lt;br /&gt;  for ( f &amp;lt;- emoticons ) { f.print }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It outputs the following:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;(^_^)&lt;br /&gt;(^o^)&lt;br /&gt;d(^_^)b&lt;br /&gt;(T_T)&lt;br /&gt;(Z.Z)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The contents of the Emoticon object is left as an exercise for the reader.  Note that I was unable to do the (-.-)Zzz emoticon, but maybe that is just because I didn't try hard enough.&lt;br /&gt;&lt;br /&gt;If this doesn't convince you to return to Java, nothing will...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-571375645142685437?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/571375645142685437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=571375645142685437' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/571375645142685437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/571375645142685437'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/07/stupid-emoticon-tricks.html' title='Stupid Emoticon Tricks'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-9176019871943392683</id><published>2009-04-01T14:26:00.000-07:00</published><updated>2009-04-01T16:56:40.868-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='parser'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Shunting Yard Algorithm</title><content type='html'>So, the next JUG meeting is introducing the concept of a &lt;a href="http://codekata.pragprog.com/"&gt;code kata&lt;/a&gt;.  One suggestion for an example topic was the &lt;a href="http://en.wikipedia.org/wiki/Shunting_yard_algorithm"&gt;Shunting Yard Algorithm&lt;/a&gt;.  I remember using an HP 42S RPN calculator all through school, and well into my professional life.  So, I thought I'd give it a go.&lt;br /&gt;&lt;br /&gt;Looking at the Wikipedia entry, they outline an algorithm in pseudo-english-code that can be implemented fairly easily in scala like this:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.kata.shuntingyard&lt;br /&gt;&lt;br /&gt;import scala.util.parsing.combinator._&lt;br /&gt;import scala.util.matching.Regex&lt;br /&gt;import scala.util.parsing.input.CharSequenceReader &lt;br /&gt;import scala.collection.mutable.Stack&lt;br /&gt;import scala.collection.mutable.Queue&lt;br /&gt;&lt;br /&gt;object ShuntingYardWikipediaParser extends RegexParsers {&lt;br /&gt;  &lt;br /&gt;  // the actual algorithm&lt;br /&gt;  def rpn(s: String) = {&lt;br /&gt;    val stack = new Stack[String]&lt;br /&gt;    val queue = new Queue[String]&lt;br /&gt;    &lt;br /&gt;    for (t: String &amp;lt;- parseAll(tokens, new CharSequenceReader(s)).get) {&lt;br /&gt;      &lt;br /&gt;      if (t isNumber) { queue += t }&lt;br /&gt;      if (t isOperator) { &lt;br /&gt;        while ((!(stack isEmpty) &amp;amp;&amp;amp; (stack.top isOperator)) &amp;amp;&amp;amp; (&lt;br /&gt;               ((t isLeftAssociative) &amp;amp;&amp;amp; (t isLowerOrEqualPrecedenceThan stack.top)) ||&lt;br /&gt;               ((t isRightAssociative) &amp;amp;&amp;amp; (t isLowerPrecedenceThan stack.top)))) {&lt;br /&gt;          queue += stack.pop&lt;br /&gt;        }&lt;br /&gt;        stack push t&lt;br /&gt;      }&lt;br /&gt;      if (t isLeftParenthesis) ( stack push t )&lt;br /&gt;      if (t isRightParenthesis) {&lt;br /&gt;        while (!(stack.top isLeftParenthesis)) { queue += stack.pop }&lt;br /&gt;        stack.pop&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;    while (!(stack isEmpty)) {&lt;br /&gt;      if (stack.top isLeftParenthesis) { error(&amp;quot;mismatched parens&amp;quot;) }&lt;br /&gt;      queue += stack.pop&lt;br /&gt;    }&lt;br /&gt;    queue.mkString(&amp;quot; &amp;quot;)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  // definitions&lt;br /&gt;  val number = &amp;quot;&amp;quot;&amp;quot;(\d+(\.\d+)?)&amp;quot;&amp;quot;&amp;quot;.r&lt;br /&gt;  val product = &amp;quot;&amp;quot;&amp;quot;[\*\/]&amp;quot;&amp;quot;&amp;quot;.r&lt;br /&gt;  val term = &amp;quot;&amp;quot;&amp;quot;[\+\-]&amp;quot;&amp;quot;&amp;quot;.r&lt;br /&gt;  val exponent = &amp;quot;&amp;quot;&amp;quot;\^&amp;quot;&amp;quot;&amp;quot;.r&lt;br /&gt;  val negation = &amp;quot;&amp;quot;&amp;quot;\!&amp;quot;&amp;quot;&amp;quot;.r&lt;br /&gt;  val leftParens = &amp;quot;&amp;quot;&amp;quot;\(&amp;quot;&amp;quot;&amp;quot;.r&lt;br /&gt;  val rightParens = &amp;quot;&amp;quot;&amp;quot;\)&amp;quot;&amp;quot;&amp;quot;.r&lt;br /&gt;  val parens = leftParens | rightParens&lt;br /&gt;  val token = number | product | term | exponent | negation | parens ^^ { case s: String =&amp;gt; s }&lt;br /&gt;  val tokens = token*&lt;br /&gt;  &lt;br /&gt;  // tricky implicit conversions to make the syntax prettier&lt;br /&gt;  implicit def stringToSmartToken(s: String): SmartToken = { SmartToken(s) }&lt;br /&gt;  case class SmartToken(s: String) {&lt;br /&gt;    implicit def regexMatches(r: Regex): Boolean = { s.matches(r.toString) } &lt;br /&gt;    def isNumber: Boolean = number&lt;br /&gt;    def isOperator = product || term || exponent || negation&lt;br /&gt;    def isLeftAssociative = isOperator &amp;amp;&amp;amp; ( product || term || negation )&lt;br /&gt;    def isRightAssociative = isOperator &amp;amp;&amp;amp; exponent&lt;br /&gt;    def isLeftParenthesis: Boolean = leftParens&lt;br /&gt;    def isRightParenthesis: Boolean = rightParens&lt;br /&gt;    def precedence = {&lt;br /&gt;      if (term) 1&lt;br /&gt;      else if (product) 2&lt;br /&gt;      else if (exponent) 3&lt;br /&gt;      else if (negation) 4&lt;br /&gt;      else error(&amp;quot;Not an operator&amp;quot;)&lt;br /&gt;    }&lt;br /&gt;    def isLowerPrecedenceThan(o: String) = {&lt;br /&gt;      (s precedence) &amp;lt; (o precedence)&lt;br /&gt;    }&lt;br /&gt;    def isLowerOrEqualPrecedenceThan(o: String) = {&lt;br /&gt;      (s precedence) &amp;lt;= (o precedence)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that I ignored the possibility of a function as described in the Wikipedia entry, but added the concept of a unary operator (negation, which I represent as a prefixed "!").&lt;br /&gt;&lt;br /&gt;The interesting part of this starts at line 41, which has (through line 47) a bunch of regex definitions of the tokens to be read.  Scala can convert a string to a regex using the ".r" method.&lt;br /&gt;&lt;br /&gt;Lines 48 - 50 take the regular expressions and combine them into &lt;a href="http://szeiger.de/blog/2008/07/27/formal-language-processing-in-scala-part-1/"&gt;parsers combinators&lt;/a&gt;, which produce string tokens.&lt;br /&gt;&lt;br /&gt;To make the string tokens syntactically pleasing, we implicitly convert them into a "SmartToken" (lines 53 - 75) which has methods relevant to this particular algorithm.  Another interesting thing is line 55, which auto-magically converts a regex (defined in an outer scope) to be treated like a boolean value of that regex applied to the SmartToken's wrapped string.  Yee-haw!  A few more refactoring passes and it will look like Ruby while still allowing you to argue with the compiler over types.&lt;br /&gt;&lt;br /&gt;But, I'll be honest.  If I didn't find the Wikipedia description of the algorithm, I probably wouldn't have implemented it in the same way.  Also, if I'm going to take the trouble to parse a language, I might as well build an abstract syntax tree.&lt;br /&gt;&lt;br /&gt;Here is my elaborate AST model:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.kata.shuntingyard&lt;br /&gt;&lt;br /&gt;import scala.util.parsing.combinator._&lt;br /&gt;&lt;br /&gt;abstract class Expression {&lt;br /&gt;  def rpn: List[String]&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;case class NumberExpr(n: String) extends Expression {&lt;br /&gt;  def rpn = List(n)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;abstract class Operator extends Expression&lt;br /&gt;case class UnaryOp(op: String, e: Expression) extends Operator {&lt;br /&gt;  def rpn = e.rpn ::: List(op)&lt;br /&gt;}&lt;br /&gt;case class BinaryOp(op: String, l: Expression, r: Expression) extends Operator {&lt;br /&gt;  def rpn = l.rpn ::: r.rpn ::: List(op)&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And, I can parse it with this object:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.kata.shuntingyard&lt;br /&gt;&lt;br /&gt;import scala.util.parsing.combinator._&lt;br /&gt;import scala.util.parsing.input.CharSequenceReader&lt;br /&gt;&lt;br /&gt;object ShuntingYardParser extends RegexParsers {&lt;br /&gt;   &lt;br /&gt;  def expression(s: String) = parseAll(expr, new CharSequenceReader(s))&lt;br /&gt;  def rpn(e: Expression) = e.rpn.mkString(&amp;quot; &amp;quot;)&lt;br /&gt;  def rpn(s: String) = {&lt;br /&gt;    val e = expression(s)&lt;br /&gt;    if (e.successful) {&lt;br /&gt;      e.get.rpn.mkString(&amp;quot; &amp;quot;)&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;      error(&amp;quot;Could not parse: &amp;quot; + s)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  // parser definitions&lt;br /&gt;  def expr: Parser[Expression] = term &lt;br /&gt;  def num = &amp;quot;&amp;quot;&amp;quot;\d+(\.\d+)?&amp;quot;&amp;quot;&amp;quot;.r | failure(&amp;quot;Some number expected&amp;quot;)&lt;br /&gt;  def number = num ^^ { case s =&amp;gt; NumberExpr(s) }&lt;br /&gt;  def group = &amp;quot;(&amp;quot; ~&amp;gt; expr &amp;lt;~ &amp;quot;)&amp;quot; ^^ { case e =&amp;gt; e }&lt;br /&gt;  def singular: Parser[Expression] = number | group | unaryOp | failure(&amp;quot;Some expression expected&amp;quot;)&lt;br /&gt;  def unaryOp = &amp;quot;!&amp;quot; ~ singular ^^ { case s ~ e =&amp;gt; UnaryOp(s, e) }&lt;br /&gt;  def exponent = rightChain(singular, &amp;quot;^&amp;quot;)&lt;br /&gt;  def product = leftChain(exponent, &amp;quot;*&amp;quot;|&amp;quot;/&amp;quot;)&lt;br /&gt;  def term = leftChain(product, &amp;quot;+&amp;quot;|&amp;quot;-&amp;quot;)&lt;br /&gt;  &lt;br /&gt;  // I think this is redundant, but couldn't figure out the chainx1(...) methods in scala's Parser class&lt;br /&gt;  def rightChain(p: Parser[Expression], x: Parser[String]) = {&lt;br /&gt;    ((p ~ x)*) ~ p ^^ {&lt;br /&gt;      case Nil ~ tail =&amp;gt; tail&lt;br /&gt;      case rest ~ tail =&amp;gt; rest.foldRight(tail) {&lt;br /&gt;        case (p ~ s, z) =&amp;gt; BinaryOp(s, p, z)&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  def leftChain(p: Parser[Expression], x: Parser[String]) = {&lt;br /&gt;    p ~ ((x ~ p)*) ^^ {&lt;br /&gt;      case head ~ Nil =&amp;gt; head&lt;br /&gt;      case head ~ rest =&amp;gt; rest.foldLeft(head) {&lt;br /&gt;        case (z, s ~ p) =&amp;gt; BinaryOp(s, z, p)&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This code really does all the parsing definitions in lines 21 - 29.  We produce an AST that can be output in RPN form.&lt;br /&gt;&lt;br /&gt;The really tricky part (for me) about this code was defining it is such a way that we didn't get any recursive parsers as the first (leftmost) term of a sequential combination.  This will lead to immediate stack-overflow purgatory as the parser infinitely recurses.  Surprisingly, the compiler/type-checker allows it, and I've heard that it might be supported in a future implementation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Well, do they work?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I guess we should actually test these implementations to see if they do what they are supposed to.  Probably better even still to have defined some tests up front to allow the algorithm to be developed under that guidance.  Scala has a wonderful testing facility called &lt;a href="http://code.google.com/p/specs/"&gt;specs&lt;/a&gt; that allows you to specify test in a very intuitive way.  Drop a library in my path and make some specifications&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.kata.shuntingyard&lt;br /&gt;&lt;br /&gt;import org.specs._&lt;br /&gt;import ShuntingYardParser._&lt;br /&gt;&lt;br /&gt;object ShuntingYardTest extends Specification {&lt;br /&gt;  &lt;br /&gt;  def passStdTests(parser: { def rpn(s: String): String }) = {&lt;br /&gt;    &amp;quot;be able to add and subtract&amp;quot; in {&lt;br /&gt;      parser.rpn(&amp;quot;3+4-2&amp;quot;) must beEqual(&amp;quot;3 4 + 2 -&amp;quot;)&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &amp;quot;do unary negation correctly&amp;quot; in {&lt;br /&gt;      parser.rpn(&amp;quot;! 3 + 2&amp;quot;) must beEqual(&amp;quot;3 ! 2 +&amp;quot;)&lt;br /&gt;      parser.rpn(&amp;quot;!(3 + 2)^2&amp;quot;) must beEqual(&amp;quot;3 2 + ! 2 ^&amp;quot;)&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &amp;quot;parse Wikipedia example correctly&amp;quot; in {&lt;br /&gt;      val input = &amp;quot;3 + 4 * 2 / (1-5) ^2 ^3&amp;quot;&lt;br /&gt;      val result = parser.rpn(input)&lt;br /&gt;      result must beEqual(&amp;quot;3 4 2 * 1 5 - 2 3 ^ ^ / +&amp;quot;)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &amp;quot;ShuntingYardParser&amp;quot; should { &lt;br /&gt;    passStdTests(ShuntingYardParser)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  &amp;quot;ShuntingYardParser&amp;quot; can { &lt;br /&gt;    &amp;quot;blow the stack&amp;quot; in {&lt;br /&gt;      val sb = new StringBuffer&lt;br /&gt;      val max = 1000&lt;br /&gt;      for(i &amp;lt;- 1 to max) { sb append &amp;quot;(&amp;quot; }&lt;br /&gt;      sb append &amp;quot;(4-3)&amp;quot;&lt;br /&gt;      for(i &amp;lt;- 1 to max) { sb append &amp;quot;*(4-3))&amp;quot; }&lt;br /&gt;      ShuntingYardParser.rpn(sb.toString) must throwA(new StackOverflowError)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;    &lt;br /&gt;  &amp;quot;ShuntingYardWikipediaParser&amp;quot; should {&lt;br /&gt;    passStdTests(ShuntingYardWikipediaParser)&lt;br /&gt;    &lt;br /&gt;    &amp;quot;not blow the stack&amp;quot; in {&lt;br /&gt;      val sb = new StringBuffer&lt;br /&gt;      val max = 1000&lt;br /&gt;      for(i &amp;lt;- 1 to max) { sb append &amp;quot;(&amp;quot; }&lt;br /&gt;      sb append &amp;quot;(4-3)&amp;quot;&lt;br /&gt;      for(i &amp;lt;- 1 to max) { sb append &amp;quot;*(4-3))&amp;quot; }&lt;br /&gt;      ShuntingYardWikipediaParser.rpn(sb.toString) mustNot throwAn(new Exception)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This spec produces an executable class that produces this output:&lt;br /&gt;&lt;pre name="code"&gt;&lt;br /&gt;Specification &amp;quot;ShuntingYardTest&amp;quot;&lt;br /&gt;  ShuntingYardParser should&lt;br /&gt;  + be able to add and subtract&lt;br /&gt;  + do unary negation correctly&lt;br /&gt;  + parse Wikipedia example correctly&lt;br /&gt;&lt;br /&gt;  Total for SUT &amp;quot;ShuntingYardParser&amp;quot;:&lt;br /&gt;  Finished in 0 second, 0 ms&lt;br /&gt;  3 examples, 4 expectations, 0 failure, 0 error&lt;br /&gt;&lt;br /&gt;  ShuntingYardParser can&lt;br /&gt;  + blow the stack&lt;br /&gt;&lt;br /&gt;  Total for SUT &amp;quot;ShuntingYardParser&amp;quot;:&lt;br /&gt;  Finished in 0 second, 0 ms&lt;br /&gt;  1 example, 1 expectation, 0 failure, 0 error&lt;br /&gt;&lt;br /&gt;  ShuntingYardWikipediaParser should&lt;br /&gt;  + be able to add and subtract&lt;br /&gt;  + do unary negation correctly&lt;br /&gt;  + parse Wikipedia example correctly&lt;br /&gt;  + not blow the stack&lt;br /&gt;&lt;br /&gt;  Total for SUT &amp;quot;ShuntingYardWikipediaParser&amp;quot;:&lt;br /&gt;  Finished in 0 second, 0 ms&lt;br /&gt;  4 examples, 5 expectations, 0 failure, 0 error&lt;br /&gt;&lt;br /&gt;Total for specification &amp;quot;ShuntingYardTest&amp;quot;:&lt;br /&gt;Finished in 0 second, 563 ms&lt;br /&gt;8 examples, 10 expectations, 0 failure, 0 error&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice that I'm testing both implementations of the parser with the same code, except for one test (blow the stack).  This is because the AST version will blow up when it encounters some input that nests thousands of levels deep.  I verify this and also verify that is doesn't affect the Wikipedia version.  I'm am deeply embarrassed that a Wikipedia algorithm is more feature-full than my home-grown version.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What next?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Well, we could actually calculate the results of the input from either the AST or the rpn input.  Both of these would be almost trivial to implement.  We could randomly generate input strings, feed them into both parsers and compare the results.  It is nice to have Scala's parser combinators as a tool in your belt.  There is a dead zone between what can/should be done with one-off regular expressions, and generating a full-fledged language with an external tool (JavaCC, ANTLR, etc).  Another option for these situations is to use an internal DSL (like the specs library I used).  But, that's a topic for another post...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-9176019871943392683?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/9176019871943392683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=9176019871943392683' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/9176019871943392683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/9176019871943392683'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/04/shunting-yard-algorithm.html' title='Shunting Yard Algorithm'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-7686855860176725328</id><published>2009-03-15T18:43:00.000-07:00</published><updated>2010-04-06T10:32:03.902-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Disjoint Bounded Views - Redux</title><content type='html'>I cleaned up my &lt;a href="http://cleverlytitled.blogspot.com/2009/03/so-i-read-both-jim-mcbeath-and-michids.html"&gt;previous post&lt;/a&gt; on "stuttering-or".  The import would now look like this:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.imports&lt;br /&gt;&lt;br /&gt;class DisjointBoundedView[A,B](val a: Option[A], val b: Option[B])&lt;br /&gt;&lt;br /&gt;object DisjointBoundedView {&lt;br /&gt;  // namespace pollution?  Maybe use &amp;quot;||&amp;quot; or &amp;quot;OrType&amp;quot;&lt;br /&gt;  type or[A,B] = DisjointBoundedView[A,B]&lt;br /&gt;  &lt;br /&gt;  // convenience of definition functions&lt;br /&gt;  private def da[A,B](a: A): or[A,B] = { new DisjointBoundedView(Some(a),None) }&lt;br /&gt;  private def db[A,B](b: B): or[A,B] = { new DisjointBoundedView(None,Some(b)) }&lt;br /&gt;  private def na[A,B](n: Nothing): or[A,B] = { new DisjointBoundedView(None, None) }&lt;br /&gt;  &lt;br /&gt;  // implicit defs - stuttering-or&lt;br /&gt;  implicit def noneToOr2[A,B](n: Nothing): or[A,B] =&lt;br /&gt;    { na(n) }&lt;br /&gt;  implicit def aToOr2[A,B](a: A): or[A,B] =&lt;br /&gt;    { da(a) }&lt;br /&gt;  implicit def bToOr2[A,B](b: B): or[A,B] =&lt;br /&gt;    { db(b) }&lt;br /&gt;  implicit def aToOr3[A,B,C](a: A): or[or[A,B],C] =&lt;br /&gt;    { da(da(a)) }&lt;br /&gt;  implicit def bToOr3[A,B,C](b: B): or[or[A,B],C] =&lt;br /&gt;    { da(db(b)) }&lt;br /&gt;  implicit def aToOr4[A,B,C,D](a: A): or[or[or[A,B],C],D] =&lt;br /&gt;    { da(da(da(a))) }&lt;br /&gt;  implicit def bToOr4[A,B,C,D](b: B): or[or[or[A,B],C],D] =&lt;br /&gt;    { da(da(db(b))) }&lt;br /&gt;  implicit def aToOr5[A,B,C,D,E](a: A): or[or[or[or[A,B],C],D],E] =&lt;br /&gt;    { da(da(da(da(a)))) }&lt;br /&gt;  implicit def bToOr5[A,B,C,D,E](b: B): or[or[or[or[A,B],C],D],E] =&lt;br /&gt;    { da(da(da(db(b)))) }&lt;br /&gt;  // more? ...&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Calling code would look like this:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.test&lt;br /&gt;&lt;br /&gt;import org.okcjug.imports.DisjointBoundedView._&lt;br /&gt;&lt;br /&gt;class Foo {&lt;br /&gt;&lt;br /&gt;  def bar[T &amp;lt;% Int or String or Double](t: Option[T]) = {&lt;br /&gt;    t match {&lt;br /&gt;      case Some(x: Int) =&amp;gt; println(&amp;quot;processing Int: &amp;quot; + x)&lt;br /&gt;      case Some(x: String) =&amp;gt; println(&amp;quot;processing String: &amp;quot; + x)&lt;br /&gt;      case Some(x: Double) =&amp;gt; println(&amp;quot;processing Double: &amp;quot; + x)&lt;br /&gt;      case None =&amp;gt; println(&amp;quot;empty and I don't care the type&amp;quot;)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def baz[T &amp;lt;% String or Int](t: List[T]) = {&lt;br /&gt;    for (x &amp;lt;- t) x match {&lt;br /&gt;      case x: String =&amp;gt; println(&amp;quot;String list item: &amp;quot; + x)&lt;br /&gt;      case x: Int =&amp;gt; println(&amp;quot;Int list item: &amp;quot; + x)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;object Foo extends Application {&lt;br /&gt;  &lt;br /&gt;  val f = new Foo&lt;br /&gt;  &lt;br /&gt;  f.bar(None)&lt;br /&gt;  f.bar(Some(1))&lt;br /&gt;  f.bar(Some(&amp;quot;blah&amp;quot;))&lt;br /&gt;  f.bar(Some(3.45))&lt;br /&gt;  // f.bar(Some(Some(2))) // compiler error&lt;br /&gt;  // f.bar(Some(Set(&amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;))) // compiler error&lt;br /&gt;  &lt;br /&gt;  f.baz(List(1,1,2,3,5,8,13))&lt;br /&gt;  f.baz(List(&amp;quot;boogie&amp;quot;, &amp;quot;woogie&amp;quot;))&lt;br /&gt;  // f.baz(List(3.4, 3.14)) // compiler error&lt;br /&gt;  // f.baz(List(1,&amp;quot;one&amp;quot;)) // compiler error&lt;br /&gt;  // f.baz(Some(1)) // compiler error&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The only difference is that we now don't require clarifying the type for a &lt;code&gt;None&lt;/code&gt;, and the class name more accurately reflects what it does.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;UPDATE:&lt;/span&gt; Per Ittay's suggestion below, I've updated the implementation to use Either as the backing class (shown below).  This simplifies the code and allows extraction of values from the composite type via pattern matching.  Also, it can no longer accurately be described as "stuttering-or".&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.imports&lt;br /&gt;&lt;br /&gt;object DisjointBoundedView { &lt;br /&gt;  // namespace pollution?  Maybe use &amp;quot;||&amp;quot; or &amp;quot;OrType&amp;quot;  &lt;br /&gt;  type or[A,B] = Either[A,B]  &lt;br /&gt;    &lt;br /&gt;  // implicit defs &lt;br /&gt;  implicit def l[T](t: T) = Left(t)&lt;br /&gt;  implicit def r[T](t: T) = Right(t)&lt;br /&gt;  implicit def ll[T](t: T) = Left(Left(t))&lt;br /&gt;  implicit def lr[T](t: T) = Left(Right(t))&lt;br /&gt;  implicit def lll[T](t: T) = Left(Left(Left(t)))  &lt;br /&gt;  implicit def llr[T](t: T) = Left(Left(Right(t))) &lt;br /&gt;  implicit def llll[T](t: T) = Left(Left(Left(Left(t))))  &lt;br /&gt;  implicit def lllr[T](t: T) = Left(Left(Left(Right(t))))  &lt;br /&gt;  // more? ...  &lt;br /&gt;    &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-7686855860176725328?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/7686855860176725328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=7686855860176725328' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/7686855860176725328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/7686855860176725328'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/03/disjoint-bounded-views-redux.html' title='Disjoint Bounded Views - Redux'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-8399880048943733673</id><published>2009-03-11T10:21:00.000-07:00</published><updated>2009-04-01T16:57:09.322-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jug'/><title type='text'>OKCJUG Slides</title><content type='html'>Although they may not make much sense without the code and explanation that goes along with them, I've &lt;a href="http://sites.google.com/site/okcjugfiles/Home/okcjug-20090310.pdf"&gt;posted&lt;/a&gt; the slides used in my JUG presentation yesterday.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-8399880048943733673?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/8399880048943733673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=8399880048943733673' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/8399880048943733673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/8399880048943733673'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/03/okcjug-slides.html' title='OKCJUG Slides'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-8732712325898627700</id><published>2009-03-09T14:27:00.000-07:00</published><updated>2009-03-09T18:24:52.628-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='implicit'/><category scheme='http://www.blogger.com/atom/ns#' term='erasure'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Stuttering Or</title><content type='html'>So I read both &lt;a href="http://jim-mcbeath.blogspot.com/2008/10/polymorphism-using-implicit-conversions.html"&gt;Jim McBeath&lt;/a&gt; and &lt;a href="http://michid.wordpress.com/2008/02/08/implicit-double-dispatch-revisited/"&gt;Michid's&lt;/a&gt; blog entries on implementing polymorphism using implicit conversions, especially where it would be otherwise difficult because of type erasure.  But, I was uneasy with their approaches.  Jim's required implementing redundant classes in a heirarchy and Michid's seemed comlex.  Both required that you explicity implement an implicit function for each disjoint type you want one of your method's parameters to be called as.  And, even worse, the calling code has to remember to import the implicit functions for this to work.&lt;br /&gt;&lt;br /&gt;I call my attempt at a better version the "stuttering-or" method, and it looks like this:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.typeerasure.arrrgh.util&lt;br /&gt;&lt;br /&gt;case class DisjointType[A,B](val a: Option[A], val b: Option[B])&lt;br /&gt;&lt;br /&gt;object DisjointType {&lt;br /&gt;  type or[A,B] = DisjointType[A,B] // who wants to type &amp;quot;DisjointType&amp;quot; all the time?&lt;br /&gt;  &lt;br /&gt;  // convenience of definition functions&lt;br /&gt;  private def da[A,B](a: A): or[A,B] = { DisjointType(Some(a),None) }&lt;br /&gt;  private def db[A,B](b: B): or[A,B] = { DisjointType(None,Some(b)) }&lt;br /&gt;  &lt;br /&gt;  // implicit defs - stuttering-or&lt;br /&gt;  implicit def aToDisjointType2[A,B](a: A): or[A,B] =&lt;br /&gt;    { da(a) }&lt;br /&gt;  implicit def bToDisjointType2[A,B](b: B): or[A,B] =&lt;br /&gt;    { db(b) }&lt;br /&gt;  implicit def aToDisjointType3[A,B,C](a: A): or[or[A,B],C] =&lt;br /&gt;    { da(da(a)) }&lt;br /&gt;  implicit def bToDisjointType3[A,B,C](b: B): or[or[A,B],C] =&lt;br /&gt;    { da(db(b)) }&lt;br /&gt;  implicit def aToDisjointType4[A,B,C,D](a: A): or[or[or[A,B],C],D] =&lt;br /&gt;    { da(da(da(a))) }&lt;br /&gt;  implicit def bToDisjointType4[A,B,C,D](b: B): or[or[or[A,B],C],D] =&lt;br /&gt;    { da(da(db(b))) }&lt;br /&gt;  implicit def aToDisjointType5[A,B,C,D,E](a: A): or[or[or[or[A,B],C],D],E] =&lt;br /&gt;    { da(da(da(da(a)))) }&lt;br /&gt;  implicit def bToDisjointType5[A,B,C,D,E](b: B): or[or[or[or[A,B],C],D],E] =&lt;br /&gt;    { da(da(da(db(b)))) }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The "magic" part of this is that it allows infix type notation to represent "Type1 or Type2" as "DisjointType[Type1,Type2]".  Then, the implicit defs allow the component types to be represented in a type view.  This guards the methods that define it to only accept members of the component types.  Note that it is up to the method implementer to cover all the possible cases as the type system will not help you there.&lt;br /&gt;&lt;br /&gt;Defining the methods is something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.typeerasure.arrrgh.work&lt;br /&gt;&lt;br /&gt;import org.okcjug.typeerasure.arrrgh.util.DisjointType._&lt;br /&gt;&lt;br /&gt;class Foo {&lt;br /&gt;&lt;br /&gt;  def erasureMethod[T &amp;lt;% Int or String or Double](t: Option[T]) = {&lt;br /&gt;    t match {&lt;br /&gt;      case Some(x: Int) =&amp;gt; println(&amp;quot;processing Int: &amp;quot; + x)&lt;br /&gt;      case Some(x: String) =&amp;gt; println(&amp;quot;processing String: &amp;quot; + x)&lt;br /&gt;      case Some(x: Double) =&amp;gt; println(&amp;quot;processing Double: &amp;quot; + x)&lt;br /&gt;      case None =&amp;gt; println(&amp;quot;empty and I don't care the type&amp;quot;)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def erasureMethod2[T &amp;lt;% String or Int](lt: List[T]) = {&lt;br /&gt;    for (x &amp;lt;- lt) x match {&lt;br /&gt;      case x: String =&amp;gt; println(&amp;quot;String list item: &amp;quot; + x)&lt;br /&gt;      case x: Int =&amp;gt; println(&amp;quot;Int list item: &amp;quot; + x)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And, the calling code looks like this:&lt;br /&gt;&lt;pre name="code" class="Scala"&gt;&lt;br /&gt;package org.okcjug.typeerasure.arrrgh&lt;br /&gt;&lt;br /&gt;import org.okcjug.typeerasure.arrrgh.work.Foo&lt;br /&gt;import org.okcjug.typeerasure.arrrgh.util.DisjointType._&lt;br /&gt;&lt;br /&gt;object App extends Application {&lt;br /&gt;&lt;br /&gt;  val f = new Foo()&lt;br /&gt;  &lt;br /&gt;  f.erasureMethod(Some(&amp;quot;blah&amp;quot;))&lt;br /&gt;  // f.erasureMethod(None) // compiler error&lt;br /&gt;  f.erasureMethod(None.asInstanceOf[Option[String]]) // ok&lt;br /&gt;  f.erasureMethod(Some(42))&lt;br /&gt;  // f.erasureMethod(Some(List(&amp;quot;b&amp;quot;))) compiler error&lt;br /&gt;  &lt;br /&gt;  f.erasureMethod2(List(&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;c&amp;quot;))&lt;br /&gt;  f.erasureMethod2(List(5,4,3,2))&lt;br /&gt;  // f.erasureMethod2(List(4.3)) compiler error&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So, what does this get me?  Well, implementing the code is fairly straightforward, just using a "Type1 or Type2 or Type3 ..." construct for the disjoint types (up to 5 in the given code).  Also, discerning the specific type within the polymorphic method for purposes of dispatch is done using the standard "match" keyword.&lt;br /&gt;&lt;br /&gt;What I don't like about my solution is that the calling code must import the implicit methods (here: org.okcjug.typeerasure.arrrgh.util.DisjointType._).  Each of the the compared methods from the top of this article also required importing the implicit methods.  However, I think my approach shows more promise because the implicit defs that need to be imported are not specific to the pseudo-polymorphic methods I'm implementing.  In fact, the content of this import is suitable to be included in the Predef object.&lt;br /&gt;&lt;br /&gt;Maybe I'll poke around the scala mailing list and see if any library maintainers want to oblige me...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-8732712325898627700?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/8732712325898627700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=8732712325898627700' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/8732712325898627700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/8732712325898627700'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/03/so-i-read-both-jim-mcbeath-and-michids.html' title='Stuttering Or'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-1359894698240535301</id><published>2009-03-09T14:12:00.000-07:00</published><updated>2009-03-09T16:52:36.897-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jug'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Lazy initialization of blog posts</title><content type='html'>Well, it has been a couple of years since my last post and we did &lt;span style="font-weight: bold;"&gt;not&lt;/span&gt; get the opportunity to use Scala at work.  I lost interest and started chasing other shiny, twinkly things.&lt;br /&gt;&lt;br /&gt;But, I did get a &lt;a href="http://okcjug.org/content/view/95/1/"&gt;chance to give a presentation&lt;/a&gt; on Scala at the &lt;a href="http://okcjug.org/"&gt;local JUG&lt;/a&gt;.  I'll post slides when it is done if I don't completely embarrass myself.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-1359894698240535301?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/1359894698240535301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=1359894698240535301' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/1359894698240535301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/1359894698240535301'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2009/03/lazy-initialization-of-blog-posts.html' title='Lazy initialization of blog posts'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-226995781245658674</id><published>2006-12-28T01:09:00.000-08:00</published><updated>2006-12-28T02:06:10.130-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ant'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>More Ant builds</title><content type='html'>Since the Scala compiler is a pretty heavy process to run in buildfiles where it is not needed, I've nested it within a conditional to only run when the Scala library is in the classpath.&lt;br /&gt;&lt;br /&gt;My new build macro looks like this:&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    &amp;lt;macrodef name=&amp;quot;build&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;attribute name=&amp;quot;srcdir&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;attribute name=&amp;quot;builddir&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;sequential&amp;gt;&lt;br /&gt;            &amp;lt;mkdir dir=&amp;quot;@{builddir}&amp;quot; /&amp;gt;&lt;br /&gt;            &amp;lt;javac srcdir=&amp;quot;@{srcdir}&amp;quot; &lt;br /&gt;                destdir=&amp;quot;@{builddir}&amp;quot;&lt;br /&gt;                source=&amp;quot;${compile.source}&amp;quot;&lt;br /&gt;                target=&amp;quot;${compile.target}&amp;quot;&lt;br /&gt;                deprecation=&amp;quot;${compile.deprecation}&amp;quot;&lt;br /&gt;                debug=&amp;quot;${compile.debug}&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;classpath refid=&amp;quot;classpath&amp;quot; /&amp;gt;&lt;br /&gt;            &amp;lt;/javac&amp;gt;&lt;br /&gt;            &lt;br /&gt;            &amp;lt;if&amp;gt;&lt;br /&gt;                &amp;lt;available classpathref=&amp;quot;classpath&amp;quot; classname=&amp;quot;scala.ScalaObject&amp;quot;/&amp;gt;&lt;br /&gt;                &amp;lt;then&amp;gt;&lt;br /&gt;                    &amp;lt;scalac srcdir=&amp;quot;@{srcdir}&amp;quot;&lt;br /&gt;                                    destdir=&amp;quot;@{builddir}&amp;quot;&lt;br /&gt;                                    classpathref=&amp;quot;classpath&amp;quot; /&amp;gt;   &lt;br /&gt;                &amp;lt;/then&amp;gt;   &lt;br /&gt;            &amp;lt;/if&amp;gt;   &lt;br /&gt;&lt;br /&gt;            &amp;lt;copy todir=&amp;quot;@{builddir}&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;fileset dir=&amp;quot;@{srcdir}&amp;quot;&amp;gt;&lt;br /&gt;                    &amp;lt;include name=&amp;quot;**/*&amp;quot;/&amp;gt;&lt;br /&gt;                    &amp;lt;exclude name=&amp;quot;**/*.java&amp;quot; /&amp;gt;&lt;br /&gt;                    &amp;lt;exclude name=&amp;quot;**/*.scala&amp;quot; /&amp;gt;   &lt;br /&gt;                    &amp;lt;exclude name=&amp;quot;**/.svn/*&amp;quot; /&amp;gt;&lt;br /&gt;                &amp;lt;/fileset&amp;gt;&lt;br /&gt;            &amp;lt;/copy&amp;gt;&lt;br /&gt;        &amp;lt;/sequential&amp;gt;&lt;br /&gt;    &amp;lt;/macrodef&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;We also need to define the scalac task like so:&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    &amp;lt;taskdef resource=&amp;quot;scala/tools/ant/antlib.xml&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;classpath&amp;gt;&lt;br /&gt;            &amp;lt;pathelement location=&amp;quot;ant/jars/scala-compiler.jar&amp;quot; /&amp;gt;    &lt;br /&gt;        &amp;lt;/classpath&amp;gt;&lt;br /&gt;    &amp;lt;/taskdef&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-226995781245658674?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/226995781245658674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=226995781245658674' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/226995781245658674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/226995781245658674'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2006/12/more-ant-builds.html' title='More Ant builds'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-6175278153768492848</id><published>2006-12-27T19:00:00.000-08:00</published><updated>2006-12-27T23:11:22.560-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ant'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Ant builds</title><content type='html'>We have a standardized ant build file(s) at work.  There is usually not much thinking needed other than naming the project.  If we used Scala regularly, we would need to incorporate the &amp;lt;scalac ... /&amp;gt; target into our buildfiles in such a way that it would transparently build Scala code if it existed.  It is also important that the build succeed in one pass with no manual intervention for the &lt;a href="https://hudson.dev.java.net/"&gt;CI server&lt;/a&gt; to perform its automated builds.&lt;br /&gt;&lt;br /&gt;How can we structure our code and build files to satisfy this requirement?  Scala code and freely call Java code (and vice-versa).  In our build files we need to call both javac and scalac in some particular order.  If we call javac first, then code like following will fail because the java compiler cannot yet see the scala class when it executes.&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;--- Foo.java ---&lt;br /&gt;public class Foo {&lt;br /&gt; private Bar bar;&lt;br /&gt; // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;--- Bar.scala ---&lt;br /&gt;class Bar {&lt;br /&gt; // ...&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;Of course, you have the reverse situation if you call scalac first, with same-project Java code invisible to the Scala compiler.  A post to the Scala mailing list brought the following &lt;a href="http://www.nabble.com/Re%3A-Mixed-language-project-builds-p8017752.html"&gt;suggestion&lt;/a&gt;:&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;--- Foo.java ---&lt;br /&gt;public class Foo {&lt;br /&gt;    private Bar bar;&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;--- Bar.java ---&lt;br /&gt;public interface Bar {&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;--- BarImpl.scala ---&lt;br /&gt;class BarImpl() extends Bar {&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This allows us to statically reference a Java interface from Java code and to implement the class in Scala.  Instances can be created at runtime, using the container (EJB, Spring, or JSF) or by using &lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Class.forName(&amp;quot;package.BarImpl&amp;quot;).newInstance();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Of course, we can still easily reference our Java object from Scala.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;--- Baz.scala ---&lt;br /&gt;class Baz {&lt;br /&gt;    def doSomething(foo: Foo): Unit = {&lt;br /&gt;        // do something with our Java object Foo&lt;br /&gt;    }&lt;br /&gt;    def doSomethingElse(): Unit = {&lt;br /&gt;        // instantiate our own Java-defined object&lt;br /&gt;        foo = new Foo();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;So, the plan is to require Java interfaces for any Scala objects that are referenced from Java code.  Of course, many of the advantages from Scala come from using its type system and will only show if whole layers of an application are implemented in Scala.  Luckily, most of our layers are hidden behind interfaces anyway.&lt;br /&gt;&lt;br /&gt;Next I'd like to experiment with different types of container-instantiation of Scala classes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-6175278153768492848?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/6175278153768492848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=6175278153768492848' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/6175278153768492848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/6175278153768492848'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2006/12/ant-builds.html' title='Ant builds'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-2999567496229426496</id><published>2006-12-26T00:41:00.000-08:00</published><updated>2006-12-26T01:42:01.068-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='facelets'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='netbeans'/><category scheme='http://www.blogger.com/atom/ns#' term='glassfish'/><category scheme='http://www.blogger.com/atom/ns#' term='ant'/><category scheme='http://www.blogger.com/atom/ns#' term='hudson'/><category scheme='http://www.blogger.com/atom/ns#' term='jsf'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>What next?</title><content type='html'>My goal is to identify potential problems with using Scala in my work environment.  Most apps are small-to-middling sized web applications used internally to support a sales and manufacturing company.  Relevant technologies used are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="https://glassfish.dev.java.net/"&gt;Glassfish&lt;/a&gt; for the application server&lt;/li&gt;&lt;li&gt;&lt;a href="http://java.sun.com/javaee/javaserverfaces/"&gt;JSF&lt;/a&gt;/&lt;a href="https://facelets.dev.java.net/"&gt;Facelets&lt;/a&gt; for the view layer&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt; for the IDE.  Although there is some attraction for &lt;a href="http://www.netbeans.org/"&gt;Netbeans&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Yes, we still build with &lt;a href="http://ant.apache.org/"&gt;Ant&lt;/a&gt;.  Being a mouth-breather, I can't quite wrap my head around &lt;a href="http://maven.apache.org/"&gt;Maven&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Continuous Integration.  We use &lt;a href="https://hudson.dev.java.net/"&gt;Hudson&lt;/a&gt;, but I'm more wed to the idea of CI than to any particular server.&lt;/li&gt;&lt;/ul&gt;My brainstorm list of questions to be answered:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Can I build ejb3s with Scala?&lt;/li&gt;&lt;li&gt;JSF-managed beans?&lt;/li&gt;&lt;li&gt;Spring-managed beans?&lt;br /&gt;&lt;/li&gt;&lt;li&gt;How do I structure builds with mixed Java/Scala code?&lt;/li&gt;&lt;li&gt;Can I use annotations?  Create them in Scala?&lt;/li&gt;&lt;/ul&gt;I'm sure that I'll come up more as I go along.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-2999567496229426496?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/2999567496229426496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=2999567496229426496' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/2999567496229426496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/2999567496229426496'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2006/12/what-next.html' title='What next?'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6115154198867082591.post-7163401438610513117</id><published>2006-12-25T23:43:00.000-08:00</published><updated>2006-12-26T00:33:58.061-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>What I want (for now)</title><content type='html'>I want to learn more about &lt;a href="http://scala.epfl.ch/"&gt;Scala&lt;/a&gt;.  I've already read most of the &lt;a href="http://scala.epfl.ch/docu/index.html"&gt;documentation&lt;/a&gt;.  I even did some hello-world type exercises.  But, that is about as far as I can go without trying to apply it to some real-world problems.  I don't have any extra time to make up problems to solve, which means I would have to use it in projects at work.  Doing so presents a couple of challenges:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Using a new language can be incredibly unproductive (at first) and detrimental to deadlines.  I can't afford to bite off too much.&lt;/li&gt;&lt;li&gt;We have a team of 5 developers, and being able to work with each other's code is very important.  I would be sorely ticked-off if I had to fix a bug and found myself struggling with some scripting-language-of-the-week.&lt;/li&gt;&lt;/ol&gt;I intend to use the next few weeks to explore ways to minimize the first challenge.  Since Scala compiles to Java bytecode, we should (in theory) be able to gradually incorporate Scala code into our projects where it makes sense and provides some benefits.  In practice, there are many issues relating to our environment and the libraries/frameworks/tools that we use that might cause heartburn.&lt;br /&gt;&lt;br /&gt;The second challenge is not as straight forward.  Personally, I'm interested in learning new concepts and applying them.  Scala has many features that make it &lt;a href="http://scala.epfl.ch/docu/rationale.html"&gt;attractive&lt;/a&gt; as an alternate language, especially for Java developers.  However, what is interesting to me is not necessarily interesting to other people.  Plus, I have a history of chasing interesting but impractical &lt;a href="http://www.w3.org/TR/owl-ref/"&gt;technologies&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;But, I figure that exploring the technical challenges can keep me occupied before I try to convince four other people that using Scala is a great idea.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6115154198867082591-7163401438610513117?l=cleverlytitled.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cleverlytitled.blogspot.com/feeds/7163401438610513117/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6115154198867082591&amp;postID=7163401438610513117' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/7163401438610513117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6115154198867082591/posts/default/7163401438610513117'/><link rel='alternate' type='text/html' href='http://cleverlytitled.blogspot.com/2006/12/what-i-want-for-now.html' title='What I want (for now)'/><author><name>Mitch Blevins</name><uri>http://www.blogger.com/profile/09476167560094979019</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
