Default value:
def saymyname (name:string = "Jack") {println (name)}
Variable parameters:
def summoreparameters (elem:int*) = { var sum = 0for (e <-elem) {println (e) sum + = e} sum}
Use of underscores:
def add (a:int,b:int) = a+bdef add2 = Add (_:int,2)
Recursive functions: Need to explicitly give the return type of the function
def FAC (n:int): Int = if (n <= 0) 1 Else n*fac (n-1)
function currying:
Write this argument independently, this is currying
def mulitply (X:int) (y:int) = x*ydef m2 = mulitply (2) _;
Curry is the parameter can be separated, some of the function parameters can be underlined to replace
How anonymous functions are declared
Val t = () =>333
: followed by the data type, C for the passed in parameters
def TESTFUNC02 (c: () =>int) { println (c ()) 1000}
anonymous functions
Val D1 = (a:int) = = a+100;
The anonymous function as a parameter is actually the parameter name, followed by the argument type, then the expression
Def TESTF1 (callback: (Int,int) =>int) ={ println (Callback (123,123));}
Nested function, in fact, is a def inside a set of Def
def add3 (X:int, Y:int, z:int): int = {def add2 (X:int, y:int): int = {x + y}add2 (add2 (x, y), Z)}
def sum (f:int = int): (int, int) + int = { def sumf (A:int, b:int): int = if (a >b) 0 else F ( A) + SUMF (A + 1, b) SUMF}
Scala Learning note 4--scala's function one