Skip to content

Commit 9d88a09

Browse files
committed
update modules
1 parent 2d8d0f5 commit 9d88a09

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/packages/modules/index.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Modules
22

3-
Modules include programs that contain a set of packages and their sub-packages. It mostly serves to enable a program to use its own packages or to make a package available to other users. In the common scenario it is a set of packages that you import in your code.
3+
Modules are the most common and recommended way to organize a Jule project. A module defines the structure of the project and safely groups all packages within the project to achieve modularization. This allows you to have subpackages in any project and organize code effectively. It is also important when designing third-party packages, as it provides the organization for the package.
44

55
Modules standardize your code and outline its main structure. Your module file is a type specifier, the directory where the file is located is considered the parent directory of your module and your compiler processes your code accordingly.
66

@@ -23,22 +23,20 @@ It is useful to use modules. It is more difficult to test your projects without
2323

2424
For most programs it is necessary to write subpackages. It is important for a streamlined and maintainable development experience. You also need to use a module to access sub-packages.
2525

26-
Modules can access sub-packages from the main package through their own package import behavior. This applies to all modules.
26+
Modules can access sub-packages from the main package through their own package import behavior. This applies to all modules. In a [use declaration](/packages/using-packages), to import any subpackage, the name of the current module in that scope must be used first. Import paths that do not start with the module name are considered invalid.
2727

2828
For example:
2929
```
3030
project/
3131
├─ foo/
3232
│ ├─ bar/
3333
│ │ └─ bar.jule
34-
│ │
3534
│ └─ foo.jule
36-
3735
├─ jule.mod
3836
└─ main.jule
3937
```
4038

41-
In the project structure above, the `main.jule` file must use `foo::bar` to access the `bar` package of module. This is because the module directory is the `project` directory. Likewise, the `foo` package should use `foo::bar` instead of `bar`.
39+
In the project structure above, the `main.jule` file must use `"project/foo/bar"` to use the `bar` package of module. This is because the module directory is the `project` directory. Likewise, the `foo` package should use `"project/foo/bar"` instead of `bar`.
4240

4341
## Nested Modules
4442

@@ -50,14 +48,12 @@ project/
5048
├─ foo/
5149
│ ├─ bar/
5250
│ │ └─ bar.jule
53-
│ │
5451
│ ├─ foo.jule
5552
│ └─ jule.mod
56-
5753
├─ jule.mod
5854
└─ main.jule
5955
```
6056

61-
In the example above, since `main.jule` has a module file, it will import the `bar` package with `foo::bar`. However, since the `foo` package has a module within itself, it is its main package. So it uses `bar` to import the `bar` package.
57+
In the example above, since `main.jule` has a module file, it will import the `bar` package with `"package/foo/bar"`. However, since the `foo` package has a module within itself, it is its main package. So it uses `"foo/bar"` to import the `bar` package.
6258

6359
In this way, the `foo` package was designed as a separate module and became more portable. It should be easy to move to different locations due to its intuitive imports thanks to the module file.

0 commit comments

Comments
 (0)