<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Go towards a Word-Progress &#187; 中学生</title>
	<atom:link href="http://wordprogress.org/archives/tag/%e4%b8%ad%e5%ad%a6%e7%94%9f/feed" rel="self" type="application/rss+xml" />
	<link>http://wordprogress.org</link>
	<description>　～言霊とプログラム言語の共進化!?</description>
	<lastBuildDate>Fri, 22 Jan 2010 03:37:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>ScalaとJavaScript　その１　クロージャ</title>
		<link>http://wordprogress.org/archives/257</link>
		<comments>http://wordprogress.org/archives/257#comments</comments>
		<pubDate>Fri, 06 Nov 2009 03:50:39 +0000</pubDate>
		<dc:creator>アルケー</dc:creator>
				<category><![CDATA[Scala]]></category>
		<category><![CDATA[啓蒙]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[中学生]]></category>

		<guid isPermaLink="false">http://wordprogress.org/?p=257</guid>
		<description><![CDATA[
		<script type="text/javascript"><!--
			show_rakuten('#rakuteneagles10001402', 'NotFound');
		// -->
		</script>
		教育用言語としてのJavaScriptに注目している。
正直、JavaScriptは苦手なので、Scalaと比較しながら、まずは自分で要点を把握する。
まずは、力作の[JavaScript]　猿でもわかるクロージャ超入門を勉強させていただく。
[JavaScript]　猿でもわかるクロージャ超入門から、以下、抜粋
「クロージャーって何？」って誰かに聞かれたら、
「ああ、関数の中に書く関数のことでしょ」って答えとけば、３０％ぐらい正解ということになります。(w
・・・
関数の中の関数
Javascriptで、関数の中に関数を書く・・・innerを実行するには、outer内でinner( )を実行
function outer(){
    function inner(){
        alert("hello");
    }
    inner();  //←コレ
}

outer(); // "hello"と表示された！
Scalaではこんな感じ
scala&#62; def outer {
     &#124;     def inner =   print("hello");
     &#124;     [...]]]></description>
			<content:encoded><![CDATA[
		<script type="text/javascript"><!--
			show_rakuten('#rakuteneagles10001402', 'NotFound');
		// -->
		</script>
		<p>教育用言語としてのJavaScriptに注目している。<br />
正直、JavaScriptは苦手なので、Scalaと比較しながら、まずは自分で要点を把握する。</p>
<p>まずは、力作の<a href="http://dqn.sakusakutto.jp/2009/01/javascript_1.html">[JavaScript]　猿でもわかるクロージャ超入門</a>を勉強させていただく。</p>
<h3><span style="text-decoration: underline;"><a href="http://dqn.sakusakutto.jp/2009/01/javascript_1.html">[JavaScript]　猿でもわかるクロージャ超入門</a>から、以下、抜粋</span></h3>
<p>「クロージャーって何？」って誰かに聞かれたら、<br />
「ああ、関数の中に書く関数のことでしょ」って答えとけば、３０％ぐらい正解ということになります。(w</p>
<p>・・・</p>
<h4 style="margin-top: 1.5em; margin-right: 1em; margin-bottom: 1em; margin-left: 0.1em; padding-top: 0.4em; padding-right: 0.4em; padding-bottom: 0.3em; padding-left: 1.1em; font-size: 16px; font-weight: bold; border-left-style: solid; border-left-width: 0.4em; border-left-color: #9999ff;">関数の中の関数</h4>
<p>Javascriptで、関数の中に関数を書く・・・innerを実行するには、outer内でinner( )を実行</p>
<pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.75em; margin-left: 0px; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: #eeeeff; overflow-x: auto; overflow-y: auto; font-family: 'Courier New', Courier, mono; line-height: 1; background-position: initial initial; padding: 0.5em; border: 1px dotted #999999;"><code style="padding: 0px; margin: 0px;">function outer(){
    function inner(){
        alert("hello");
    }
    inner();  //←コレ
}

outer(); // "hello"と表示された！</code></pre>
<h5 style="font-size: 0.83em; ">Scalaではこんな感じ</h5>
<pre style="margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; background-color: #f8f8f8; white-space: pre-wrap; word-wrap: break-word; padding: 1ex; border: 1px solid #707b8d;">scala&gt; def outer {
     |     def inner =   print("hello");
     |     inner  //呼び出し
     | }
outer: Unit
scala&gt; outer
hello</pre>
<h4 style="margin-top: 1.5em; margin-right: 1em; margin-bottom: 1em; margin-left: 0.1em; padding-top: 0.4em; padding-right: 0.4em; padding-bottom: 0.3em; padding-left: 1.1em; font-size: 16px; font-weight: bold; border-left-style: solid; border-left-width: 0.4em; border-left-color: #9999ff;">無名関数</h4>
<h5 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.75em; margin-left: 0px; font-size: 14px; font-weight: bold; padding: 0px;">関数を定義する方法その２　(無名関数を使う)</h5>
<pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.75em; margin-left: 0px; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: #eeeeff; overflow-x: auto; overflow-y: auto; font-family: 'Courier New', Courier, mono; line-height: 1; background-position: initial initial; padding: 0.5em; border: 1px dotted #999999;"><code style="padding: 0px; margin: 0px;">var <strong>speak =</strong> function <strong>()</strong>{ alert("hello"); }

speak(); // "hello"と出力</code></pre>
<p>無名関数を定義してすぐさま実行したいときは<br />
( function( ){..} )( );</p>
<h5>感想</h5>
<p>おおっ・・・もし学校でJavaScriptを教えてたら、なんで、最後の<span style="color: #800000;"><strong>();</strong></span>は省略できないのって、質問が出そう。Scalaでの無名関数は簡単すぎるので、省略(RUbyのブロックあたりと並べて説明するべきかな)。関係ないが、valとlazy valの違いの説明には使えるかも。</p>
<h4><span style="color: #800000;">◇ちょっと休憩。</span></h4>
<p><span style="color: #800000;">「モナドは像だ」ならば、「クロージャは鷲だ」 [　=&gt;　大鷲(元の関数)の中に別の鳥(例えば、ハヤブサ・・返り値としての関数)があるイメージ]<br />
・・・ということで、東北楽天ゴールデンイーグルス。あぁ、札幌の第一戦を勝っていれば、今頃、仙台で日本シ(以下略)・・いや、仙台といえば、これからは<a href="http://sites.google.com/site/scalatohoku/">Scala東北</a>だ(勝手推薦)。<br />
</span> <div id="rakuteneagles10001402" class="rakuten_details">Now Loading...</div></p>
<h3><span style="text-decoration: underline;"><a href="http://dqn.sakusakutto.jp/2009/01/javascript_4.html">[JavaScript]　猿でもわかるクロージャ超入門　最終回</a>から、以下、抜粋</span></h3>
<p>こんなコードを実行してみてください。</p>
<pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.75em; margin-left: 0px; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: #eeeeff; overflow-x: auto; overflow-y: auto; font-family: 'Courier New', Courier, mono; line-height: 1; background-position: initial initial; padding: 0.5em; border: 1px dotted #999999;"><code style="padding: 0px; margin: 0px;">//サンプル5-2

function outer(){
    var x = 1;

    return　function (){
        alert(x);
	<strong>x = x + 1</strong>;
    };

}

var f =  outer();
f();  // 1
f();  // 2
f();  // 3

</code></pre>
<p>&#8230;クロージャを使うと、このように「状態を保持する関数」を作ることができます。&#8230;「クロージャはオブジェクトに似ている」</p>
<h5 style="font-size: 0.83em; ">Scalaでクローじゃ</h5>
<ul>
<li>まずは、クロージャの定義 　※　<span style="color: #800000;"><strong><span style="color: #800000;">() =&gt; { }</span></strong></span>という無名関数のScala流表記は、JavaScriptよりも、直感的でないかも・・　これは高階関数(以下略)</li>
</ul>
<pre class="brush:scala">def outer = {
    var x =0
    //これが無名関数として返される。
    () =&gt; { x += 1;print("x : "+x); ; x}
}</pre>
<ul>
<li>クロージャが遅延評価される様子、実行する環境ごと(ここでは、変数f、変数g)に内部状態カあることを見ておこう :</li>
</ul>
<pre style="margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; background-color: #f8f8f8; white-space: pre-wrap; word-wrap: break-word; padding: 1ex; border: 1px solid #707b8d;">scala&gt; println {" f : "+f()}
x : 1 f : 1
scala&gt; println {" f : "+f()}
x : 2 f : 2
scala&gt; println {" f : "+f()}
x : 3 f : 3
 ※余計なこと[fって何と聞く]をしてみる
scala&gt; f
res43: () =&gt; Int =
 ※そんなの関係ねぇ、な様子
scala&gt; println {" f : "+f()}
x : 4 f : 4
println {" g : "+g()}
x : 1 g : 1</pre>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 1270px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">
<pre class="brush:scala" style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; ">//これが無名関数として返される。</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://wordprogress.org/archives/257/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>「Scala入門」に勝手流追記　その1　yieldなど</title>
		<link>http://wordprogress.org/archives/238</link>
		<comments>http://wordprogress.org/archives/238#comments</comments>
		<pubDate>Fri, 06 Nov 2009 00:48:19 +0000</pubDate>
		<dc:creator>kyon</dc:creator>
				<category><![CDATA[Scala]]></category>
		<category><![CDATA[中学生]]></category>

		<guid isPermaLink="false">http://wordprogress.org/?p=238</guid>
		<description><![CDATA[
		<script type="text/javascript"><!--
			show_rakuten('#book12166433', '<!-- cache --><div class="rakuten_image"><a href="http://hb.afl.rakuten.co.jp/hgc/0b16999f.c5b9c54b.0b1699a0.49a76732/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fbook%2F4574749%2F" target="_blank"><img src="http://thumbnail.image.rakuten.co.jp/@0_mall/book/cabinet/4988/4988005491954.jpg?_ex=128x128"><br /><p class="rakuten_logo"><!-- Rakuten Web Services Attribution Snippet FROM HERE --><a href="http://webservice.rakuten.co.jp/" target="_blank"><img src="http://webservice.rakuten.co.jp/img/credit/200709/credit_4936.gif" border="0" alt="楽天ウェブサービスセンター" title="楽天ウェブサービスセンター" width="49" height="36"/></a><!-- Rakuten Web Services Attribution Snippet TO HERE --></p><font class="rakuten_warn"><a href="#" class="tooltip">[ご利用にあたって]<span>このサイトで掲載されている情報は、「Go towards a Word-Progress」の作成者により運営されています。価格、販売可能情報は、変更される場合があります。購入時に楽天市場店舗（www.rakuten.co.jp）に表示されている価格が、その商品の販売に適用されます。</span></a></font></div><div class="rakuten_info"><p class="rakuten_itemname"><a href="http://hb.afl.rakuten.co.jp/hgc/0b16999f.c5b9c54b.0b1699a0.49a76732/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fbook%2F4574749%2F" target="_blank">阿久悠を歌った100人 勝手にしやがれ 男性ポップス編</a></p><p class="rakuten_caption">(オムニバス)このアーティストの新着メールを登録する発売日：2007年11月05日登録情報レーベル：ユニバーサルミュージック(株)インターナショナル発売元：ユニバーサル ミュージック(株)ディスク枚数：1枚(CD1枚)総曲数：20(アルバム)収録時間：68分41秒品番：UICZ-8033JAN:4988005491954作詞家・阿久悠の作品を歌った男性歌手のオリジナル曲を集成。決定打といえる曲が抜けてはいるが、企画性やコンセプト先行型だった阿久の作詞法が、ポップスの本質である同時代性を突いていると実感させ……</p><p><em>販売価格：</em> 2500 円 <font class="rakuten_time">(10/07/30 03:35 更新)</font></p><p><em>販売店舗：</em> <a href="http://www.rakuten.co.jp/book/" target="_blank">楽天ブックス</a></p></div><!-- cache -->');
		// -->
		</script>
		
		<script type="text/javascript"><!--
			show_rakuten('#hobbyist10060346', 'NotFound');
		// -->
		</script>
		
		<script type="text/javascript"><!--
			show_rakuten('#et-cn10012696', '<!-- cache --><div class="rakuten_image"><a href="http://hb.afl.rakuten.co.jp/hgc/0b16999f.c5b9c54b.0b1699a0.49a76732/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fet-cn%2Fp10-547%2F" target="_blank"><img src="http://thumbnail.image.rakuten.co.jp/@0_mall/et-cn/cabinet/s38/p10-547.jpg?_ex=128x128"><br /><p class="rakuten_logo"><!-- Rakuten Web Services Attribution Snippet FROM HERE --><a href="http://webservice.rakuten.co.jp/" target="_blank"><img src="http://webservice.rakuten.co.jp/img/credit/200709/credit_4936.gif" border="0" alt="楽天ウェブサービスセンター" title="楽天ウェブサービスセンター" width="49" height="36"/></a><!-- Rakuten Web Services Attribution Snippet TO HERE --></p><font class="rakuten_warn"><a href="#" class="tooltip">[ご利用にあたって]<span>このサイトで掲載されている情報は、「Go towards a Word-Progress」の作成者により運営されています。価格、販売可能情報は、変更される場合があります。購入時に楽天市場店舗（www.rakuten.co.jp）に表示されている価格が、その商品の販売に適用されます。</span></a></font></div><div class="rakuten_info"><p class="rakuten_itemname"><a href="http://hb.afl.rakuten.co.jp/hgc/0b16999f.c5b9c54b.0b1699a0.49a76732/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fet-cn%2Fp10-547%2F" target="_blank">セガ/プライズ涼宮ハルヒの憂鬱EXフィギュア笹の葉ラプソディ全2種セット</a></p><p class="rakuten_caption">詳　細 2009年、改めて放送開始した“涼宮ハルヒの憂鬱”の新エピソードから待望の立体化。サブタイトル『笹の葉ラプソディ』に登場する中学生時代の涼宮ハルヒと大人の朝比奈みくるは、セガプライズのエクストラシリーズで初のラインナップです。・涼宮ハルヒ(東中)・朝比奈みくる(大)全2種セット◆その他の涼宮ハルヒの商品は　　　⇒　 こちらへ メーカー セガ サイズ ハルヒ:約15cm/みくる:約17cm その他 ・こちらの商品は未開封品になります。　　　　メーカー出荷時の商品パッケージにてお渡しいたします。　　＊……</p><p><em>販売価格：</em> 2625 円 <font class="rakuten_time">(10/07/30 03:35 更新)</font></p><p><em>販売店舗：</em> <a href="http://www.rakuten.co.jp/et-cn/" target="_blank">トレジャーカプセル楽天市場支店</a></p></div><!-- cache -->');
		// -->
		</script>
		このブログでは、Scalaを当然の前提としている一方で、ハルヒ中学生バージョンScala入門を書く気はないので、罪滅ぼしまでに、各地のScala入門に勝手流追記していこうと思いたつ。
 提供 勝手にしやがれ.orz(違)
Now Loading...
Scalaへのとっかかりとして、ウノウラボ内田氏のScala入門が簡潔で良い。・・・が、５分で伝えるために、はしょりすぎ・誤記がちょっとだけ垣間見える :
変数
関数型的な「val」と手続き指向的な「var」
val i = 1
var i = 1
val i:String = "hello"
var i:String = "hello"
追記
valは、再代入不可な変数(immutable)。varは代入可能な変数(mutable)。そのため、以下のようになる。:
scala&#62; val L = 1; var R =2
L: Int = 1
R: Int = 2

scala&#62; L += R
:7: error: reassignment to val
       L += R
         ^

scala&#62; [...]]]></description>
			<content:encoded><![CDATA[
		<script type="text/javascript"><!--
			show_rakuten('#book12166433', '<!-- cache --><div class="rakuten_image"><a href="http://hb.afl.rakuten.co.jp/hgc/0b16999f.c5b9c54b.0b1699a0.49a76732/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fbook%2F4574749%2F" target="_blank"><img src="http://thumbnail.image.rakuten.co.jp/@0_mall/book/cabinet/4988/4988005491954.jpg?_ex=128x128"><br /><p class="rakuten_logo"><!-- Rakuten Web Services Attribution Snippet FROM HERE --><a href="http://webservice.rakuten.co.jp/" target="_blank"><img src="http://webservice.rakuten.co.jp/img/credit/200709/credit_4936.gif" border="0" alt="楽天ウェブサービスセンター" title="楽天ウェブサービスセンター" width="49" height="36"/></a><!-- Rakuten Web Services Attribution Snippet TO HERE --></p><font class="rakuten_warn"><a href="#" class="tooltip">[ご利用にあたって]<span>このサイトで掲載されている情報は、「Go towards a Word-Progress」の作成者により運営されています。価格、販売可能情報は、変更される場合があります。購入時に楽天市場店舗（www.rakuten.co.jp）に表示されている価格が、その商品の販売に適用されます。</span></a></font></div><div class="rakuten_info"><p class="rakuten_itemname"><a href="http://hb.afl.rakuten.co.jp/hgc/0b16999f.c5b9c54b.0b1699a0.49a76732/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fbook%2F4574749%2F" target="_blank">阿久悠を歌った100人 勝手にしやがれ 男性ポップス編</a></p><p class="rakuten_caption">(オムニバス)このアーティストの新着メールを登録する発売日：2007年11月05日登録情報レーベル：ユニバーサルミュージック(株)インターナショナル発売元：ユニバーサル ミュージック(株)ディスク枚数：1枚(CD1枚)総曲数：20(アルバム)収録時間：68分41秒品番：UICZ-8033JAN:4988005491954作詞家・阿久悠の作品を歌った男性歌手のオリジナル曲を集成。決定打といえる曲が抜けてはいるが、企画性やコンセプト先行型だった阿久の作詞法が、ポップスの本質である同時代性を突いていると実感させ……</p><p><em>販売価格：</em> 2500 円 <font class="rakuten_time">(10/07/30 03:35 更新)</font></p><p><em>販売店舗：</em> <a href="http://www.rakuten.co.jp/book/" target="_blank">楽天ブックス</a></p></div><!-- cache -->');
		// -->
		</script>
		
		<script type="text/javascript"><!--
			show_rakuten('#hobbyist10060346', 'NotFound');
		// -->
		</script>
		
		<script type="text/javascript"><!--
			show_rakuten('#et-cn10012696', '<!-- cache --><div class="rakuten_image"><a href="http://hb.afl.rakuten.co.jp/hgc/0b16999f.c5b9c54b.0b1699a0.49a76732/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fet-cn%2Fp10-547%2F" target="_blank"><img src="http://thumbnail.image.rakuten.co.jp/@0_mall/et-cn/cabinet/s38/p10-547.jpg?_ex=128x128"><br /><p class="rakuten_logo"><!-- Rakuten Web Services Attribution Snippet FROM HERE --><a href="http://webservice.rakuten.co.jp/" target="_blank"><img src="http://webservice.rakuten.co.jp/img/credit/200709/credit_4936.gif" border="0" alt="楽天ウェブサービスセンター" title="楽天ウェブサービスセンター" width="49" height="36"/></a><!-- Rakuten Web Services Attribution Snippet TO HERE --></p><font class="rakuten_warn"><a href="#" class="tooltip">[ご利用にあたって]<span>このサイトで掲載されている情報は、「Go towards a Word-Progress」の作成者により運営されています。価格、販売可能情報は、変更される場合があります。購入時に楽天市場店舗（www.rakuten.co.jp）に表示されている価格が、その商品の販売に適用されます。</span></a></font></div><div class="rakuten_info"><p class="rakuten_itemname"><a href="http://hb.afl.rakuten.co.jp/hgc/0b16999f.c5b9c54b.0b1699a0.49a76732/?pc=http%3A%2F%2Fitem.rakuten.co.jp%2Fet-cn%2Fp10-547%2F" target="_blank">セガ/プライズ涼宮ハルヒの憂鬱EXフィギュア笹の葉ラプソディ全2種セット</a></p><p class="rakuten_caption">詳　細 2009年、改めて放送開始した“涼宮ハルヒの憂鬱”の新エピソードから待望の立体化。サブタイトル『笹の葉ラプソディ』に登場する中学生時代の涼宮ハルヒと大人の朝比奈みくるは、セガプライズのエクストラシリーズで初のラインナップです。・涼宮ハルヒ(東中)・朝比奈みくる(大)全2種セット◆その他の涼宮ハルヒの商品は　　　⇒　 こちらへ メーカー セガ サイズ ハルヒ:約15cm/みくる:約17cm その他 ・こちらの商品は未開封品になります。　　　　メーカー出荷時の商品パッケージにてお渡しいたします。　　＊……</p><p><em>販売価格：</em> 2625 円 <font class="rakuten_time">(10/07/30 03:35 更新)</font></p><p><em>販売店舗：</em> <a href="http://www.rakuten.co.jp/et-cn/" target="_blank">トレジャーカプセル楽天市場支店</a></p></div><!-- cache -->');
		// -->
		</script>
		<p><em><span style="color: #808080;">このブログでは、Scalaを当然の前提としている一方で、</span></em><span style="text-decoration: line-through;"><em><span style="color: #808080;">ハルヒ中学生バージョン</span></em></span><em><span style="color: #808080;">Scala入門を書く気はないので、罪滅ぼしまでに、各地のScala入門に勝手流追記していこうと思いたつ。</span></em><br />
<br/><strong><span style="text-decoration: underline;"> 提供</span></strong> 勝手にしやがれ.orz(違)<br />
<div id="book12166433" class="rakuten_details">Now Loading...</div></p>
<p><br/>Scalaへのとっかかりとして、<a href="http://www.unoh.net/mt32/mt-tb.cgi/1521">ウノウラボ内田氏のScala入門</a>が簡潔で良い。・・・が、５分で伝えるために、はしょりすぎ・誤記がちょっとだけ垣間見える :</p>
<h3 style="font-weight: bold; margin-top: 20px; margin-bottom: 10px; font-family: 'trebuchet ms', helvetica, arial, sans-serif; line-height: 1.5;">変数</h3>
<p>関数型的な「val」と手続き指向的な「var」</p>
<pre style="margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; background-color: #c8c8f8; white-space: pre-wrap; word-wrap: break-word; padding: 1ex; border: 1px solid #707b8d;">val i = 1
var i = 1
val i:String = "hello"
var i:String = "hello"</pre>
<h5>追記</h5>
<p>valは、再代入不可な変数(immutable)。varは代入可能な変数(mutable)。そのため、以下のようになる。:</p>
<pre style="margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; background-color: #f8f8f8; white-space: pre-wrap; word-wrap: break-word; padding: 1ex; border: 1px solid #707b8d;">scala&gt; val L = 1; var R =2
L: Int = 1
R: Int = 2

scala&gt; L += R
:7: error: reassignment to val
       L += R
         ^

scala&gt; R += L
scala&gt; R
res15: Int = 3</pre>
<p>再代入不可のvalが、actorをはじめとするscalaの並列処理ワールドを可能にする。</p>
<h3 style="font-weight: bold; margin-top: 20px; margin-bottom: 10px; font-family: 'trebuchet ms', helvetica, arial, sans-serif; line-height: 1.5;">制御構文</h3>
<p>10回ループしたかったら</p>
<pre style="margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; background-color: #c8c8f8; white-space: pre-wrap; word-wrap: break-word; padding: 1ex; border: 1px solid #707b8d;">for (n &lt;- 1 to 10) <span style="text-decoration: line-through;">yield </span>println(n)</pre>
<h5>解説</h5>
<p>yieldは、rubyなどと同様、値を返す。なので、以下のように書く :</p>
<pre style="margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; background-color: #f8f8f8; white-space: pre-wrap; word-wrap: break-word; padding: 1ex; border: 1px solid #707b8d;">
scala&gt; for (n &lt;- 1 to 10) println(n)
1
2
3
4
5
6
7
8
9
10

scala&gt; val x = for (n &lt;- 1 to 10) yield n * n
x: RandomAccessSeq.Projection[Int] = RangeM(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)</pre>
<div><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: small;"><span style="line-height: 18px; white-space: pre-wrap;"><br />
</span></span></div>
<p>最後のRangeMが気持ち悪い場合は、toListしよう :</p>
<pre style="margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; background-color: #f8f8f8; white-space: pre-wrap; word-wrap: break-word; padding: 1ex; border: 1px solid #707b8d;">scala&gt; x.toList
res17: List[Int] = List(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)</pre>
<p><div id="hobbyist10060346" class="rakuten_details">Now Loading...</div><br />
<div id="et-cn10012696" class="rakuten_details">Now Loading...</div></p>
]]></content:encoded>
			<wfw:commentRss>http://wordprogress.org/archives/238/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
