mirror of
https://github.com/golang/go
synced 2024-11-22 00:04:41 -07:00
- Added section on type equivalence
- Changed signature syntax: parameter names are always mandatory - Minor white-space cosmetic changes SVN=117240
This commit is contained in:
parent
c1aba41194
commit
50cea7038b
@ -1,6 +1,6 @@
|
|||||||
The Go Programming Language
|
The Go Programming Language
|
||||||
----
|
----
|
||||||
(April 18, 2008)
|
(April 29, 2008)
|
||||||
|
|
||||||
This document is an informal specification/proposal for a new systems programming
|
This document is an informal specification/proposal for a new systems programming
|
||||||
language.
|
language.
|
||||||
@ -365,6 +365,7 @@ point value that is constrained only upon assignment.
|
|||||||
-44
|
-44
|
||||||
+3.24e-7
|
+3.24e-7
|
||||||
|
|
||||||
|
|
||||||
The string type
|
The string type
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -501,6 +502,7 @@ an error if placed in a character literal (it is not a single code
|
|||||||
point), and will appear as two code points if placed in a string
|
point), and will appear as two code points if placed in a string
|
||||||
literal.
|
literal.
|
||||||
|
|
||||||
|
|
||||||
More about types
|
More about types
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -601,6 +603,7 @@ structure.
|
|||||||
f func();
|
f func();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Compound Literals
|
Compound Literals
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -623,6 +626,7 @@ be of the same type, which is the element type of the resulting array.
|
|||||||
|
|
||||||
Unresolved issues: Are elements converted? What about length?
|
Unresolved issues: Are elements converted? What about length?
|
||||||
|
|
||||||
|
|
||||||
Map Literals
|
Map Literals
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -641,6 +645,7 @@ All keys must have the same type; all values must have the same type.
|
|||||||
Unresolved issues: Are elements converted?
|
Unresolved issues: Are elements converted?
|
||||||
Colon for a separator or comma?
|
Colon for a separator or comma?
|
||||||
|
|
||||||
|
|
||||||
Struct literals
|
Struct literals
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -712,7 +717,7 @@ Functions can return multiple values simultaneously.
|
|||||||
Receiver = "(" identifier Type ")" .
|
Receiver = "(" identifier Type ")" .
|
||||||
Parameters = "(" [ ParameterList ] ")" .
|
Parameters = "(" [ ParameterList ] ")" .
|
||||||
ParameterList = ParameterSection { "," ParameterSection } .
|
ParameterList = ParameterSection { "," ParameterSection } .
|
||||||
ParameterSection = [ IdentifierList ] Type .
|
ParameterSection = IdentifierList Type .
|
||||||
Result = Type | "(" ParameterList ")" .
|
Result = Type | "(" ParameterList ")" .
|
||||||
|
|
||||||
// Function types
|
// Function types
|
||||||
@ -758,6 +763,7 @@ variables, and variables declared within the function literal.
|
|||||||
|
|
||||||
Unresolved issues: Are there method literals? How do you use them?
|
Unresolved issues: Are there method literals? How do you use them?
|
||||||
|
|
||||||
|
|
||||||
Methods
|
Methods
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -874,6 +880,45 @@ can match any type at all, including basic types, arrays, etc.
|
|||||||
TODO: details about reflection
|
TODO: details about reflection
|
||||||
|
|
||||||
|
|
||||||
|
Equivalence of types
|
||||||
|
---
|
||||||
|
|
||||||
|
Types are structurally equivalent: Two types are equivalent ('equal') if they
|
||||||
|
are constructed the same way from equivalent types.
|
||||||
|
|
||||||
|
For instance, all variables declared as "*int" have equivalent type,
|
||||||
|
as do all variables declared as "map [string] chan int".
|
||||||
|
|
||||||
|
More precisely, two struct types are equivalent if they have exactly the same fields
|
||||||
|
in the same order, with equal field names and types. For all other composite types,
|
||||||
|
the types of the components must be equivalent. Additionally, for equivalent arrays,
|
||||||
|
the lengths must be equal (or absent), and for channel types the mode must be equal
|
||||||
|
(">", "<", or none). The names of receivers, parameters, or result values of functions
|
||||||
|
are ignored for the purpose of type equivalence.
|
||||||
|
|
||||||
|
For instance, the struct type
|
||||||
|
|
||||||
|
struct {
|
||||||
|
a int;
|
||||||
|
b int;
|
||||||
|
f *func (m *[32] float, x int, y int) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
is equivalent to
|
||||||
|
|
||||||
|
struct {
|
||||||
|
a, b int;
|
||||||
|
f *F
|
||||||
|
}
|
||||||
|
|
||||||
|
where "F" is declared as "func (a *[30 + 2] float, b, c int) (ok bool)".
|
||||||
|
|
||||||
|
Finally, two interface types are equivalent if they both declare the same set of
|
||||||
|
methods: For each method in the first interface type there is a method in the
|
||||||
|
second interface type with the same method name and equivalent signature, and
|
||||||
|
vice versa. Note that the declaration order of the methods is not relevant.
|
||||||
|
|
||||||
|
|
||||||
Literals
|
Literals
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -1036,6 +1081,7 @@ the following holds:
|
|||||||
t.f == 0.0
|
t.f == 0.0
|
||||||
t.next == nil
|
t.next == nil
|
||||||
|
|
||||||
|
|
||||||
Export declarations
|
Export declarations
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -1184,6 +1230,7 @@ TODO: how does this definition jibe with using nil to specify
|
|||||||
conversion failure if the result is not of pointer type, such
|
conversion failure if the result is not of pointer type, such
|
||||||
as an any variable holding an int?
|
as an any variable holding an int?
|
||||||
|
|
||||||
|
|
||||||
Allocation
|
Allocation
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -1243,6 +1290,7 @@ TODO: are there parameters to any conversions? go.y has oexpr_list as the
|
|||||||
contents of a TypeName() conversion; i expected expr instead and that's what
|
contents of a TypeName() conversion; i expected expr instead and that's what
|
||||||
the others have.
|
the others have.
|
||||||
|
|
||||||
|
|
||||||
The constant generator 'iota'
|
The constant generator 'iota'
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -1762,6 +1810,7 @@ followed by a series of declarations.
|
|||||||
|
|
||||||
Program = PackageClause { ImportDecl } { Declaration } .
|
Program = PackageClause { ImportDecl } { Declaration } .
|
||||||
|
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
----
|
----
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user