<?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>格物致知 &#187; Scala</title>
	<atom:link href="http://leeing.org/category/programming-language/scala/feed/" rel="self" type="application/rss+xml" />
	<link>http://leeing.org</link>
	<description>keep Thinking</description>
	<lastBuildDate>Fri, 04 Nov 2011 16:20:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Scala: 方法名约定</title>
		<link>http://leeing.org/2010/08/07/scala-method-name-convention/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/08/07/scala-method-name-convention/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 15:03:47 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=651</guid>
		<description><![CDATA[Scala中没有操作符但是支持运算符重载，方法的最后一个字符也对优先级有影响，它决定了方法调用的目标。 Scala的这个约定在熟悉之后你会发现它提高了流畅性，例如，如果想要将一个值添加到一list中，可以写作：value::list，尽管可以读为：“value被附加到list上”，这个方法的目标实际上list而参数是value，也就是说list.::(value)。 如果方法名以冒号结尾，那调用目标是操作符后面的实例，在下一个例子中，^() 是一个定义在类Cow中的方法，而 ^:() 是一个定义在Moon中的方法： class Cow { def ^(moon: Moon) = println("Cow jumped over the moon") } class Moon { def ^:(cow: Cow) = println("This cow jumped over the moon too") } 调用如下： val cow = new Cow val moon = new Moon cow ^ moon cow ^: moon 这两种调用方式看起来基本是相同的，cow在左而moon在右，但前一个调用是在cow上而后一个则是在moon上，这种区别对于新手来说可能很奇怪，但它在列表操作中是很平常的，所以最好熟悉这种写法，前面代码的输出是： Cow jumped over [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/26/scala-operator-override/' rel='bookmark' title='Permanent Link: Scala : &#8220;运算符&#8221; 重载'>Scala : &#8220;运算符&#8221; 重载</a></li>
<li><a href='http://leeing.org/2010/04/18/scala-option-and-foldleft/' rel='bookmark' title='Permanent Link: Scala : Option 和 foldLeft'>Scala : Option 和 foldLeft</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/08/07/scala-method-name-convention/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scala : &#8220;运算符&#8221; 重载</title>
		<link>http://leeing.org/2010/04/26/scala-operator-override/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/04/26/scala-operator-override/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 15:45:46 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=529</guid>
		<description><![CDATA[运算符带了双引号，这是因为从技术上来说，Scala 并没有所谓的“运算符”,在这里是指重载符号,如+ ,+- 等等。 在 Scala 中,事实上这些是方法的名字。但是由于 Scala 并不需要点来分隔对象引用和方法名,因而看起来像是运算符。调用 ref1+ref2 其实与 ref1.+(ref2)是等同的,调用的其实是 ref1 的+()方法。 举例如下: class Complex(val real: Int, val imaginary: Int) { def +(operand: Complex) : Complex = { new Complex(real + operand.real, imaginary + operand.imaginary) } override def toString() : String = { real + (if (imaginary &#60; 0) "" else "+") + [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/20/scala-functions-and-parameters/' rel='bookmark' title='Permanent Link: Scala : Functions and Parameters'>Scala : Functions and Parameters</a></li>
<li><a href='http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/' rel='bookmark' title='Permanent Link: Scala : Partial Functions 和 Type Parameters'>Scala : Partial Functions 和 Type Parameters</a></li>
<li><a href='http://leeing.org/2010/04/25/scala-variables-in-scope-containers/' rel='bookmark' title='Permanent Link: Scala : 作用域中的变量，容器'>Scala : 作用域中的变量，容器</a></li>
<li><a href='http://leeing.org/2010/04/18/scala-option-and-foldleft/' rel='bookmark' title='Permanent Link: Scala : Option 和 foldLeft'>Scala : Option 和 foldLeft</a></li>
<li><a href='http://leeing.org/2010/04/26/scala-interactive-application-and-functional-composition/' rel='bookmark' title='Permanent Link: Scala : 交互式应用程序，函数组合'>Scala : 交互式应用程序，函数组合</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/04/26/scala-operator-override/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala : 交互式应用程序，函数组合</title>
		<link>http://leeing.org/2010/04/26/scala-interactive-application-and-functional-composition/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/04/26/scala-interactive-application-and-functional-composition/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 06:25:32 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=523</guid>
		<description><![CDATA[函数和交互式应用程序 回调（callback）在交互式应用程序中是很常见的。例如一个按钮被点击，并进行一个特定的动作。在Web 应用程序中创建回调是尤其困难的，除非你拥有像Scala这样强大的工具。下面创建一个方法，它生成一个随机的String，以作为一个全局唯一的标识符（GUID）。 scala&#62; def randomName() = "I"+ scala.util.Random.nextLong.abs randomName: ()java.lang.String 然后定义一个通用的JavaScript trait, 我们不需要刷新它，假设它包含可以在浏览器中运行的JavaScript 命令。 scala&#62; trait JavaScript defined trait JavaScript 下面用一个能生成 JavaScript的函数来创建一个Map 以关联GUID： scala&#62; var callbacks: Map[String, () =&#62; JavaScript] = Map() callbacks: Map[String,() =&#62; JavaScript] = Map() scala&#62; def register(f: () =&#62; JavaScript) = { &#124; val name = randomName &#124; callbacks += [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/19/scala-collection-list/' rel='bookmark' title='Permanent Link: Scala 集合框架：List'>Scala 集合框架：List</a></li>
<li><a href='http://leeing.org/2010/04/18/scala-option-and-foldleft/' rel='bookmark' title='Permanent Link: Scala : Option 和 foldLeft'>Scala : Option 和 foldLeft</a></li>
<li><a href='http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/' rel='bookmark' title='Permanent Link: Scala : Partial Functions 和 Type Parameters'>Scala : Partial Functions 和 Type Parameters</a></li>
<li><a href='http://leeing.org/2010/04/20/scala-functions-and-parameters/' rel='bookmark' title='Permanent Link: Scala : Functions and Parameters'>Scala : Functions and Parameters</a></li>
<li><a href='http://leeing.org/2010/04/25/scala-variables-in-scope-containers/' rel='bookmark' title='Permanent Link: Scala : 作用域中的变量，容器'>Scala : 作用域中的变量，容器</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/04/26/scala-interactive-application-and-functional-composition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala : 作用域中的变量，容器</title>
		<link>http://leeing.org/2010/04/25/scala-variables-in-scope-containers/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/04/25/scala-variables-in-scope-containers/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 08:50:30 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=521</guid>
		<description><![CDATA[Functions Bound to Variables in Scope 函数被绑定到创建函数时所在的作用域内中的变量，这样就允许承载状态，例如首先声明一个名为 foo 的变量： scala&#62; val foo = "dog" foo: java.lang.String = dog 下面创建一个引用了这个变量的函数： scala&#62; val whoTo = (s: String) =&#62; s+" "+foo whoTo: (String) =&#62; java.lang.String = &#60;function1&#62; 调用这个函数： scala&#62; whoTo("I love my") res0: java.lang.String = I love my dog scala&#62; whoTo("I walk my") res1: java.lang.String = I walk [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/20/scala-functions-and-parameters/' rel='bookmark' title='Permanent Link: Scala : Functions and Parameters'>Scala : Functions and Parameters</a></li>
<li><a href='http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/' rel='bookmark' title='Permanent Link: Scala : Partial Functions 和 Type Parameters'>Scala : Partial Functions 和 Type Parameters</a></li>
<li><a href='http://leeing.org/2010/04/19/scala-collection-tuple-map-option/' rel='bookmark' title='Permanent Link: Scala 集合框架：Tuple,Map[K,V],Option[T]'>Scala 集合框架：Tuple,Map[K,V],Option[T]</a></li>
<li><a href='http://leeing.org/2010/04/19/scala-collection-list/' rel='bookmark' title='Permanent Link: Scala 集合框架：List'>Scala 集合框架：List</a></li>
<li><a href='http://leeing.org/2010/04/26/scala-interactive-application-and-functional-composition/' rel='bookmark' title='Permanent Link: Scala : 交互式应用程序，函数组合'>Scala : 交互式应用程序，函数组合</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/04/25/scala-variables-in-scope-containers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala : Partial Functions 和 Type Parameters</title>
		<link>http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 08:56:55 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=516</guid>
		<description><![CDATA[方法和函数是不同的，在Scala中，除了方法以外，一切都是一个实例。方法被附加到实例之上，并且被实例所调用。Function是实现了 FunctionNN trait (NN是指参数的个数，在 Scala 2.8 的文档中可知，NN 的取值范围是 1～22）的实例。在运行时函数没有什么特别的地方，但在编译阶段，有一些方式可以让编写一个函数使用很少的代码。 Partial Functions Partial function 是只有部份参数被 apply 的函数，在Scala中，可以从方法中来构建 partially applied function: scala&#62; def plus(a: Int, b: Int) = "Result is: "+(a + b) plus: (a: Int,b: Int)java.lang.String scala&#62; val p = (b: Int) =&#62; plus(42, b) p: (Int) =&#62; java.lang.String = partial function 允许你基于已有的方法或函数来构建新的函数，参数可以用不同的括号来分组： scala&#62; def add(a: [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/20/scala-functions-and-parameters/' rel='bookmark' title='Permanent Link: Scala : Functions and Parameters'>Scala : Functions and Parameters</a></li>
<li><a href='http://leeing.org/2010/04/25/scala-variables-in-scope-containers/' rel='bookmark' title='Permanent Link: Scala : 作用域中的变量，容器'>Scala : 作用域中的变量，容器</a></li>
<li><a href='http://leeing.org/2010/04/19/scala-collection-tuple-map-option/' rel='bookmark' title='Permanent Link: Scala 集合框架：Tuple,Map[K,V],Option[T]'>Scala 集合框架：Tuple,Map[K,V],Option[T]</a></li>
<li><a href='http://leeing.org/2010/04/19/scala-collection-list/' rel='bookmark' title='Permanent Link: Scala 集合框架：List'>Scala 集合框架：List</a></li>
<li><a href='http://leeing.org/2010/04/26/scala-interactive-application-and-functional-composition/' rel='bookmark' title='Permanent Link: Scala : 交互式应用程序，函数组合'>Scala : 交互式应用程序，函数组合</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala : Functions and Parameters</title>
		<link>http://leeing.org/2010/04/20/scala-functions-and-parameters/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/04/20/scala-functions-and-parameters/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 12:51:13 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=508</guid>
		<description><![CDATA[一个Function 是一个实例 在scala中，function是类的实例，所以在一个function上进行和类的实例一样的操作，下面创建了一个function并将它赋值给一个变量： scala&#62; val f:Int =&#62; String = x =&#62; "Dude: "+x f: (Int) =&#62; String = &#60;function1&#62; 实际上它相当于： scala&#62; val f:(Int =&#62; String) = { x=&#62; "Dude :" +x } f: (Int) =&#62; String = &#60;function1&#62; 可以在 f上调用方法： scala&#62; f.toString res0: java.lang.String = &#60;function1&#62; scala&#62; f == f res1: Boolean = true scala&#62; [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/' rel='bookmark' title='Permanent Link: Scala : Partial Functions 和 Type Parameters'>Scala : Partial Functions 和 Type Parameters</a></li>
<li><a href='http://leeing.org/2010/04/25/scala-variables-in-scope-containers/' rel='bookmark' title='Permanent Link: Scala : 作用域中的变量，容器'>Scala : 作用域中的变量，容器</a></li>
<li><a href='http://leeing.org/2010/04/19/scala-collection-tuple-map-option/' rel='bookmark' title='Permanent Link: Scala 集合框架：Tuple,Map[K,V],Option[T]'>Scala 集合框架：Tuple,Map[K,V],Option[T]</a></li>
<li><a href='http://leeing.org/2010/04/19/scala-collection-list/' rel='bookmark' title='Permanent Link: Scala 集合框架：List'>Scala 集合框架：List</a></li>
<li><a href='http://leeing.org/2010/04/26/scala-interactive-application-and-functional-composition/' rel='bookmark' title='Permanent Link: Scala : 交互式应用程序，函数组合'>Scala : 交互式应用程序，函数组合</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/04/20/scala-functions-and-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala 集合框架：Tuple,Map[K,V],Option[T]</title>
		<link>http://leeing.org/2010/04/19/scala-collection-tuple-map-option/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/04/19/scala-collection-tuple-map-option/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 13:37:37 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=502</guid>
		<description><![CDATA[Tuple Tuple 能让一个方法返回两个或三个值，例如下面的代码输入一个 List[Double]，返回元素个数，元素的和及其平方和： def sumSq(in: List[Double]): (Int, Double, Double) = in.foldLeft((0, 0d, 0d))((t, v) =&#62; (t._1 + 1, t._2 + v, t._3 + v * v)) 这里，编译器会将在括号中的集合元素看作是一个Tuple，上面的代码会翻译成：Tuple3[Int,Double,Double]，这个函数接收两个参数：t和 v，t是一个Tuple3，而v是一个Double。 使用模式匹配可以让上面的代码更易理解： def sumSq(in: List[Double]) : (Int, Double, Double) = in.foldLeft((0, 0d, 0d)){ case ((cnt, sum, sq), v) =&#62; (cnt + 1, sum + v, sq + [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/19/scala-collection-list/' rel='bookmark' title='Permanent Link: Scala 集合框架：List'>Scala 集合框架：List</a></li>
<li><a href='http://leeing.org/2010/04/25/scala-variables-in-scope-containers/' rel='bookmark' title='Permanent Link: Scala : 作用域中的变量，容器'>Scala : 作用域中的变量，容器</a></li>
<li><a href='http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/' rel='bookmark' title='Permanent Link: Scala : Partial Functions 和 Type Parameters'>Scala : Partial Functions 和 Type Parameters</a></li>
<li><a href='http://leeing.org/2010/04/18/scala-option-and-foldleft/' rel='bookmark' title='Permanent Link: Scala : Option 和 foldLeft'>Scala : Option 和 foldLeft</a></li>
<li><a href='http://leeing.org/2010/04/20/scala-functions-and-parameters/' rel='bookmark' title='Permanent Link: Scala : Functions and Parameters'>Scala : Functions and Parameters</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/04/19/scala-collection-tuple-map-option/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala 集合框架：List</title>
		<link>http://leeing.org/2010/04/19/scala-collection-list/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/04/19/scala-collection-list/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 06:38:28 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=493</guid>
		<description><![CDATA[本文的示例代码来自 &#60;Beginning Scala&#62; ，由于Scala中的集合框架已经重写， 这里的代码输出都是在 Scala 2.8.0RC1 下运行得出的，跟原书中有一定的差距。 1. Range collections 可以拥有任意数量的元素，或者局限于零个或一个元素（如 Option )，Collections 可以是strict 或是 lazy 的。Lazy Collection 可以拥有不消耗内存的元素，直到它们被访问。例如一个 Range 类： scala&#62; 0 until 10 by 3 res7: scala.collection.immutable.Range = Range(0, 3, 6, 9) 在这里，Range 中的元素在被访问之前并不会被实例化，下面代码只访问了前5个元素： scala&#62; (1 to Integer.MAX_VALUE - 1).take(5) res8: scala.collection.immutable.Range = Range(1, 2, 3, 4, 5) 这个例子中不会消耗很多内存，因为只有需要的元素才被创建。 2. 构造一个列表 Collection [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/19/scala-collection-tuple-map-option/' rel='bookmark' title='Permanent Link: Scala 集合框架：Tuple,Map[K,V],Option[T]'>Scala 集合框架：Tuple,Map[K,V],Option[T]</a></li>
<li><a href='http://leeing.org/2010/04/20/scala-functions-and-parameters/' rel='bookmark' title='Permanent Link: Scala : Functions and Parameters'>Scala : Functions and Parameters</a></li>
<li><a href='http://leeing.org/2010/04/26/scala-interactive-application-and-functional-composition/' rel='bookmark' title='Permanent Link: Scala : 交互式应用程序，函数组合'>Scala : 交互式应用程序，函数组合</a></li>
<li><a href='http://leeing.org/2010/01/27/programming-scala-notes-1scala-features/' rel='bookmark' title='Permanent Link: 《Programming Scala》：Scala 的特性'>《Programming Scala》：Scala 的特性</a></li>
<li><a href='http://leeing.org/2010/04/25/scala-variables-in-scope-containers/' rel='bookmark' title='Permanent Link: Scala : 作用域中的变量，容器'>Scala : 作用域中的变量，容器</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/04/19/scala-collection-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala : Option 和 foldLeft</title>
		<link>http://leeing.org/2010/04/18/scala-option-and-foldleft/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/04/18/scala-option-and-foldleft/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 08:49:54 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=479</guid>
		<description><![CDATA[下面这段代码来自Beginning Scala，它的主要功能是读取输入的字符串，把其中的数字字符串转为整数，并相加求和，很简单的一段代码，但包含了很多語法细节。 import scala.io._ def toInt(in: String): Option[Int] = try { Some(Integer.parseInt(in.trim)) } catch { case e: NumberFormatException =&#62; None } def sum(in: Seq[String]) = { val ints = in.flatMap(s =&#62; toInt(s)) ints.foldLeft(0)((a, b) =&#62; a + b) } val lines = Seq("1","2","3","str") println("Sum is :"+sum(lines)) 在这里，首先看 Option[Int]，Option是一个很有趣的容器，它只包含零个或一个元素，如果是零个元素，则类型为 None，None 是一个 singleton ; 如果拥有一个元素，则类型为 Some( theElement)，Option的一个重要作用是避免了空指针异常和显式的null [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/19/scala-collection-tuple-map-option/' rel='bookmark' title='Permanent Link: Scala 集合框架：Tuple,Map[K,V],Option[T]'>Scala 集合框架：Tuple,Map[K,V],Option[T]</a></li>
<li><a href='http://leeing.org/2010/04/20/scala-functions-and-parameters/' rel='bookmark' title='Permanent Link: Scala : Functions and Parameters'>Scala : Functions and Parameters</a></li>
<li><a href='http://leeing.org/2010/04/19/scala-collection-list/' rel='bookmark' title='Permanent Link: Scala 集合框架：List'>Scala 集合框架：List</a></li>
<li><a href='http://leeing.org/2010/01/27/programming-scala-notes-1scala-features/' rel='bookmark' title='Permanent Link: 《Programming Scala》：Scala 的特性'>《Programming Scala》：Scala 的特性</a></li>
<li><a href='http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/' rel='bookmark' title='Permanent Link: Scala : Partial Functions 和 Type Parameters'>Scala : Partial Functions 和 Type Parameters</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/04/18/scala-option-and-foldleft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>《Programming Scala》：Scala 的特性</title>
		<link>http://leeing.org/2010/01/27/programming-scala-notes-1scala-features/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://leeing.org/2010/01/27/programming-scala-notes-1scala-features/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 09:11:49 +0000</pubDate>
		<dc:creator>leeing</dc:creator>
				<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://leeing.org/?p=240</guid>
		<description><![CDATA[本文是《Programming Scala》第一章的笔记，Scala 是一门很有趣也很简练的语言。 Scala为并行，简洁，可伸缩性而设计，它是一种函数式和面向对象的混合式语言，提供了基于actor的消息传递模型以去除并行带来的复杂性。使用这个模型，可以编写简洁的多线程代码(synchoroize关键字可以从词汇中消除了)，而不用担心线程之间的数据连接以及处理锁和释放所带来的问题。 然而Scala也能用来编写单线程的应用程序，或者作为多线程应用的单线程模块，它的函数式风格有利于单线程和多线程的应用。Scala的并行模型与Erlang的风格很相似，但Scala的优点是：它是强类型而Erlang是弱类型，能在JVM上运行，与Java很好的进行交互。 下图展示了Scala在企业应用中适合的地方： 注意到，可以将Java代码包装在Scala的actor库中提供线程的隔离，如果要在线程之间通讯，则使用Scala轻量级API来传递信息。在Scala中不用在创建线程时马上用同步来限制其并行，而是在不使用锁的情况下进行真正的并行操作，这就能更关注应用逻辑而不是低层次的线程。 Scala是静态类型的，但与Java 不同的是，不必明确反复地指定类型，很多情况下编译器可以进行类型推断，这一特性在简化函数的参数和返回值时很有用。 Scala的内核是很小的，其它包含操作符，Actor，都仅仅只是Scala库的一部份，可扩展性是极强，完全可以自行写一个实现。函数式编程是一种声明式的风格，在这种风格中指明的是“做什么”而不是“应该怎样做”，在XSLT，规则引擎，或者ANTLR中使用的就是函数式风格。 在一个数组中寻找最大值的函数式编程如下： def findMax(temperatures : List[Int]) = { temperatures.foldLeft(Integer.MIN_VALUE) { Math.max } } 将列表中的每个元素乘以2： val values = List(1, 2, 3, 4, 5) val doubleValues = values.map( _ * 2) 计算一个数的阶乘： def fact(n: Int) = 1 to n reduceLeft (_*_) 从网络获取股票的收盘价并找出最大值： import scala.actors._ import Actor._ val symbols [...]


Related posts:<ol><li><a href='http://leeing.org/2010/04/25/scala-variables-in-scope-containers/' rel='bookmark' title='Permanent Link: Scala : 作用域中的变量，容器'>Scala : 作用域中的变量，容器</a></li>
<li><a href='http://leeing.org/2010/04/21/scala-partial-functions-and-type-parameters/' rel='bookmark' title='Permanent Link: Scala : Partial Functions 和 Type Parameters'>Scala : Partial Functions 和 Type Parameters</a></li>
<li><a href='http://leeing.org/2010/04/20/scala-functions-and-parameters/' rel='bookmark' title='Permanent Link: Scala : Functions and Parameters'>Scala : Functions and Parameters</a></li>
<li><a href='http://leeing.org/2010/04/19/scala-collection-tuple-map-option/' rel='bookmark' title='Permanent Link: Scala 集合框架：Tuple,Map[K,V],Option[T]'>Scala 集合框架：Tuple,Map[K,V],Option[T]</a></li>
<li><a href='http://leeing.org/2010/04/18/scala-option-and-foldleft/' rel='bookmark' title='Permanent Link: Scala : Option 和 foldLeft'>Scala : Option 和 foldLeft</a></li>
</ol>]]></description>
		<wfw:commentRss>http://leeing.org/2010/01/27/programming-scala-notes-1scala-features/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

