From ac05579345f9cd3f3ba0b6aed33a1883d24c2348 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 26 Sep 2008 11:15:14 -0700 Subject: [PATCH] 1) Fixed spec w/ respect to result types. 2) Added proposal for making "if" statements consistent with the other control structures. R=r DELTA=59 (32 added, 6 deleted, 21 changed) OCL=15583 CL=15964 --- doc/go_spec.txt | 74 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/doc/go_spec.txt b/doc/go_spec.txt index 753dc3a92e..45ce6eadd7 100644 --- a/doc/go_spec.txt +++ b/doc/go_spec.txt @@ -4,7 +4,7 @@ The Go Programming Language Specification (DRAFT) Robert Griesemer, Rob Pike, Ken Thompson ---- -(September 19, 2008) +(September 26, 2008) This document is a semi-formal specification of the Go systems @@ -19,8 +19,6 @@ Any part may change substantially as design progresses. Contents @@ -1098,30 +1102,39 @@ Function types ---- A function type denotes the set of all functions with the same parameter -list and result. +and result types. FunctionType = "(" [ ParameterList ] ")" [ Result ] . ParameterList = ParameterSection { "," ParameterSection } . - ParameterSection = IdentifierList Type . + ParameterSection = [ IdentifierList ] Type . Result = Type | "(" ParameterList ")" . -Functions can return multiple values simultaneously. +In ParameterList, the parameter names (IdentifierList) either must all be +present, or all be absent. If the parameters are named, each name stands +for one parameter of the specified type. If the parameters are unnamed, each +type stands for one parameter of that type. - // Function types () + (x int) () int - (s string) + (string) (a, b int, z float) bool + (a, b int, z float) (bool) (a, b int, z float) (success bool) - (a, b int, z float) (success bool, result float) + (int, int, float) (float, *[]int) A variable can hold only a pointer to a function, not a function value. In particular, v := func() {} creates a variable of type *(). To call the function referenced by v, one writes v(). It is illegal to dereference a function pointer. -TODO: For consistency, we should require the use of & to get the pointer to -a function: &func() {}. +Type equality: Two function types are equal if both have the same number +of parameters and result values and if corresponding parameter and result +types are equal. In particular, the parameter and result names are ignored +for the purpose of type equivalence. + +Assignment compatibility: A function pointer can be assigned to a function +(pointer) variable only if both function types are equal. Interface types @@ -1853,12 +1866,12 @@ In assignments, the type of the expression must match the type of the left-hand If statements ---- -If statements have the traditional form except that the -condition need not be parenthesized and the "then" statement -must be in brace brackets. The condition may be omitted, in which -case it is assumed to have the value "true". +If statements specify the conditional execution of two branches; the "if" +and the "else" branch. If Expression evaluates to true, +the "if" branch is executed. Otherwise the "else" branch is executed if present. +If Condition is omitted, it is equivalent to true. - IfStat = "if" [ [ Simplestat ] ";" ] [ Condition ] Block [ "else" Statement ] . + IfStat = "if" [ [ Simplestat ] ";" ] [ Expression ] Block [ "else" Statement ] . if x > 0 { return true; @@ -1877,13 +1890,26 @@ the variable is initialized once before the statement is entered. } -TODO: We should fix this and move to: + Switch statements ----