Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
3aec2e46
Commit
3aec2e46
authored
Sep 25, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite the section about imports
DELTA=42 (10 added, 11 deleted, 21 changed) OCL=35017 CL=35020
parent
0c18d138
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
29 deletions
+28
-29
doc/go_spec.html
doc/go_spec.html
+28
-29
No files found.
doc/go_spec.html
View file @
3aec2e46
...
...
@@ -4176,23 +4176,12 @@ An implementation may require that all source files for a package inhabit the sa
<h3
id=
"Import_declarations"
>
Import declarations
</h3>
<p>
An import declaration states that the current package depends on the
<i>
imported
</i>
package and provides acccess to its
<a
href=
"#Exported_identifiers"
>
exported identifiers
</a>
.
</p>
<p>
The import declaration binds a package name to the imported package (except in
the case of
<code>
.
</code>
or
<code>
_
</code>
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.
</p>
<p>
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.
An import declaration states that the source file containing the
declaration uses identifiers
<a
href=
"#Exported_identifiers"
>
exported
</a>
by the
<i>
imported
</i>
package and enables access to them. The import names an
identifier (PackageName) to be used for access and an ImportPath
that specifies the package to be imported.
</p>
<pre
class=
"ebnf"
>
...
...
@@ -4203,22 +4192,30 @@ ImportPath = StringLit .
</pre>
<p>
If a package
<code>
A
</code>
is imported by a package
<code>
P
</code>
and
<code>
A
</code>
exports an identifier
<code>
X
</code>
, then
<code>
X
</code>
may be referred to by the
<a
href=
"#Qualified_identifiers"
>
qualified identifier
</a>
<code>
A.X
</code>
within
<code>
P
</code>
. If an explicit package name
<code>
B
</code>
is present,
<code>
X
</code>
must be referred to as
<code>
B.X
</code>
.
Finally, if the import declaration uses an explicit period
(
<code>
.
</code>
) for the package name,
<code>
X
</code>
will be declared
in the current file's
<a
href=
"#Blocks"
>
file block
</a>
and can be accessed
without a qualifier.
The PackageName is used in
<a
href=
"#Qualified_identifiers"
>
qualified identifiers
</a>
to access the exported identifiers of the package within the importing source file.
It is declared in the
<a
href=
"#Blocks"
>
file block
</a>
.
If the PackageName is omitted, it defaults to the identifier specified in the
<a
href=
"#Package_clauses"
>
package clause
</a>
of the imported package.
If an explicit period (
<code>
.
</code>
) appears instead of a name, all the
package's exported identifiers will be declared in the current file's
file block and can be accessed without a qualifier.
</p>
<p>
The interpretation of the ImportPath is implementation-dependent but
it is typically a substring of the full file name of the compiled
package and may be relative to a repository of installed packages.
</p>
<p>
In this table, assume we have compiled a package named
<code>
math
</code>
, which exports function
<code>
Sin
</code>
, and
installed the compiled package in
file
Assume we have compiled a package containing the package clause
<code>
package
math
</code>
, which exports function
<code>
Sin
</code>
, and
installed the compiled package in
the file identified by
<code>
"lib/math"
</code>
.
This table illustrates how
<code>
Sin
</code>
may be accessed in files
that import the package after the
various types of import declaration.
</p>
<pre
class=
"grammar"
>
...
...
@@ -4230,6 +4227,8 @@ import . "lib/math" Sin
</pre>
<p>
An import declaration declares a dependency relation between
the importing and imported package.
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
<a
href=
"#Blank_identifier"
>
blank
</a>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment