You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/packages/modules/index.md
+4-8Lines changed: 4 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Modules
2
2
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.
4
4
5
5
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.
6
6
@@ -23,22 +23,20 @@ It is useful to use modules. It is more difficult to test your projects without
23
23
24
24
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.
25
25
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.
27
27
28
28
For example:
29
29
```
30
30
project/
31
31
├─ foo/
32
32
│ ├─ bar/
33
33
│ │ └─ bar.jule
34
-
│ │
35
34
│ └─ foo.jule
36
-
│
37
35
├─ jule.mod
38
36
└─ main.jule
39
37
```
40
38
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`.
42
40
43
41
## Nested Modules
44
42
@@ -50,14 +48,12 @@ project/
50
48
├─ foo/
51
49
│ ├─ bar/
52
50
│ │ └─ bar.jule
53
-
│ │
54
51
│ ├─ foo.jule
55
52
│ └─ jule.mod
56
-
│
57
53
├─ jule.mod
58
54
└─ main.jule
59
55
```
60
56
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.
62
58
63
59
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