From 997851e681669439d01ad52457576e3370e1a9e4 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 25 Sep 2009 15:36:25 -0700 Subject: [PATCH] - reworked section on import declarations - added missing

tags in various places DELTA=62 (32 added, 4 deleted, 26 changed) OCL=35014 CL=35014 --- doc/go_spec.html | 78 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index c265661e10..4255fec42b 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1266,7 +1266,7 @@ can be represented accurately as a value of type T.

The predeclared identifier nil is assignment compatible with any pointer, function, slice, map, channel, or interface type and -represents the zero value for that type. +represents the zero value for that type.

@@ -1417,7 +1417,7 @@ the entity declared by the inner declaration.

The package clause is not a declaration; the package name does not appear in any scope. Its purpose is to identify the files belonging -to the same package and to specify the default name for import +to the same package and to specify the default package name for import declarations.

@@ -1694,14 +1694,18 @@ var s = "OMDB" // s has type string

Short variable declarations

+

A short variable declaration uses the syntax: +

 ShortVarDecl = IdentifierList ":=" ExpressionList .
 
+

It is a shorthand for a regular variable declaration with initializer expressions but no types: +

 "var" IdentifierList = ExpressionList .
@@ -1836,7 +1840,9 @@ operators and functions to operands.
 
 

Operands

+

Operands denote the elementary values in an expression. +

 Operand    = Literal | QualifiedIdent | MethodExpr | "(" Expression ")" .
@@ -3009,9 +3015,9 @@ respectively. Except for shift operations, if the operands of a binary operation
 are an untyped integer constant and an untyped floating-point constant,
 the integer constant is converted to an untyped floating-point constant
 (relevant for / and %).
-

-

+ +

Applying an operator to untyped constants results in an untyped constant of the same kind (that is, a boolean, integer, floating-point, or string constant), except for @@ -4170,34 +4176,42 @@ An implementation may require that all source files for a package inhabit the sa

Import declarations

-A source file gains access to exported identifiers -from another package through an import declaration. -In the general form, an import declaration provides an identifier -that code in the source file may use to access the imported package's -contents and a file name referring to the (compiled) implementation of -the package. The file name may be relative to a repository of -installed packages. +An import declaration states that the current package depends on the +imported package and provides acccess to its +exported identifiers. +

+ +

+The import declaration binds a package name to the imported package (except in +the case of . or _ imports; see below). The package name +denotes the imported package within the current source file. If no explicit +package name is present, the package name defined within the source +files of the imported package is used. +

+ +

+The imported package is specified by an import path; the meaning of the path +is implementation-dependent. It may be a file name relative to a repository +of installed packages and the file a (compiled) implementation of the package.

 ImportDecl       = "import" ( ImportSpec | "(" [ ImportSpecList ] ")" ) .
 ImportSpecList   = ImportSpec { ";" ImportSpec } [ ";" ] .
-ImportSpec       = [ "." | PackageName ] PackageFileName .
-PackageFileName  = StringLit .
+ImportSpec       = [ "." | PackageName ] ImportPath .
+ImportPath       = StringLit .
 

-After an import, in the usual case an exported name N from the imported -package P may be accessed by the qualified identifier -P.N (§Qualified identifiers). The actual -name P depends on the form of the import declaration. If -an explicit package name p1 is provided, the qualified -identifer will have the form p1.N. If no name -is provided in the import declaration, P will be the package -name declared within the source files of the imported package. +If a package A is imported by a package P and +A exports an identifier X, then X +may be referred to by the qualified identifier +A.X within P. If an explicit package name +B is present, X must be referred to as B.X. Finally, if the import declaration uses an explicit period -(.) for the package name, N will be declared -in the current file's file block and can be accessed without a qualifier. +(.) for the package name, X will be declared +in the current file's file block and can be accessed +without a qualifier.

@@ -4208,13 +4222,25 @@ installed the compiled package in file

-Import syntax               Local name of Sin
+Import declaration          Local name of Sin
 
-import M "lib/math"         M.Sin
 import   "lib/math"         math.Sin
+import M "lib/math"         M.Sin
 import . "lib/math"         Sin
 
+

+It is illegal for a package to import itself or to import a package without +referring to any of its exported identifiers. To import a package solely for +its side-effects (initialization), use the blank +identifier as explicit package name: +

+ +
+import _ "lib/math"
+
+ +

Multiple-file packages

@@ -4500,7 +4526,9 @@ provides a safe, more convenient way to inspect interface values.

Size and alignment guarantees

+

For the numeric types (§Numeric types), the following sizes are guaranteed: +

 type                      size in bytes
-- 
2.48.1