diff --git a/doc/go_spec.html b/doc/go_spec.html index 3823876457..cd46744b9c 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -900,7 +900,7 @@ Signature = Parameters [ Result ] . Result = Parameters | Type . Parameters = "(" [ ParameterList [ "," ] ] ")" . ParameterList = ParameterDecl { "," ParameterDecl } . -ParameterDecl = [ IdentifierList ] ( Type | "..." ) . +ParameterDecl = [ IdentifierList ] ( Type | "..." [ Type ] ) .

@@ -913,9 +913,12 @@ one unnamed result it may written as an unparenthesized type.

For the last parameter only, instead of a type one may write -... to indicate that the function may be invoked with -zero or more additional arguments of any -type. +... or ... T to indicate that the function +may be invoked with zero or more additional arguments. If the type +T is present in the parameter declaration, the additional +arguments must all be +assignment compatible +with type T; otherwise they may be of any type.

@@ -923,6 +926,7 @@ func()
 func(x int)
 func() int
 func(string, float, ...)
+func(prefix string, values ... int)
 func(a, b int, z float) bool
 func(a, b int, z float) (bool)
 func(a, b int, z float, opt ...) (success bool)
@@ -1189,7 +1193,9 @@ identical types. In detail:
 
 	
  • Two function types are identical if they have the same number of parameters and result values and if corresponding parameter and result types are - identical. All "..." parameters are defined to have identical type. + identical. All "..." parameters without a specified type are defined to have + identical type. All "..." parameters with specified identical type + T are defined to have identical type. Parameter and result names are not required to match.
  • Two interface types are identical if they have the same set of methods @@ -2596,15 +2602,15 @@ parameter.

    -Within f, the ... parameter has static -type interface{} (the empty interface). For each call, -its dynamic type is a structure whose sequential fields are the -trailing arguments of the call. That is, the actual arguments -provided for a ... parameter are wrapped into a struct -that is passed to the function instead of the actual arguments. -Using the reflection interface, f may -unpack the elements of the dynamic type to recover the actual -arguments. +Within f, a ... parameter with no +specified type has static type interface{} (the empty +interface). For each call, its dynamic type is a structure whose +sequential fields are the trailing arguments of the call. That is, +the actual arguments provided for a ... parameter are +wrapped into a struct that is passed to the function instead of the +actual arguments. Using the reflection +interface, f may unpack the elements of the dynamic +type to recover the actual arguments.

    @@ -2621,12 +2627,40 @@ call will be, schematically, struct { string; int }.

    +

    +If the final parameter of f has type ... T, +within the function it is equivalent to a parameter of type +[]T. At each call of f, the actual +arguments provided for the ... T parameter are placed +into a new slice of type []T whose successive elements are +the actual arguments. The length of the slice is therefore the +number of arguments bound to the ... T parameter and +may differ for each call site. +

    -As a special case, if a function passes its own ... parameter as the argument -for a ... in a call to another function with a ... parameter, +Given the function and call +

    +
    +func Greeting(prefix string, who ... string)
    +Greeting("hello:", "Joe", "Anna", "Eileen")
    +
    + +

    +Within Greeting, who will have value +[]string{"Joe", "Anna", "Eileen") +

    + + +

    +As a special case, if a function passes its own ... parameter, +with or without specified type, as the argument +for a ... in a call to another function with a ... parameter +of identical type, the parameter is not wrapped again but passed directly. In short, a formal ... -parameter is passed unchanged as an actual ... parameter. +parameter is passed unchanged as an actual ... parameter provided the +types match. +

    Operators