Skip to content

Commit 6878870

Browse files
committed
update modules
1 parent be10d5a commit 6878870

File tree

8 files changed

+33
-17
lines changed

8 files changed

+33
-17
lines changed

.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export default defineConfig({
337337
link: '/packages/modules/',
338338
items: [
339339
{ text: 'Internal Packages', link: '/packages/modules/internal-packages' },
340+
{ text: 'Specification', link: '/packages/modules/specification' },
340341
],
341342
},
342343
{ text: 'Using Packages', link: '/packages/using-packages' },

src/getting-started/first-project.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# First Project
22

3-
In this section, you will quickly create your first Jule project. Youll learn the language details in later sections. This part is meant for a quick start and first look.
3+
In this section, you will quickly create your first Jule project. You'll learn the language details in later sections. This part is meant for a quick start and first look.
44

55
First, choose a workspace and create a `main.jule` file. Jule source code is written in files with the `.jule` extension. The compiler only works with these files. The `main.jule` file you create will be the file where you write your program.
66

@@ -10,7 +10,7 @@ fn main() {
1010
println("hello world")
1111
}
1212
```
13-
Once you've written your code in the `main.jule` file, youre ready to compile. With the compiler, you perform package-based compilation. [Packages](/packages/) are a core part of Jules project management. The directory you compile from is treated as the main package of your program.
13+
Once you've written your code in the `main.jule` file, you're ready to compile. With the compiler, you perform package-based compilation. [Packages](/packages/) are a core part of Jule's project management. The directory you compile from is treated as the main package of your program.
1414

1515
To compile your project with the compiler, you can use a command like the following:
1616
```

src/packages/modules/index.md

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

3-
Modules are the recommended way to organize a Jule project. A module defines the projects structure and groups related packages in a safe, modular fashion. This enables the use of subpackages, helps maintain clean organization, and is especially useful when designing third-party packages.
3+
Modules are the recommended way to organize a Jule project. A module defines the project's structure and groups related packages in a safe, modular fashion. This enables the use of subpackages, helps maintain clean organization, and is especially useful when designing third-party packages.
44

5-
Modules standardize code layout and establish the main structure of a project. The module file acts as the entry point: the directory containing it is treated as the modules root, and the compiler processes your code accordingly.
5+
Modules standardize code layout and establish the main structure of a project. The module file acts as the entry point: the directory containing it is treated as the module's root, and the compiler processes your code accordingly.
66

77
## Initialize a Module
88

9-
To create a module, run the compiler command in the target directory. This generates the required files and marks the current working directory as the root of your module.
9+
To create a module with a name, run the compiler command in the target directory. This generates the required files and marks the current working directory as the root of your module.
1010

1111
For example:
1212
```
13-
$ julec mod init
13+
$ julec mod init mylib
1414
```
1515

1616
## Module Files
@@ -19,7 +19,7 @@ A module is defined by a file named `jule.mod`. Its presence marks the directory
1919

2020
## Using Modules
2121

22-
Modules are not optional if you want to use Jules testing features—without them, testing becomes more difficult and less functional. See [writing tests](/debugging/testing/writing-tests#modules) for details.
22+
Modules are not optional if you want to use Jule's testing features—without them, testing becomes more difficult and less functional. See [writing tests](/debugging/testing/writing-tests#modules) for details.
2323

2424
For most projects, subpackages are essential to maintainable development. Modules are required to organize and import these subpackages.
2525

@@ -32,11 +32,11 @@ project/
3232
│ ├─ bar/
3333
│ │ └─ bar.jule
3434
│ └─ foo.jule
35-
├─ jule.mod
35+
├─ jule.mod (name is baz)
3636
└─ main.jule
3737
```
3838

39-
Here, `main.jule` must import the `bar` package as `"project/foo/bar"`, because the module root is `project/`. Likewise, the `foo` package must also use `"project/foo/bar"`, not just `bar`.
39+
Here a module with name `baz`, the file `main.jule` must import the `bar` package as `"baz/foo/bar"`, because the module name is `baz`. Likewise, the `foo` package must also use `"baz/foo/bar"`, not just `bar`.
4040

4141
## Nested Modules
4242

@@ -51,11 +51,11 @@ project/
5151
│ ├─ bar/
5252
│ │ └─ bar.jule
5353
│ ├─ foo.jule
54-
│ └─ jule.mod
55-
├─ jule.mod
54+
│ └─ jule.mod (name is foo)
55+
├─ jule.mod (name is baz)
5656
└─ main.jule
5757
```
5858

59-
In this structure `main.jule` located in the root module, imports bar as `"project/foo/bar"`. The` foo` package, however, contains its own `jule.mod`, making it a separate module. Inside `foo`, the `bar` package is imported as `"foo/bar"`.
59+
In this structure `main.jule` located in the root module, imports bar as `"baz/foo/bar"`. The `foo` package, however, contains its own `jule.mod`, making it a separate module. Inside `foo`, the `bar` package is imported as `"foo/bar"`.
6060

6161
This design makes the `foo` package self-contained and portable. Thanks to its own module file, it can be moved or reused in different projects without breaking imports.

src/packages/modules/internal-packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ project/
1616
└─ main.jule
1717
```
1818

19-
The `foo` package has its own module (`foo/jule.mod`), making `foo` the root of its module. The `internal` package under `foo` is internal to this module. All code within the `foo` module can access it. The `main.jule` file belongs to a different module (the project root module) and cannot access `foo/internal`, even though it can import the `foo` package itself.
19+
The `foo` package has its own module (`foo/jule.mod`), making `foo` the root of its module. The `internal` package under `foo` is internal to this module. All code within the `foo` module can access it. The `main.jule` file belongs to a different module (the project root module) and cannot access `foo/internal` directory, even though it can import the `foo` package itself.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Specification
2+
3+
Modules are represented with `jule.mod` files. The directories containing these files are treated as root directories, and their subdirectories behave as subpackages. Subpackages can also have their own dedicated modules.
4+
5+
## Module Names
6+
7+
Every module must have a module name. Module names define how the root directory of a module is represented in the import paths. This is important for portability, as it ensures a definitive name is used regardless of the root module directory.
8+
9+
In the module file, it is represented as follows:
10+
```
11+
module mylib
12+
```
13+
In the example above, the module name is specified as `mylib`.
14+
15+
A module name may only consist of letters, digits, `_`, or `.` characters. The first character must be either a letter or an `_`.

src/packages/using-packages.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Having any native module package `std` will make it unreachable. Because there i
3232
### Module
3333
Your own project may not consist of only one package, the main one. You may want to include different packages in your project. It is a useful action to use separate packages for the organization of the project. Jule recognizes subpackages in your project's main package and allows you to import those subpackages.
3434

35-
For example, your main package is head directory. This package is your entry package for project. But for this, your main program must also be a module. For more information about modules, you can look at the [modules](/packages/modules/) section.
35+
For example, your main package is the `head` directory. This package is your entry package for your project. But for this, your main program must also be a module. For more information about modules, you can look at the [modules](/packages/modules/) section.
3636

3737
Your example project tree:
3838
```
@@ -43,7 +43,7 @@ head/
4343
│ │ └─ bar.jule
4444
│ ├─ README.md
4545
│ └─ foo.jule
46-
├─ jule.mod
46+
├─ jule.mod (name is head)
4747
├─ LICENSE
4848
└─ main.jule
4949
```

src/some-questions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,4 @@ fn main() {
318318
foo(fn|mut x| { *x++ })
319319
}
320320
```
321-
In the example above, the `foo` function takes an anonymous function as a parameter and allows the `x` parameter to be used mutably. However, if you look at the first call in the example, youll see it actually only makes a `println` call. In this case, there is no need for the parameter to be mutable, and this does not compromise Jule's mutability safety. However, in the second call, the value of the `x` parameter is modified, so mutability is required.
321+
In the example above, the `foo` function takes an anonymous function as a parameter and allows the `x` parameter to be used mutably. However, if you look at the first call in the example, you'll see it actually only makes a `println` call. In this case, there is no need for the parameter to be mutable, and this does not compromise Jule's mutability safety. However, in the second call, the value of the `x` parameter is modified, so mutability is required.

src/the-mission.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ To achieve memory efficiency, some decisions must be made such as avoiding featu
3232
Rust is known for its strict safety guarantees, and it does an excellent job. However, as mentioned before, there are many different approaches.
3333
Jule is not as rigid as Rust; it's designed to be more flexible, similar to Go.
3434

35-
Go provides runtime safety, catching errors like boundary violations and nil pointer dereferencing. However, it doesnt enforce data race safety, even though concurrency is a key feature. This assumes the developer will act carefully and responsibly.
35+
Go provides runtime safety, catching errors like boundary violations and nil pointer dereferencing. However, it doesn't enforce data race safety, even though concurrency is a key feature. This assumes the developer will act carefully and responsibly.
3636

3737
Jule adopts a similar philosophy but is slightly stricter than Go. While it assumes developers will avoid issues like data races, it also performs some static safety analysis at compile-time.
3838

0 commit comments

Comments
 (0)