<?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-7393949551245461895</id><updated>2011-11-02T08:12:12.869-07:00</updated><category term='scala'/><category term='parser combinator'/><title type='text'>A+</title><subtitle type='html'>Plain Old Java Programmer</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://virasak.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7393949551245461895/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://virasak.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Virasak Dungsrikaew</name><uri>http://www.blogger.com/profile/18425018230442299719</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>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7393949551245461895.post-7563818013339110690</id><published>2010-01-12T03:42:00.000-08:00</published><updated>2010-04-08T00:18:06.685-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Word Counts in Scala</title><content type='html'>After reading &lt;a href="http://blogs.sourceallies.com/2009/12/word-counts-example-in-ruby-and-scala"&gt;Zach Cox blog about word counting&lt;/a&gt;, I found that some parts of his Scala code are unnecessary long. For examples, using Tuple2[String,Int] instead of (String,Int) or nest for loop. The file2String is also unnecessary, because we can use line iterator from Source#getLines. So I try to implement my version that suppose to shorter and be more Scala. Here is a result:&lt;br /&gt;&lt;br /&gt;&lt;script src="http://gist.github.com/265899.js?file=WordFreq.scala"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;The best part of my code (in my opinion) is the for loop. It's concise and readable.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7393949551245461895-7563818013339110690?l=virasak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://virasak.blogspot.com/feeds/7563818013339110690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://virasak.blogspot.com/2010/01/word-counts-in-scala.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7393949551245461895/posts/default/7563818013339110690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7393949551245461895/posts/default/7563818013339110690'/><link rel='alternate' type='text/html' href='http://virasak.blogspot.com/2010/01/word-counts-in-scala.html' title='Word Counts in Scala'/><author><name>Virasak Dungsrikaew</name><uri>http://www.blogger.com/profile/18425018230442299719</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-7393949551245461895.post-4854212565256618154</id><published>2009-09-24T23:43:00.000-07:00</published><updated>2009-09-25T00:16:10.345-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><category scheme='http://www.blogger.com/atom/ns#' term='parser combinator'/><title type='text'>Parser combinator with line oriented file format</title><content type='html'>Last night, I have flighted with parser combinator to parse the XYZ format that be commonly used in molecular visualization programs. I am new in parser combinator, so it take me a few hours to accustom to its warning and errors.&lt;br /&gt;&lt;br /&gt;The problem is the format uses new lines as a token to group each atom, but I can't find any ready-to-used parsers class or any tutorial that handle this problem. After an hour of experiment, finally I found the solution. To handle new lines as a token, I have to override whiteSpace to not include \n (because I extends my parser from RegexParsers). Now I known that why nobody tell me how to fixed it, because it's just simple.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7393949551245461895-4854212565256618154?l=virasak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://virasak.blogspot.com/feeds/4854212565256618154/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://virasak.blogspot.com/2009/09/parser-combinator-with-line-oriented.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7393949551245461895/posts/default/4854212565256618154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7393949551245461895/posts/default/4854212565256618154'/><link rel='alternate' type='text/html' href='http://virasak.blogspot.com/2009/09/parser-combinator-with-line-oriented.html' title='Parser combinator with line oriented file format'/><author><name>Virasak Dungsrikaew</name><uri>http://www.blogger.com/profile/18425018230442299719</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-7393949551245461895.post-3742783588780993039</id><published>2009-09-20T03:08:00.000-07:00</published><updated>2009-09-25T00:16:26.463-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Hello, Scala!</title><content type='html'>Recently, my work is implementing a scientific computing program in Scala.&lt;br /&gt;So, This blog will be my memo for both scientific things and Scala (and also any languages I have introduced in this work)&lt;br /&gt;&lt;br /&gt;I will start with a simple problem that I found in&lt;br /&gt;http://dotneverland.blogspot.com/2009/09/quick-sample-of-lists-and-tuples-in.html .&lt;br /&gt;Change the list of numbers into a list of pair-wise sum of the numbers.&lt;br /&gt;ex. [1, 2, 3, 4, 5] =&gt; [3, 5, 7, 9]&lt;br /&gt;&lt;br /&gt;My best solution is&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;val numbers = List(1,2,3,4,5)&lt;br /&gt;numbers.zip(numbers.tail).map {&lt;br /&gt;case (a, b) =&gt; a + b&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// or&lt;br /&gt;List.map2(numbers, numbers.tail) {&lt;br /&gt;case (a, b) =&gt; a + b&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;The case function is a shorthand of pattern matching. It is used in this code to take advantage of deconstructor of tuple. If we don't used this way, we have to access the tuple elements by _1 and _2 properties.&lt;br /&gt;&lt;br /&gt;Update&lt;br /&gt;I just found that map2 can receive Function2&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;&lt;br /&gt;List.map2(numbers, numbers.tail)(_+_)&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/7393949551245461895-3742783588780993039?l=virasak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://virasak.blogspot.com/feeds/3742783588780993039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://virasak.blogspot.com/2009/09/hello-scala.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7393949551245461895/posts/default/3742783588780993039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7393949551245461895/posts/default/3742783588780993039'/><link rel='alternate' type='text/html' href='http://virasak.blogspot.com/2009/09/hello-scala.html' title='Hello, Scala!'/><author><name>Virasak Dungsrikaew</name><uri>http://www.blogger.com/profile/18425018230442299719</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>
