-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve introduction of modules and imports
Thanks @RyanBrewer317!
- Loading branch information
Showing
37 changed files
with
80 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
// Import a Gleam module from the standard library | ||
import gleam/io | ||
|
||
pub fn main() { | ||
// Print to the console | ||
io.println("Hello, Joe!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import gleam/io | ||
import gleam/string as text | ||
|
||
pub fn main() { | ||
// Use a function from the `gleam/io` module | ||
io.println("Hello, Mike!") | ||
|
||
// Use a function from the `gleam/string` module | ||
io.println(text.reverse("Hello, Joe!")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<p> | ||
Gleam code is organized into units called <em>modules</em>. A module is a | ||
bunch of definitions (of types, functions, etc.) that seem to belong together. | ||
For example, the | ||
<a href="https://hexdocs.pm/gleam_stdlib/gleam/io.html"> | ||
<code>gleam/io</code> | ||
</a> | ||
module contains a variety of functions for printing, like | ||
<code>println</code>. | ||
</p> | ||
<p> | ||
All gleam code is in <i>some</i> module or other, whose name comes from the | ||
name of the file it's in. For example, <code>gleam/io</code> is in a file | ||
called <code>io.gleam</code> in a directory called <code>gleam</code>. | ||
</p> | ||
<p> | ||
For code in one module to access code in another module, we import it using | ||
the <code>import</code> keyword, and the name used to refer to it is the last | ||
part of the module name. For example, to import the | ||
<code>gleam/io</code> module is referred to as <code>io</code> once imported. | ||
</p> | ||
<p> | ||
The <code>as</code> keyword can be used to refer to a module by a different | ||
name. See how the <code>gleam/string</code> module is be referred to as | ||
<code>text</code> here. | ||
</p> |
15 changes: 0 additions & 15 deletions
15
src/content/chapter0_basics/lesson02_unqualified_imports/en.html
This file was deleted.
Oops, something went wrong.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
src/content/chapter0_basics/lesson03_unqualified_imports/en.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<p> | ||
Normally functions from other modules are used in a | ||
<em>qualified</em> fashion, meaning the name used to refer the module goes | ||
before function name with a dot between them. For example, | ||
<code>io.println("Hello!")</code>. | ||
</p> | ||
<p> | ||
It is also possible to specify a list of functions to import from a module in | ||
an <em>unqualified</em> fashion, meaning the function name can be used without | ||
the module <em>qualifier</em> (the name and the dot) before it. | ||
</p> | ||
<p> | ||
Generally it is best to use qualified imports, as this makes it clear where | ||
the function is defined, making the code easier to read. | ||
</p> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters