<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>aaron.harnly.net &#187; geek</title>
	<atom:link href="http://harnly.net/category/blog/geek/feed/" rel="self" type="application/rss+xml" />
	<link>http://harnly.net</link>
	<description>Sì, abbiamo un'anima. Ma è fatta di tanti piccoli robot.</description>
	<pubDate>Thu, 11 Mar 2010 14:01:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<item>
		<title>Lazy vals with implicit parameters</title>
		<link>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/</link>
		<comments>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 15:04:54 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/?p=176</guid>
		<description><![CDATA[Lazy vals were an excellent addition to Scala 2.6.0. They allow you to defer calculation of a value until it is actually needed, after which the calculated value is cached. 

Unfortunately, this doesn&#8217;t play so well with another wonderful Scala feature &#8212; implicit parameters. It&#8217;s often the case that you&#8217;ll want to defer resolution of an [...]]]></description>
			<content:encoded><![CDATA[<p>Lazy vals were an excellent addition to <a href="http://www.scala-lang.org/docu/changelog.html#v2.6.0">Scala 2.6.0</a>. They allow you to defer calculation of a value until it is actually needed, after which the calculated value is cached. </p>

<p>Unfortunately, this doesn&#8217;t play so well with another wonderful Scala feature &mdash; <a href="http://www.scala-lang.org/intro/implicit.html">implicit parameters</a>. It&#8217;s often the case that you&#8217;ll want to defer resolution of an implicit until a method call, rather than in the scope of object creation. But lazy values cannot take any parameters, implicit or otherwise &mdash; so it seems you&#8217;re stuck.</p>

<p>Memoized to the rescue! This is a simple helper class that takes care of the caching of a result. Where you might have had the following method with an implicit parameter:</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">def</span> foo<span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">implicit</span> bar<span style="color: #000080;">:</span> Bar<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> ResultType <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> ... <span style="color: #F78811;">&#125;</span></pre></div></div>


<p>you instead write the following:</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">private</span> <span style="color: #0000ff; font-weight: bold;">var</span> <span style="color: #000080;">_</span>foo <span style="color: #000080;">=</span> Memoized<span style="color: #F78811;">&#91;</span>ResultType<span style="color: #F78811;">&#93;</span>
<span style="color: #0000ff; font-weight: bold;">def</span> foo<span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">implicit</span> bar<span style="color: #000080;">:</span> Bar<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #000080;">_</span>foo or <span style="color: #F78811;">&#123;</span> ... <span style="color: #F78811;">&#125;</span></pre></div></div>


<p>(complete source below the fold)
<span id="more-176"></span></p>

<p>That&#8217;s it; nothing fancy. This is not a true memoization solution for a function that takes a parameter &mdash; check out <a href="http://projects.workingmouse.com/public/scalaz/trunk/src/main/scalaz/memo/">the memo package</a> in <a href="http://wiki.workingmouse.com/index.php/Scalaz">Scalaz</a> for that. But I&#8217;ve found it handy, and you might too.</p>


<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">class</span> Memoized<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
	<span style="color: #0000ff; font-weight: bold;">private</span> <span style="color: #0000ff; font-weight: bold;">var</span> value<span style="color: #000080;">:</span> Option<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> None
	<span style="color: #0000ff; font-weight: bold;">def</span> isEmpty <span style="color: #000080;">=</span> value.<span style="color: #000000;">isEmpty</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> isDefined <span style="color: #000080;">=</span> <span style="color: #000080;">!</span> isEmpty
	<span style="color: #0000ff; font-weight: bold;">def</span> get<span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> value.<span style="color: #000000;">get</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> set<span style="color: #F78811;">&#40;</span>newValue<span style="color: #000080;">:</span> T<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span> value <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#125;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> getOrSet<span style="color: #F78811;">&#40;</span> newValue<span style="color: #000080;">:</span> <span style="color: #000080;">=&gt;</span> T<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>isDefined<span style="color: #F78811;">&#41;</span> get <span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #F78811;">&#123;</span>
		set<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span>
		get
	<span style="color: #F78811;">&#125;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> or<span style="color: #F78811;">&#40;</span> newValue<span style="color: #000080;">:</span> <span style="color: #000080;">=&gt;</span> T<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> T <span style="color: #000080;">=</span> getOrSet<span style="color: #F78811;">&#40;</span>newValue<span style="color: #F78811;">&#41;</span>
	<span style="color: #0000ff; font-weight: bold;">override</span> <span style="color: #0000ff; font-weight: bold;">def</span> toString <span style="color: #000080;">=</span> value.<span style="color: #000000;">toString</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> Memoized <span style="color: #F78811;">&#123;</span>
	<span style="color: #0000ff; font-weight: bold;">def</span> apply<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Memoized<span style="color: #F78811;">&#91;</span>T<span style="color: #F78811;">&#93;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/geek/lang/scala/lazy-vals-with-implicit-parameters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Future Is Now: Treasures in the Carbon docs</title>
		<link>http://harnly.net/2008/blog/geek/macosx/the-future-is-now-treasures-in-the-carbon-docs/</link>
		<comments>http://harnly.net/2008/blog/geek/macosx/the-future-is-now-treasures-in-the-carbon-docs/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 18:28:38 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/geek/macosx/the-future-is-now-treasures-in-the-carbon-docs/</guid>
		<description><![CDATA[Ran across these funny notes in the Carbon documentation:

This warning that &#8220;The Future&#8221; could arrive any day:

Important: In the future, individual application processes may not always share the same address space, so in general you should never attempt to access code or data in another process.

and this one is just precious:

Note: Because multitasking allows an [...]]]></description>
			<content:encoded><![CDATA[<p>Ran across these funny notes in the Carbon documentation:</p>

<p><a href="http://developer.apple.com/documentation/Carbon/Conceptual/Multitasking_MultiproServ/03tasks/chapter_3_section_13.html">This warning that &#8220;The Future&#8221; could arrive any day:</a></p>

<blockquote><b>Important</b>: In the future, individual application processes may not always share the same address space, so in general you should never attempt to access code or data in another process.</b></blockquote>

<p>and <a href="http://developer.apple.com/documentation/Carbon/Conceptual/Multitasking_MultiproServ/02concepts/chapter_2_section_3.html#//apple_ref/doc/uid/TP30000268-DontLinkElementID_5">this one is just precious</a>:</p>

<blockquote><b>Note</b>: Because multitasking allows an operating system to attend to several different operations at the same time, these operations may appear to occur simultaneously on even a single-processor system, due to the speed of the processor.</blockquote>

<p>You don&#8217;t say. </p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/geek/macosx/the-future-is-now-treasures-in-the-carbon-docs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Submitted without comment</title>
		<link>http://harnly.net/2007/blog/geek/microsoft/submitted-without-comment/</link>
		<comments>http://harnly.net/2007/blog/geek/microsoft/submitted-without-comment/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 20:59:19 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/geek/microsoft/submitted-without-comment/</guid>
		<description><![CDATA[Make of it what you will:


]]></description>
			<content:encoded><![CDATA[<p>Make of it what you will:</p>

<p><img src="http://img.photobucket.com/albums/v609/mithrastheprophet/top-book-in-the-microsoft-network.png"></p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/microsoft/submitted-without-comment/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Somebody oughta&#8230;</title>
		<link>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 20:57:57 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[markdown]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/geek/lang/java/somebody-oughta/</guid>
		<description><![CDATA[&#8230;write a JavaDoc Doclet so I can use Markdown instead of nasty old HTML in source code comments. How nice would that be?

While we&#8217;re at it, somebody oughta write a Markdown plugin for Apple Mail, too. But I think that somebody should be me, so I&#8217;ll put off thinking about it for awhile.
]]></description>
			<content:encoded><![CDATA[<p>&#8230;write a <a href="http://java.sun.com/j2se/javadoc/">JavaDoc</a> <a href="http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/doclet/overview.html">Doclet</a> so I can use <a href="http://daringfireball.net/projects/markdown/">Markdown</a> instead of nasty old HTML in source code comments. How nice would that be?</p>

<p>While we&#8217;re at it, somebody oughta write a Markdown plugin for Apple Mail, too. But I think that somebody should be me, so I&#8217;ll put off thinking about it for awhile.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Somebody oughta&#8230;</title>
		<link>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta-2/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta-2/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 20:57:57 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[markdown]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/autobiography/somebody-oughta-2/</guid>
		<description><![CDATA[&#8230;write a JavaDoc Doclet so I can use Markdown instead of nasty old HTML in source code comments. How nice would that be?

While we&#8217;re at it, somebody oughta write a Markdown plugin for Apple Mail, too. But I think that somebody should be me, so I&#8217;ll put off thinking about it for awhile.
]]></description>
			<content:encoded><![CDATA[<p>&#8230;write a <a href="http://java.sun.com/j2se/javadoc/">JavaDoc</a> <a href="http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/doclet/overview.html">Doclet</a> so I can use <a href="http://daringfireball.net/projects/markdown/">Markdown</a> instead of nasty old HTML in source code comments. How nice would that be?</p>

<p>While we&#8217;re at it, somebody oughta write a Markdown plugin for Apple Mail, too. But I think that somebody should be me, so I&#8217;ll put off thinking about it for awhile.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/java/somebody-oughta-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>TextMate bundle for Scala</title>
		<link>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/</link>
		<comments>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 18:52:11 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/macosx/textmate-bundle-for-scala/</guid>
		<description><![CDATA[I&#8217;ve put together a stub of a TextMate bundle for Scala. 

At the moment, it just contains a bare-bones language definition, a template for Ant tasks, and a couple of snippets. I&#8217;d like to keep improving it, and would welcome suggestions and modifications.

I&#8217;ll be setting up anonymous SVN access one of these days (yeah, right), [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve put together a stub of a <a href="http://macromates.com/textmate/manual/bundles">TextMate bundle</a> for <a href="http://www.scala-lang.org">Scala</a>. </p>

<p>At the moment, it just contains a bare-bones language definition, a template for Ant tasks, and a couple of snippets. I&#8217;d like to keep improving it, and would welcome suggestions and modifications.</p>

<p>I&#8217;ll be setting up anonymous SVN access one of these days (yeah, right), but for the moment, you can download the bundle directly: </p>

<p><a href="/projects/scala-textmate-bundle/downloads/ScalaAWH.tmbundle.zip"><img src="/projects/images/filetypes/128/tmbundle.png">
ScalaAWH.tmbundle.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NLTK&#8217;s &#8220;ing words&#8221;: variations</title>
		<link>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations/#comments</comments>
		<pubDate>Sun, 22 Apr 2007 13:36:23 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/ruby/nltks-ing-words-variations/</guid>
		<description><![CDATA[NLTK, the &#8220;natural language toolkit&#8221; for Python, is a wonderful lightweight framework that provides a wealth of NLP tools. The other day, in reading through its documentation, I came across a little appendix describing the advantages of Python for implementing and (especially) teaching NLP.

The authors show a simple sample program to find and list words [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nltk.sourceforge.net">NLTK, the &#8220;natural language toolkit&#8221;</a> for Python, is a wonderful lightweight framework that provides a wealth of NLP tools. The other day, in reading through its documentation, I came across a <a href="http://nltk.sourceforge.net/lite/doc/en/nlp-python.html">little appendix describing the advantages of Python</a> for implementing and (especially) teaching NLP.</p>

<p>The authors show a simple sample program to find and list words ending in &#8220;ing&#8221; from the standard input:</p>

<p><code>import sys
for line in sys.stdin.readlines():
    for word in line.split():
        if word.endswith('ing'):
            print word</code></p>

<p>and contrast this elegant Python implementation with a variety of monstrosities in other languages. I won&#8217;t disagree that the Python is nice, but it seemed like a good little exercise to see whether I can&#8217;t produce something almost as good in my languages de jour.</p>

<p>To wit, a Ruby version:
<code>for line in ARGF 
  for word in line.split
    if word.match(/ing$/) then
      puts word<br />
    end
  end
end
</code></p>

<p>which is almost identical to the Python version, though showing Ruby&#8217;s not-exactly-pretty fascination with the &#8216;end&#8217; keyword.</p>

<p>And a Scala version using for-comprehensions. Note to Scala creators: It&#8217;s really frustrating having the various ways of executing Scala &#8212; as a script, as an object, etc. &#8212; all disagree slightly on how the outermost wrapper of a procedure should be formatted. </p>

<p><code>import scala.io._
object IngWords extends Application {
   for (
      val line &lt;- Source.fromInputStream(System.in).getLines;
      val word &lt;- line.split(" ");
      word.endsWith("ing")
   ) 
  Console.println(word)<br />
}</code></p>

<p>(Aside: I need a decent syntax highlighting package for WP, it seems.)</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NLTK&#8217;s &#8220;ing words&#8221;: variations</title>
		<link>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations-2/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations-2/#comments</comments>
		<pubDate>Sun, 22 Apr 2007 13:36:23 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/autobiography/nltks-ing-words-variations-2/</guid>
		<description><![CDATA[NLTK, the &#8220;natural language toolkit&#8221; for Python, is a wonderful lightweight framework that provides a wealth of NLP tools. The other day, in reading through its documentation, I came across a little appendix describing the advantages of Python for implementing and (especially) teaching NLP.

The authors show a simple sample program to find and list words [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nltk.sourceforge.net">NLTK, the &#8220;natural language toolkit&#8221;</a> for Python, is a wonderful lightweight framework that provides a wealth of NLP tools. The other day, in reading through its documentation, I came across a <a href="http://nltk.sourceforge.net/lite/doc/en/nlp-python.html">little appendix describing the advantages of Python</a> for implementing and (especially) teaching NLP.</p>

<p>The authors show a simple sample program to find and list words ending in &#8220;ing&#8221; from the standard input:</p>

<p><code>import sys
for line in sys.stdin.readlines():
    for word in line.split():
        if word.endswith('ing'):
            print word</code></p>

<p>and contrast this elegant Python implementation with a variety of monstrosities in other languages. I won&#8217;t disagree that the Python is nice, but it seemed like a good little exercise to see whether I can&#8217;t produce something almost as good in my languages de jour.</p>

<p>To wit, a Ruby version:
<code>for line in ARGF 
  for word in line.split
    if word.match(/ing$/) then
      puts word<br />
    end
  end
end
</code></p>

<p>which is almost identical to the Python version, though showing Ruby&#8217;s not-exactly-pretty fascination with the &#8216;end&#8217; keyword.</p>

<p>And a Scala version using for-comprehensions. Note to Scala creators: It&#8217;s really frustrating having the various ways of executing Scala &#8212; as a script, as an object, etc. &#8212; all disagree slightly on how the outermost wrapper of a procedure should be formatted. </p>

<p><code>import scala.io._
object IngWords extends Application {
   for (
      val line &lt;- Source.fromInputStream(System.in).getLines;
      val word &lt;- line.split(" ");
      word.endsWith("ing")
   ) 
  Console.println(word)<br />
}</code></p>

<p>(Aside: I need a decent syntax highlighting package for WP, it seems.)</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/ruby/nltks-ing-words-variations-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>each_line do &#124;line&#124; in Scala</title>
		<link>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala/#comments</comments>
		<pubDate>Wed, 28 Mar 2007 04:32:16 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/scala/each_line-do-line-in-scala/</guid>
		<description><![CDATA[I&#8217;m so used to the each_line idiom in Ruby, I felt utterly lost in Scala without it. 

Here&#8217;s an approximation of it, though I&#8217;d love to hear that there&#8217;s an even more scala-ish (scalic?) way of doing this:

   def eachline(stream : InputStream)(f : String => Unit) {
      val [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m so used to the each_line idiom in Ruby, I felt utterly lost in Scala without it. </p>

<p>Here&#8217;s an approximation of it, though I&#8217;d love to hear that there&#8217;s an even more scala-ish (scalic?) way of doing this:</p>

<p><code>   def eachline(stream : InputStream)(f : String => Unit) {
      val buf = new BufferedReader( new InputStreamReader( stream ) )
      var line = buf.readLine
      while (line != null) {
         f(line)
         line = buf.readLine
      }
   }
</code></p>

<p>I use this with a block as so:
<code>      eachline(System.in) { line =>
         Console.println(line)
      }
</code></p>

<p>Not bad, but it could be better, I think. Can I tickle this to be a method on streams, instead of a funny little function sitting on its own?</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala/feed/</wfw:commentRss>
		</item>
		<item>
		<title>each_line do &#124;line&#124; in Scala</title>
		<link>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala-2/</link>
		<comments>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala-2/#comments</comments>
		<pubDate>Wed, 28 Mar 2007 04:32:16 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/autobiography/each_line-do-line-in-scala-2/</guid>
		<description><![CDATA[I&#8217;m so used to the each_line idiom in Ruby, I felt utterly lost in Scala without it. 

Here&#8217;s an approximation of it, though I&#8217;d love to hear that there&#8217;s an even more scala-ish (scalic?) way of doing this:

   def eachline(stream : InputStream)(f : String => Unit) {
      val [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m so used to the each_line idiom in Ruby, I felt utterly lost in Scala without it. </p>

<p>Here&#8217;s an approximation of it, though I&#8217;d love to hear that there&#8217;s an even more scala-ish (scalic?) way of doing this:</p>

<p><code>   def eachline(stream : InputStream)(f : String => Unit) {
      val buf = new BufferedReader( new InputStreamReader( stream ) )
      var line = buf.readLine
      while (line != null) {
         f(line)
         line = buf.readLine
      }
   }
</code></p>

<p>I use this with a block as so:
<code>      eachline(System.in) { line =>
         Console.println(line)
      }
</code></p>

<p>Not bad, but it could be better, I think. Can I tickle this to be a method on streams, instead of a funny little function sitting on its own?</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/lang/scala/each_line-do-line-in-scala-2/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.040 seconds -->
