Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>scala
Welcome to Scala version 2.10.6 (Java HotSpot(TM) Client VM, Java 1.7.0_72).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
scala>
scala>
scala>
scala>
scala> def m(x:Int) =x *x
m: (x: Int)Int
scala> m
<console>:9: error: missing arguments for method m;
follow this method with `_' if you want to treat it as a partially applied function
m
^
scala> m(2)
res1: Int = 4
scala> (x)=>x
<console>:8: error: missing parameter type
(x)=>x
^
scala> (x:Int)=>x
res3: Int => Int = <function1>
scala> res3(5)
res4: Int = 5
scala> s(x:Int)=>x
<console>:1: error: not a legal formal parameter
s(x:Int)=>x
^
scala> ms(x:Int)=>x
<console>:1: error: not a legal formal parameter
ms(x:Int)=>x
^
scala> ms (x:Int)=>x
<console>:1: error: not a legal formal parameter
ms (x:Int)=>x
^
scala> ms (x:Int) => x
<console>:1: error: not a legal formal parameter
ms (x:Int) => x
^
scala> md (x:Int) => x
<console>:1: error: not a legal formal parameter
md (x:Int) => x
^
scala> md (x:Int) => x
<console>:1: error: not a legal formal parameter
md (x:Int) => x
^
scala> md (x:Int) => x*x
<console>:1: error: not a legal formal parameter
md (x:Int) => x*x
^
scala> md (x:Int) => x * x
<console>:1: error: not a legal formal parameter
md (x:Int) => x * x
^
scala> md(x:Int) => x*x
<console>:1: error: not a legal formal parameter
md(x:Int) => x*x
^
scala> val md = (x:Int) => x*x
md: Int => Int = <function1>
scala> md(5)
res5: Int = 25
scala> md(55)
res6: Int = 3025
scala> arr.map(md)
<console>:9: error: not found: value arr
arr.map(md)
^
scala> arr.map(md)
<console>:9: error: not found: value arr
arr.map(md)
^
scala> val arr = Array(1,2)
arr: Array[Int] = Array(1, 2)
scala> arr.map(md(3))
<console>:10: error: type mismatch;
found : Int
required: Int => ?
arr.map(md(3))
^
scala> arr.map(md)
res10: Array[Int] = Array(1, 4)
scala> arr.filter(_ % 2==0)
res11: Array[Int] = Array(2)
scala> arr.filter(_ % 2==0).map(_*5)
res12: Array[Int] = Array(10)
scala>
(c) 2016 Microsoft Corporation。保留所有权利。
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>
C:\Users\Lenovo>scala
Welcome to Scala version 2.10.6 (Java HotSpot(TM) Client VM, Java 1.7.0_72).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
scala>
scala>
scala>
scala>
scala> def m(x:Int) =x *x
m: (x: Int)Int
scala> m
<console>:9: error: missing arguments for method m;
follow this method with `_' if you want to treat it as a partially applied function
m
^
scala> m(2)
res1: Int = 4
scala> (x)=>x
<console>:8: error: missing parameter type
(x)=>x
^
scala> (x:Int)=>x
res3: Int => Int = <function1>
scala> res3(5)
res4: Int = 5
scala> s(x:Int)=>x
<console>:1: error: not a legal formal parameter
s(x:Int)=>x
^
scala> ms(x:Int)=>x
<console>:1: error: not a legal formal parameter
ms(x:Int)=>x
^
scala> ms (x:Int)=>x
<console>:1: error: not a legal formal parameter
ms (x:Int)=>x
^
scala> ms (x:Int) => x
<console>:1: error: not a legal formal parameter
ms (x:Int) => x
^
scala> md (x:Int) => x
<console>:1: error: not a legal formal parameter
md (x:Int) => x
^
scala> md (x:Int) => x
<console>:1: error: not a legal formal parameter
md (x:Int) => x
^
scala> md (x:Int) => x*x
<console>:1: error: not a legal formal parameter
md (x:Int) => x*x
^
scala> md (x:Int) => x * x
<console>:1: error: not a legal formal parameter
md (x:Int) => x * x
^
scala> md(x:Int) => x*x
<console>:1: error: not a legal formal parameter
md(x:Int) => x*x
^
scala> val md = (x:Int) => x*x
md: Int => Int = <function1>
scala> md(5)
res5: Int = 25
scala> md(55)
res6: Int = 3025
scala> arr.map(md)
<console>:9: error: not found: value arr
arr.map(md)
^
scala> arr.map(md)
<console>:9: error: not found: value arr
arr.map(md)
^
scala> val arr = Array(1,2)
arr: Array[Int] = Array(1, 2)
scala> arr.map(md(3))
<console>:10: error: type mismatch;
found : Int
required: Int => ?
arr.map(md(3))
^
scala> arr.map(md)
res10: Array[Int] = Array(1, 4)
scala> arr.filter(_ % 2==0)
res11: Array[Int] = Array(2)
scala> arr.filter(_ % 2==0).map(_*5)
res12: Array[Int] = Array(10)
scala>