Permalink
Browse files

Site updated at 2012-12-11 01:22:02 UTC

  • Loading branch information...
1 parent 4b51c54 commit d70e921c984c8c9d5a85e2c735d90a11bea9ff31 @reniclin committed Dec 11, 2012
View
@@ -4,7 +4,7 @@
<title><![CDATA[Renic Lin]]></title>
<link href="http://reniclin.github.com/atom.xml" rel="self"/>
<link href="http://reniclin.github.com/"/>
- <updated>2012-12-10T11:23:44+08:00</updated>
+ <updated>2012-12-11T09:21:14+08:00</updated>
<id>http://reniclin.github.com/</id>
<author>
<name><![CDATA[Renic Lin]]></name>
@@ -14,6 +14,41 @@
<entry>
+ <title type="html"><![CDATA[Clojure Read a File as a Sequence of Lines]]></title>
+ <link href="http://reniclin.github.com/blog/2012/12/11/clojure-read-a-file-as-a-sequence-of-lines/"/>
+ <updated>2012-12-11T09:04:00+08:00</updated>
+ <id>http://reniclin.github.com/blog/2012/12/11/clojure-read-a-file-as-a-sequence-of-lines</id>
+ <content type="html"><![CDATA[<h2>Clojure把檔案逐行讀成sequence</h2>
+
+<!-- more -->
+
+
+<p>Clojure (Lisp) 常用到sequence,讀檔時也可以把檔案逐行讀成sequence:</p>
+
+<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+</pre></td><td class='code'><pre><code class='clojure'><span class='line'><span class="p">(</span><span class="nb">line-seq </span><span class="p">(</span><span class="nf">clojure.java.io/reader</span> <span class="p">(</span><span class="nf">clojure.java.io/file</span> <span class="s">&quot;file-path&quot;</span><span class="p">)))</span>
+</span></code></pre></td></tr></table></div></figure>
+
+
+<p>讀出來的東西類似像這樣:</p>
+
+<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+</pre></td><td class='code'><pre><code class='clojure'><span class='line'><span class="p">(</span><span class="s">&quot;line-1&quot;</span> <span class="s">&quot;line-2&quot;</span> <span class="s">&quot;line-3&quot;</span> <span class="s">&quot;line-4&quot;</span> <span class="s">&quot;line-4&quot;</span><span class="p">)</span>
+</span></code></pre></td></tr></table></div></figure>
+
+
+<p>讀成sequence之後就可以用doseq之類方便處裡sequence的macro來操作它,例如:</p>
+
+<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
+<span class='line-number'>2</span>
+</pre></td><td class='code'><pre><code class='clojure'><span class='line'><span class="p">(</span><span class="nb">doseq </span><span class="p">[</span><span class="nv">line</span> <span class="p">(</span><span class="nb">line-seq </span><span class="p">(</span><span class="nf">clojure.java.io/reader</span> <span class="p">(</span><span class="nf">clojure.java.io/file</span> <span class="s">&quot;file-path&quot;</span><span class="p">)))]</span>
+</span><span class='line'> <span class="p">(</span><span class="nb">println </span><span class="nv">line</span><span class="p">))</span>
+</span></code></pre></td></tr></table></div></figure>
+
+]]></content>
+ </entry>
+
+ <entry>
<title type="html"><![CDATA[web-todo]]></title>
<link href="http://reniclin.github.com/blog/2012/08/27/web-todo/"/>
<updated>2012-08-27T21:16:00+08:00</updated>
@@ -159,86 +194,86 @@
<h3>lein 1.x</h3>
-<ol>
+<ul>
<li>安裝 leiningen noir plugin</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein plugin install lein-noir 1.2.1
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>建立一個新的 noir 專案</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein noir new my-web
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>cd 到剛剛建出來的資料夾</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span><span class="nb">cd </span>my-web
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>試跑一下</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein run
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>成功跑起來之後可以用瀏覽器打開 http://localhost:8080 就可以看到歡迎畫面。</li>
-</ol>
+</ul>
<h3>lein 2.x 的步驟比較簡單,不用先裝 plugin</h3>
-<ol>
+<ul>
<li>建立一個新的 noir 專案</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein new noir my-web
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>cd 到剛剛建出來的資料夾</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span><span class="nb">cd </span>my-web
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>試跑一下</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein run
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>成功跑起來之後可以用瀏覽器打開 http://localhost:8080 就可以看到歡迎畫面。</li>
-</ol>
+</ul>
]]></content>
</entry>
@@ -256,9 +291,9 @@
<p>前陣子在使用 seesaw 寫 desktop app,遇到想把所有 source code build 成單一執行檔的需求,
使用 leiningen,可以輕鬆把你的 source 和其它的 dependencies 包成一個可單獨執行 standalone 的 jar。</p>
-<ol>
+<ul>
<li>在宣告ns時要加上 (:gen-class),例如:</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
@@ -274,9 +309,9 @@
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>在project.clj裡加上 :main,例如:</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
@@ -294,14 +329,14 @@
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li><p>使用 leiningen 產生 jar</p>
-<p> $ lein uberjar</p></li>
+<p> $ lein uberjar</p></li>
<li><p>執行</p>
-<p> $ java -jar my-project-1.0.0-SNAPSHOT-standalone.jar</p></li>
-</ol>
+<p> $ java -jar my-project-1.0.0-SNAPSHOT-standalone.jar</p></li>
+</ul>
]]></content>
</entry>
@@ -105,9 +105,9 @@ <h1 class="entry-title">Clojure Building Standalone Jar With Leiningen</h1>
<p>前陣子在使用 seesaw 寫 desktop app,遇到想把所有 source code build 成單一執行檔的需求,
使用 leiningen,可以輕鬆把你的 source 和其它的 dependencies 包成一個可單獨執行 standalone 的 jar。</p>
-<ol>
+<ul>
<li>在宣告ns時要加上 (:gen-class),例如:</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
@@ -123,9 +123,9 @@ <h1 class="entry-title">Clojure Building Standalone Jar With Leiningen</h1>
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>在project.clj裡加上 :main,例如:</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
@@ -143,14 +143,14 @@ <h1 class="entry-title">Clojure Building Standalone Jar With Leiningen</h1>
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li><p>使用 leiningen 產生 jar</p>
-<p> $ lein uberjar</p></li>
+<p> $ lein uberjar</p></li>
<li><p>執行</p>
-<p> $ java -jar my-project-1.0.0-SNAPSHOT-standalone.jar</p></li>
-</ol>
+<p> $ java -jar my-project-1.0.0-SNAPSHOT-standalone.jar</p></li>
+</ul>
</div>
@@ -231,6 +231,10 @@ <h1 class="entry-title">Clojure Building Standalone Jar With Leiningen</h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/2012/12/11/clojure-read-a-file-as-a-sequence-of-lines/">Clojure Read a File as a Sequence of Lines</a>
+ </li>
+
+ <li class="post">
<a href="/blog/2012/08/27/web-todo/">web-todo</a>
</li>
@@ -289,7 +293,7 @@ <h1 class="entry-title">Clojure Building Standalone Jar With Leiningen</h1>
<section>
<h1>Categories</h1>
<ul id="categories">
- <li class='category'><a href='/blog/categories/clojure/'>clojure (2)</a></li>
+ <li class='category'><a href='/blog/categories/clojure/'>clojure (3)</a></li>
<li class='category'><a href='/blog/categories/clojurescript/'>clojurescript (2)</a></li>
<li class='category'><a href='/blog/categories/jar/'>jar (1)</a></li>
<li class='category'><a href='/blog/categories/leiningen/'>leiningen (2)</a></li>
@@ -108,86 +108,86 @@ <h1 class="entry-title">Clojure Noir Getting Start</h1>
<h3>lein 1.x</h3>
-<ol>
+<ul>
<li>安裝 leiningen noir plugin</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein plugin install lein-noir 1.2.1
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>建立一個新的 noir 專案</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein noir new my-web
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>cd 到剛剛建出來的資料夾</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span><span class="nb">cd </span>my-web
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>試跑一下</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein run
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>成功跑起來之後可以用瀏覽器打開 http://localhost:8080 就可以看到歡迎畫面。</li>
-</ol>
+</ul>
<h3>lein 2.x 的步驟比較簡單,不用先裝 plugin</h3>
-<ol>
+<ul>
<li>建立一個新的 noir 專案</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein new noir my-web
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>cd 到剛剛建出來的資料夾</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span><span class="nb">cd </span>my-web
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>試跑一下</li>
-</ol>
+</ul>
<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>lein run
</span></code></pre></td></tr></table></div></figure>
-<ol>
+<ul>
<li>成功跑起來之後可以用瀏覽器打開 http://localhost:8080 就可以看到歡迎畫面。</li>
-</ol>
+</ul>
</div>
@@ -270,6 +270,10 @@ <h1 class="entry-title">Clojure Noir Getting Start</h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/2012/12/11/clojure-read-a-file-as-a-sequence-of-lines/">Clojure Read a File as a Sequence of Lines</a>
+ </li>
+
+ <li class="post">
<a href="/blog/2012/08/27/web-todo/">web-todo</a>
</li>
@@ -328,7 +332,7 @@ <h1 class="entry-title">Clojure Noir Getting Start</h1>
<section>
<h1>Categories</h1>
<ul id="categories">
- <li class='category'><a href='/blog/categories/clojure/'>clojure (2)</a></li>
+ <li class='category'><a href='/blog/categories/clojure/'>clojure (3)</a></li>
<li class='category'><a href='/blog/categories/clojurescript/'>clojurescript (2)</a></li>
<li class='category'><a href='/blog/categories/jar/'>jar (1)</a></li>
<li class='category'><a href='/blog/categories/leiningen/'>leiningen (2)</a></li>
Oops, something went wrong.

0 comments on commit d70e921

Please sign in to comment.