-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code and name organization #107
Changes from all commits
2ae6b6f
5bba3a8
98562a6
a05e9c3
dfe42cb
3931951
43cfde9
b489c23
5b10b4d
6ce0f97
218df9f
5c33fbf
160b5c4
5829ac9
8692c9a
6b7f469
654cad6
aa96aaf
ca5d5bd
c132018
3d99524
5813814
3154969
a546035
1222334
3cebea3
4bbba84
d7d2850
7c4c32c
d5b8ab9
3e15730
e578b1f
5319498
06dea5d
bf74c75
9559bec
af6f4b1
2311f03
db2d550
1ebecc1
54f740b
cf53d74
0d81ff4
03f92f8
a5c4e16
8d62937
1d09728
9fed213
b53a98d
50cb15b
1e55c4f
365a089
0c6c6de
8297dbe
eae6a9b
2111545
23bee19
94bd816
69d1893
4f10ddb
e56549e
1cec071
99801c1
91f989e
559677b
7c464a5
e1c46e3
60dfa21
c8ea9bb
578591b
84cd55f
882d5e0
7a0a400
f914c1b
d0ba98a
b8f9fc2
53a1072
0da274b
16ba315
687c166
31a7619
6efd78e
4d15065
441fe24
6d9f997
d9a7b34
71375af
6c4d9e3
9607815
06b31f5
8a5b20b
79270d3
754cb6b
0388e5b
3c52bb7
2a1a662
e9f4404
3ef6558
f71c05d
cd6e7b4
fe4c7d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
- [Example code](#example-code) | ||
- [Basic syntax](#basic-syntax) | ||
- [Code and comments](#code-and-comments) | ||
- [Files, libraries, and packages](#files-libraries-and-packages) | ||
- [Packages, libraries, and namespaces](#packages-libraries-and-namespaces) | ||
- [Names and scopes](#names-and-scopes) | ||
- [Naming conventions](#naming-conventions) | ||
- [Aliases](#aliases) | ||
|
@@ -127,36 +127,36 @@ cleaned up during evolution. | |
live code | ||
``` | ||
|
||
### Files, libraries, and packages | ||
### Packages, libraries, and namespaces | ||
|
||
> References: [Files, libraries and packages](files_libraries_and_packages.md) | ||
> | ||
> **TODO:** References need to be evolved. | ||
> References: [Code and name organization](code_and_name_organization.md) | ||
|
||
Carbon code is organized into files, libraries, and packages: | ||
- **Files** are grouped into libraries, which are in turn grouped into | ||
packages. | ||
- **Libraries** are the granularity of code reuse through imports. | ||
- **Packages** are the unit of distribution. | ||
|
||
- A **file** is the unit of compilation. | ||
- A **library** can be made up of multiple files, and is the unit whose public | ||
interface can be imported. | ||
- A **package** is a collection of one or more libraries, typically ones with | ||
a single common source and with some close association. | ||
Name paths in Carbon always start with the package name. Additional namespaces | ||
may be specified as desired. | ||
|
||
A file belongs to precisely one library, and a library belongs to precisely one | ||
package. | ||
For example, this code declares a struct `Geometry.Shapes.Flat.Circle` in a | ||
library `Geometry/OneSide`: | ||
|
||
Files have a `.6c` extension. They must start with a declaration of their | ||
package and library. They may import both other libraries from within their | ||
package, as well as libraries from other packages. For example: | ||
```carbon | ||
package Geometry library("OneSide") namespace Shapes; | ||
|
||
namespace Flat; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A semicolon-terminated namespace declaration is not very clear about how it combines with other namespace declarations. Specifically, does it override the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think line 140 covers this: |
||
struct Flat.Circle { ... } | ||
``` | ||
|
||
This type can be used from another package: | ||
|
||
```carbon | ||
// This is a file in the "Eucalyptus" library of the "Koala" package. | ||
package Koala library Eucalyptus; | ||
package ExampleUser; | ||
|
||
// Import the "Wombat" library from the "Widget" package. | ||
import Widget library Wombat; | ||
import Geometry library("OneSide"); | ||
|
||
// Import the "Container" library from the "Koala" package. | ||
import library Container; | ||
fn Foo(var Geometry.Shapes.Flat.Circle: circle) { ... } | ||
``` | ||
|
||
### Names and scopes | ||
|
@@ -222,37 +222,11 @@ textually after this can refer to `MyInt`, and it will transparently refer to | |
|
||
#### Name lookup | ||
|
||
> References: [Name lookup](name_lookup.md) | ||
> References: [name lookup](name_lookup.md) | ||
> | ||
> **TODO:** References need to be evolved. | ||
|
||
Names are always introduced into some scope which defines where they can be | ||
referenced. Many of these scopes are themselves named. `namespace` is used to | ||
introduce a dedicated named scope, and we traverse nested names in a uniform way | ||
with `.`-separated names. Unqualified name lookup will always find a file-local | ||
result, including aliases. | ||
|
||
For example: | ||
|
||
```carbon | ||
package Koala library Eucalyptus; | ||
|
||
namespace Leaf { | ||
namespace Vein { | ||
fn Count() -> Int; | ||
} | ||
} | ||
``` | ||
|
||
`Count` may be referred to as: | ||
|
||
- `Count` from within the `Vein` namespace. | ||
- `Vein.Count` from within the `Leaf` namespace. | ||
- `Leaf.Vein.Count` from within this file. | ||
- `Koala.Leaf.Vein.Count` from any arbitrary location. | ||
|
||
Note that libraries do **not** introduce a scope; they share the scope of their | ||
package. | ||
Unqualified name lookup will always find a file-local result, including aliases. | ||
|
||
##### Name lookup for common types | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked this list because it gave succinct definitions of the concepts at the beginning of the section. Was it incorrect? If so, can we correct or improve it, instead of deleting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rephrased the paragraph on line 134 as bullets.
Note here, this may end up going back again: it changed to a paragraph based on other feedback on writing styles. I'm not heavily opinionated, but I won't provide the same information both ways.