From 956259234299da69d3a7168fd17e96be3c7272e1 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sat, 12 Jun 2010 11:37:13 -0700 Subject: [PATCH] spec: remove ... (keeping ...T) R=gri, iant, ken2, r, r2 CC=golang-dev https://golang.org/cl/1632041 --- doc/go_spec.html | 81 +++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 60 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index e2637d96cd..589d90458f 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -986,7 +986,7 @@ Signature = Parameters [ Result ] . Result = Parameters | Type . Parameters = "(" [ ParameterList [ "," ] ] ")" . ParameterList = ParameterDecl { "," ParameterDecl } . -ParameterDecl = [ IdentifierList ] ( Type | "..." [ Type ] ) . +ParameterDecl = [ IdentifierList ] [ "..." ] Type .

@@ -998,23 +998,22 @@ lists are always parenthesized except that if there is exactly one unnamed result it may written as an unparenthesized type.

-For the last parameter only, instead of a type one may write -... 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 assignable -to T; otherwise they may be of any type. +If the function's last parameter has a type prefixed with ..., +the function may be invoked with zero or more arguments for that parameter, +each of which must be assignable +to the type that follows the .... +Such a function is called variadic. +

 func()
 func(x int)
 func() int
-func(string, float, ...)
-func(prefix string, values ... int)
+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)
+func(a, b int, z float, opt ...interface{}) (success bool)
 func(int, int, float) (float, *[]int)
 func(n int) func(p *T)
 
@@ -1271,10 +1270,8 @@ literal structure and corresponding components have identical types. In detail:
  • Two pointer types are identical if they have identical base types.
  • 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 without a specified type are defined to have - identical type. All "..." parameters with specified identical type - T are defined to have identical type. + and result values, corresponding parameter and result types are + identical, and either both functions are variadic or neither is. Parameter and result names are not required to match.
  • Two interface types are identical if they have the same set of methods @@ -2602,48 +2599,13 @@ There is no distinct method type and there are no method literals.

    Passing arguments to ... parameters

    -When a function f has a ... parameter, -it is always the last formal parameter. Within calls to f, -the arguments before the ... are treated normally. -After those, an arbitrary number (including zero) of trailing -arguments may appear in the call and are bound to the ... -parameter. -

    - -

    -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. -

    - -

    -Given the function and call -

    -
    -func Fprintf(f io.Writer, format string, args ...)
    -Fprintf(os.Stdout, "%s %d", "hello", 23)
    -
    - -

    -Within Fprintf, the dynamic type of args for this -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 +If f is variadic with final parameter type ...T, +then within the function the argument is equivalent to a parameter of type +[]T. At each call of f, the argument +passed to the final parameter is +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 +number of arguments bound to the final parameter and may differ for each call site.

    @@ -2662,11 +2624,10 @@ Within Greeting, who will have value

    -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 ... +As a special case, if a function passes its own ... parameter +as the ... argument in a call to another function with +a ... parameter of identical type, +the parameter is passed directly. In short, a formal ... parameter is passed unchanged as an actual ... parameter provided the types match.

    -- 2.48.1