diff options
author | Louis Pilfold <louis@lpil.uk> | 2024-03-26 11:36:11 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-03-26 11:36:11 +0000 |
commit | 04ec0d86c8b43d1cca48adc937b3e596a10577a1 (patch) | |
tree | 8624097a135e0e879588279eed82c4c2f82bfbab /src/content/chapter0_basics/lesson03_unqualified_imports | |
parent | 9250d4324073874d393282c941f9981ce2686680 (diff) | |
download | tour-04ec0d86c8b43d1cca48adc937b3e596a10577a1.tar.gz tour-04ec0d86c8b43d1cca48adc937b3e596a10577a1.zip |
Improve introduction of modules and imports
Thanks @RyanBrewer317!
Diffstat (limited to 'src/content/chapter0_basics/lesson03_unqualified_imports')
-rw-r--r-- | src/content/chapter0_basics/lesson03_unqualified_imports/code.gleam | 10 | ||||
-rw-r--r-- | src/content/chapter0_basics/lesson03_unqualified_imports/en.html | 15 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/content/chapter0_basics/lesson03_unqualified_imports/code.gleam b/src/content/chapter0_basics/lesson03_unqualified_imports/code.gleam new file mode 100644 index 0000000..2708f25 --- /dev/null +++ b/src/content/chapter0_basics/lesson03_unqualified_imports/code.gleam @@ -0,0 +1,10 @@ +// Import the module and one of its functions +import gleam/io.{println} + +pub fn main() { + // Use the function in a qualified fashion + io.println("This is qualified") + + // Or an unqualified fashion + println("This is unqualified") +} diff --git a/src/content/chapter0_basics/lesson03_unqualified_imports/en.html b/src/content/chapter0_basics/lesson03_unqualified_imports/en.html new file mode 100644 index 0000000..ca83f2f --- /dev/null +++ b/src/content/chapter0_basics/lesson03_unqualified_imports/en.html @@ -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> |