This is a creation in Article, where the information may have evolved or changed.
Functions in the Go language
Finally the turn function, actually also has nothing to say, is nothing but a grammar problem, C language has C language syntax, C # has C # syntax, then the function of Go language? In the previous article
In fact, we have seen some simple functions, and today we will look at the details, so please look at the following:
In the above code, we declare and define a total of two functions, one is say, the other is an anonymous function, and here, through the anonymous function, a function closure is generated. In the Go language
Declare a function with the Func keyword. So, if you want to declare a function, immediately think of Func, whether it's anonymous or not, the only difference is that there is no function name behind the anonymous function, directly
Func (parameter list) (return value). As we can see from the above, the return type of the Go language function is followed by the function name, and it is the same as the type that declares the variable, which is also different from most languages. And the return value of a function can be one or more. For example, the say function above, we return two, an integer type, an error. Where the integer type is the length of the variable parameter, the error type is one of the values returned from the printf function in the FMT package, and we see that the FMT is accepted. The first variable of the value returned by the Printf () function We use the "_" symbol, which means that we do not care about the first return value and ignore it. Then look at the second parameter of the Say function, is a ... interface{} type, three points is a type of go language slices, similar to an array, but different, this will continue to be described in subsequent articles, since it is a similar array of types, It can also be thought that a mutable parameter can receive any number, but must be of the same type, where an empty interface type is used as the element type of the slices, which allows the element to receive any type of argument, and then the actual type of each element can be inferred by default parameters.
- author: Sirk
- source: http:// Www.cnblogs.com/vimsk
-
-
|