From 04ec0d86c8b43d1cca48adc937b3e596a10577a1 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 26 Mar 2024 11:36:11 +0000 Subject: Improve introduction of modules and imports Thanks @RyanBrewer317! --- .../lesson01_hello_world/code.gleam | 2 -- .../chapter0_basics/lesson01_hello_world/en.html | 14 ++++------ .../chapter0_basics/lesson02_modules/code.gleam | 10 +++++++ .../chapter0_basics/lesson02_modules/en.html | 26 ++++++++++++++++++ .../lesson02_unqualified_imports/code.gleam | 10 ------- .../lesson02_unqualified_imports/en.html | 15 ---------- .../lesson03_type_checking/code.gleam | 7 ----- .../chapter0_basics/lesson03_type_checking/en.html | 18 ------------ .../lesson03_unqualified_imports/code.gleam | 10 +++++++ .../lesson03_unqualified_imports/en.html | 15 ++++++++++ .../chapter0_basics/lesson04_ints/code.gleam | 25 ----------------- src/content/chapter0_basics/lesson04_ints/en.html | 17 ------------ .../lesson04_type_checking/code.gleam | 7 +++++ .../chapter0_basics/lesson04_type_checking/en.html | 18 ++++++++++++ .../chapter0_basics/lesson05_floats/code.gleam | 27 ------------------ .../chapter0_basics/lesson05_floats/en.html | 32 ---------------------- .../chapter0_basics/lesson05_ints/code.gleam | 25 +++++++++++++++++ src/content/chapter0_basics/lesson05_ints/en.html | 17 ++++++++++++ .../chapter0_basics/lesson06_floats/code.gleam | 27 ++++++++++++++++++ .../chapter0_basics/lesson06_floats/en.html | 32 ++++++++++++++++++++++ .../lesson06_number_formats/code.gleam | 16 ----------- .../lesson06_number_formats/en.html | 13 --------- .../chapter0_basics/lesson07_equality/code.gleam | 6 ---- .../chapter0_basics/lesson07_equality/en.html | 13 --------- .../lesson07_number_formats/code.gleam | 16 +++++++++++ .../lesson07_number_formats/en.html | 13 +++++++++ .../chapter0_basics/lesson08_equality/code.gleam | 6 ++++ .../chapter0_basics/lesson08_equality/en.html | 13 +++++++++ .../chapter0_basics/lesson08_strings/code.gleam | 23 ---------------- .../chapter0_basics/lesson08_strings/en.html | 23 ---------------- .../chapter0_basics/lesson09_bools/code.gleam | 14 ---------- src/content/chapter0_basics/lesson09_bools/en.html | 17 ------------ .../chapter0_basics/lesson09_strings/code.gleam | 23 ++++++++++++++++ .../chapter0_basics/lesson09_strings/en.html | 23 ++++++++++++++++ .../lesson10_assignments/code.gleam | 17 ------------ .../chapter0_basics/lesson10_assignments/en.html | 9 ------ .../chapter0_basics/lesson10_bools/code.gleam | 14 ++++++++++ src/content/chapter0_basics/lesson10_bools/en.html | 17 ++++++++++++ .../lesson11_assignments/code.gleam | 17 ++++++++++++ .../chapter0_basics/lesson11_assignments/en.html | 9 ++++++ .../lesson11_discard_patterns/code.gleam | 4 --- .../lesson11_discard_patterns/en.html | 10 ------- .../lesson12_discard_patterns/code.gleam | 4 +++ .../lesson12_discard_patterns/en.html | 10 +++++++ .../lesson12_type_annotations/code.gleam | 7 ----- .../lesson12_type_annotations/en.html | 15 ---------- .../lesson13_type_aliases/code.gleam | 12 -------- .../chapter0_basics/lesson13_type_aliases/en.html | 12 -------- .../lesson13_type_annotations/code.gleam | 7 +++++ .../lesson13_type_annotations/en.html | 15 ++++++++++ .../chapter0_basics/lesson14_blocks/code.gleam | 13 --------- .../chapter0_basics/lesson14_blocks/en.html | 23 ---------------- .../lesson14_type_aliases/code.gleam | 12 ++++++++ .../chapter0_basics/lesson14_type_aliases/en.html | 12 ++++++++ .../chapter0_basics/lesson15_blocks/code.gleam | 13 +++++++++ .../chapter0_basics/lesson15_blocks/en.html | 23 ++++++++++++++++ .../chapter0_basics/lesson15_lists/code.gleam | 16 ----------- src/content/chapter0_basics/lesson15_lists/en.html | 19 ------------- .../chapter0_basics/lesson16_constants/code.gleam | 13 --------- .../chapter0_basics/lesson16_constants/en.html | 18 ------------ .../chapter0_basics/lesson16_lists/code.gleam | 16 +++++++++++ src/content/chapter0_basics/lesson16_lists/en.html | 19 +++++++++++++ .../chapter0_basics/lesson17_constants/code.gleam | 13 +++++++++ .../chapter0_basics/lesson17_constants/en.html | 18 ++++++++++++ src/tour.gleam | 1 - 65 files changed, 505 insertions(+), 476 deletions(-) create mode 100644 src/content/chapter0_basics/lesson02_modules/code.gleam create mode 100644 src/content/chapter0_basics/lesson02_modules/en.html delete mode 100644 src/content/chapter0_basics/lesson02_unqualified_imports/code.gleam delete mode 100644 src/content/chapter0_basics/lesson02_unqualified_imports/en.html delete mode 100644 src/content/chapter0_basics/lesson03_type_checking/code.gleam delete mode 100644 src/content/chapter0_basics/lesson03_type_checking/en.html create mode 100644 src/content/chapter0_basics/lesson03_unqualified_imports/code.gleam create mode 100644 src/content/chapter0_basics/lesson03_unqualified_imports/en.html delete mode 100644 src/content/chapter0_basics/lesson04_ints/code.gleam delete mode 100644 src/content/chapter0_basics/lesson04_ints/en.html create mode 100644 src/content/chapter0_basics/lesson04_type_checking/code.gleam create mode 100644 src/content/chapter0_basics/lesson04_type_checking/en.html delete mode 100644 src/content/chapter0_basics/lesson05_floats/code.gleam delete mode 100644 src/content/chapter0_basics/lesson05_floats/en.html create mode 100644 src/content/chapter0_basics/lesson05_ints/code.gleam create mode 100644 src/content/chapter0_basics/lesson05_ints/en.html create mode 100644 src/content/chapter0_basics/lesson06_floats/code.gleam create mode 100644 src/content/chapter0_basics/lesson06_floats/en.html delete mode 100644 src/content/chapter0_basics/lesson06_number_formats/code.gleam delete mode 100644 src/content/chapter0_basics/lesson06_number_formats/en.html delete mode 100644 src/content/chapter0_basics/lesson07_equality/code.gleam delete mode 100644 src/content/chapter0_basics/lesson07_equality/en.html create mode 100644 src/content/chapter0_basics/lesson07_number_formats/code.gleam create mode 100644 src/content/chapter0_basics/lesson07_number_formats/en.html create mode 100644 src/content/chapter0_basics/lesson08_equality/code.gleam create mode 100644 src/content/chapter0_basics/lesson08_equality/en.html delete mode 100644 src/content/chapter0_basics/lesson08_strings/code.gleam delete mode 100644 src/content/chapter0_basics/lesson08_strings/en.html delete mode 100644 src/content/chapter0_basics/lesson09_bools/code.gleam delete mode 100644 src/content/chapter0_basics/lesson09_bools/en.html create mode 100644 src/content/chapter0_basics/lesson09_strings/code.gleam create mode 100644 src/content/chapter0_basics/lesson09_strings/en.html delete mode 100644 src/content/chapter0_basics/lesson10_assignments/code.gleam delete mode 100644 src/content/chapter0_basics/lesson10_assignments/en.html create mode 100644 src/content/chapter0_basics/lesson10_bools/code.gleam create mode 100644 src/content/chapter0_basics/lesson10_bools/en.html create mode 100644 src/content/chapter0_basics/lesson11_assignments/code.gleam create mode 100644 src/content/chapter0_basics/lesson11_assignments/en.html delete mode 100644 src/content/chapter0_basics/lesson11_discard_patterns/code.gleam delete mode 100644 src/content/chapter0_basics/lesson11_discard_patterns/en.html create mode 100644 src/content/chapter0_basics/lesson12_discard_patterns/code.gleam create mode 100644 src/content/chapter0_basics/lesson12_discard_patterns/en.html delete mode 100644 src/content/chapter0_basics/lesson12_type_annotations/code.gleam delete mode 100644 src/content/chapter0_basics/lesson12_type_annotations/en.html delete mode 100644 src/content/chapter0_basics/lesson13_type_aliases/code.gleam delete mode 100644 src/content/chapter0_basics/lesson13_type_aliases/en.html create mode 100644 src/content/chapter0_basics/lesson13_type_annotations/code.gleam create mode 100644 src/content/chapter0_basics/lesson13_type_annotations/en.html delete mode 100644 src/content/chapter0_basics/lesson14_blocks/code.gleam delete mode 100644 src/content/chapter0_basics/lesson14_blocks/en.html create mode 100644 src/content/chapter0_basics/lesson14_type_aliases/code.gleam create mode 100644 src/content/chapter0_basics/lesson14_type_aliases/en.html create mode 100644 src/content/chapter0_basics/lesson15_blocks/code.gleam create mode 100644 src/content/chapter0_basics/lesson15_blocks/en.html delete mode 100644 src/content/chapter0_basics/lesson15_lists/code.gleam delete mode 100644 src/content/chapter0_basics/lesson15_lists/en.html delete mode 100644 src/content/chapter0_basics/lesson16_constants/code.gleam delete mode 100644 src/content/chapter0_basics/lesson16_constants/en.html create mode 100644 src/content/chapter0_basics/lesson16_lists/code.gleam create mode 100644 src/content/chapter0_basics/lesson16_lists/en.html create mode 100644 src/content/chapter0_basics/lesson17_constants/code.gleam create mode 100644 src/content/chapter0_basics/lesson17_constants/en.html (limited to 'src') diff --git a/src/content/chapter0_basics/lesson01_hello_world/code.gleam b/src/content/chapter0_basics/lesson01_hello_world/code.gleam index 67cc6b4..30530b2 100644 --- a/src/content/chapter0_basics/lesson01_hello_world/code.gleam +++ b/src/content/chapter0_basics/lesson01_hello_world/code.gleam @@ -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!") } diff --git a/src/content/chapter0_basics/lesson01_hello_world/en.html b/src/content/chapter0_basics/lesson01_hello_world/en.html index a7dfc25..b555160 100644 --- a/src/content/chapter0_basics/lesson01_hello_world/en.html +++ b/src/content/chapter0_basics/lesson01_hello_world/en.html @@ -1,16 +1,12 @@ -

Here is a program that prints out the text "Hello, Joe!".

- It does this by using the println function which has been - imported from the - gleam/io - module, which is part of the Gleam standard library. + Here is a tiny program that prints out the text "Hello, Joe!". We'll explain + how it works shortly.

- In a normal Gleam program this program would be run using the command + In a normal Gleam project this program would be run using the command gleam run on the command line, but here in this tour the program - is automatically compiled and run as the code is edited. + is compiled and run inside your web browser, allowing you to try Gleam without + installing anything on your computer.

Try changing the text being printed to Hello, Mike! and see what diff --git a/src/content/chapter0_basics/lesson02_modules/code.gleam b/src/content/chapter0_basics/lesson02_modules/code.gleam new file mode 100644 index 0000000..e258c33 --- /dev/null +++ b/src/content/chapter0_basics/lesson02_modules/code.gleam @@ -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!")) +} diff --git a/src/content/chapter0_basics/lesson02_modules/en.html b/src/content/chapter0_basics/lesson02_modules/en.html new file mode 100644 index 0000000..ebfd8bc --- /dev/null +++ b/src/content/chapter0_basics/lesson02_modules/en.html @@ -0,0 +1,26 @@ +

+ Gleam code is organized into units called modules. A module is a + bunch of definitions (of types, functions, etc.) that seem to belong together. + For example, the + + gleam/io + + module contains a variety of functions for printing, like + println. +

+

+ All gleam code is in some module or other, whose name comes from the + name of the file it's in. For example, gleam/io is in a file + called io.gleam in a directory called gleam. +

+

+ For code in one module to access code in another module, we import it using + the import keyword, and the name used to refer to it is the last + part of the module name. For example, to import the + gleam/io module is referred to as io once imported. +

+

+ The as keyword can be used to refer to a module by a different + name. See how the gleam/string module is be referred to as + text here. +

diff --git a/src/content/chapter0_basics/lesson02_unqualified_imports/code.gleam b/src/content/chapter0_basics/lesson02_unqualified_imports/code.gleam deleted file mode 100644 index 2708f25..0000000 --- a/src/content/chapter0_basics/lesson02_unqualified_imports/code.gleam +++ /dev/null @@ -1,10 +0,0 @@ -// 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/lesson02_unqualified_imports/en.html b/src/content/chapter0_basics/lesson02_unqualified_imports/en.html deleted file mode 100644 index 8fda45e..0000000 --- a/src/content/chapter0_basics/lesson02_unqualified_imports/en.html +++ /dev/null @@ -1,15 +0,0 @@ -

- Normally functions from other modules are used in a qualified fashion, with - the module qualifier before function name. For example, - io.println("Hello!"). -

-

- It is also possible to specify a list of functions to import from a module in - an unqualified fashion, such as the println function in the code - editor. Because it has been imported like this it can be referred to as just - println. -

-

- Generally it is best to use qualified imports, as this makes it clear where - the function is defined, making the code easier to read. -

diff --git a/src/content/chapter0_basics/lesson03_type_checking/code.gleam b/src/content/chapter0_basics/lesson03_type_checking/code.gleam deleted file mode 100644 index e068f31..0000000 --- a/src/content/chapter0_basics/lesson03_type_checking/code.gleam +++ /dev/null @@ -1,7 +0,0 @@ -import gleam/io - -pub fn main() { - io.println("My lucky number is:") - // io.println(4) - // ๐Ÿ‘†๏ธ Uncomment this line -} diff --git a/src/content/chapter0_basics/lesson03_type_checking/en.html b/src/content/chapter0_basics/lesson03_type_checking/en.html deleted file mode 100644 index a9316c4..0000000 --- a/src/content/chapter0_basics/lesson03_type_checking/en.html +++ /dev/null @@ -1,18 +0,0 @@ -

- Gleam has a robust static type system that helps you as you write and edit - code, catching mistakes and showing you where to make changes. -

-

- Uncomment the line io.println(4) and see how a compile time error - is reported as the io.println function only works with strings, - not ints. -

-

- To fix the code change the code to call the io.debug - function instead, as it will print a value of any type. -

-

- Gleam has no null, no implicit conversions, no exceptions, and - always performs full type checking. If the code compiles you can be reasonably - confident it does not have any inconsistencies that may cause bugs or crashes. -

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 @@ +

+ Normally functions from other modules are used in a + qualified fashion, meaning the name used to refer the module goes + before function name with a dot between them. For example, + io.println("Hello!"). +

+

+ It is also possible to specify a list of functions to import from a module in + an unqualified fashion, meaning the function name can be used without + the module qualifier (the name and the dot) before it. +

+

+ Generally it is best to use qualified imports, as this makes it clear where + the function is defined, making the code easier to read. +

diff --git a/src/content/chapter0_basics/lesson04_ints/code.gleam b/src/content/chapter0_basics/lesson04_ints/code.gleam deleted file mode 100644 index cb7991b..0000000 --- a/src/content/chapter0_basics/lesson04_ints/code.gleam +++ /dev/null @@ -1,25 +0,0 @@ -import gleam/io -import gleam/int - -pub fn main() { - // Int arithmetic - io.debug(1 + 1) - io.debug(5 - 1) - io.debug(5 / 2) - io.debug(3 * 3) - io.debug(5 % 2) - - // Int comparisons - io.debug(2 > 1) - io.debug(2 < 1) - io.debug(2 >= 1) - io.debug(2 <= 1) - - // Equality works for any type - io.debug(1 == 1) - io.debug(2 == 1) - - // Standard library int functions - io.debug(int.max(42, 77)) - io.debug(int.clamp(5, 10, 20)) -} diff --git a/src/content/chapter0_basics/lesson04_ints/en.html b/src/content/chapter0_basics/lesson04_ints/en.html deleted file mode 100644 index 252496a..0000000 --- a/src/content/chapter0_basics/lesson04_ints/en.html +++ /dev/null @@ -1,17 +0,0 @@ -

Gleam's Int type represents whole numbers.

-

- There are arithmetic and comparison operators for ints, as well as the - equality operator which works on all types. -

-

- When running on the Erlang virtual machine ints have no maximum and minimum - size. When running on JavaScript runtimes ints are represented using - JavaScript's 64 bit floating point numbers, -

-

- The - gleam/int - standard library module contains functions for working with ints. -

diff --git a/src/content/chapter0_basics/lesson04_type_checking/code.gleam b/src/content/chapter0_basics/lesson04_type_checking/code.gleam new file mode 100644 index 0000000..e068f31 --- /dev/null +++ b/src/content/chapter0_basics/lesson04_type_checking/code.gleam @@ -0,0 +1,7 @@ +import gleam/io + +pub fn main() { + io.println("My lucky number is:") + // io.println(4) + // ๐Ÿ‘†๏ธ Uncomment this line +} diff --git a/src/content/chapter0_basics/lesson04_type_checking/en.html b/src/content/chapter0_basics/lesson04_type_checking/en.html new file mode 100644 index 0000000..a9316c4 --- /dev/null +++ b/src/content/chapter0_basics/lesson04_type_checking/en.html @@ -0,0 +1,18 @@ +

+ Gleam has a robust static type system that helps you as you write and edit + code, catching mistakes and showing you where to make changes. +

+

+ Uncomment the line io.println(4) and see how a compile time error + is reported as the io.println function only works with strings, + not ints. +

+

+ To fix the code change the code to call the io.debug + function instead, as it will print a value of any type. +

+

+ Gleam has no null, no implicit conversions, no exceptions, and + always performs full type checking. If the code compiles you can be reasonably + confident it does not have any inconsistencies that may cause bugs or crashes. +

diff --git a/src/content/chapter0_basics/lesson05_floats/code.gleam b/src/content/chapter0_basics/lesson05_floats/code.gleam deleted file mode 100644 index 4241ab4..0000000 --- a/src/content/chapter0_basics/lesson05_floats/code.gleam +++ /dev/null @@ -1,27 +0,0 @@ -import gleam/io -import gleam/float - -pub fn main() { - // Float arithmetic - io.debug(1.0 +. 1.5) - io.debug(5.0 -. 1.5) - io.debug(5.0 /. 2.5) - io.debug(3.0 *. 3.5) - - // Float comparisons - io.debug(2.2 >. 1.3) - io.debug(2.2 <. 1.3) - io.debug(2.2 >=. 1.3) - io.debug(2.2 <=. 1.3) - - // Equality works for any type - io.debug(1.1 == 1.1) - io.debug(2.1 == 1.2) - - // Division by zero is not an error - io.debug(3.14 /. 0.0) - - // Standard library float functions - io.debug(float.max(2.0, 9.5)) - io.debug(float.ceiling(5.4)) -} diff --git a/src/content/chapter0_basics/lesson05_floats/en.html b/src/content/chapter0_basics/lesson05_floats/en.html deleted file mode 100644 index 7175628..0000000 --- a/src/content/chapter0_basics/lesson05_floats/en.html +++ /dev/null @@ -1,32 +0,0 @@ -

Gleam's Float type represents numbers that are not integers.

-

- Gleam's numerical operators are not overloaded, so there are dedicated - operators for working with floats. -

-

- Floats are represented as 64 bit floating point numbers on both the Erlang and - JavaScript runtimes. The floating point behaviour is native to their - respective runtimes, so their exact behaviour will be slightly different - on the two runtimes. -

-

- Under the JavaScript runtime, exceeding the maximum (or minimum) representable - value for a floating point value will result in Infinity (or - -Infinity). Should you try to divide two infinities you will - get NaN as a result. -

-

- When running on the BEAM any overflow will raise an error. So there is - no NaN or Infinity float value in the Erlang - runtime. -

-

- Division by zero will not overflow, but is instead defined to be zero. -

-

- The - gleam/float - standard library module contains functions for working with floats. -

diff --git a/src/content/chapter0_basics/lesson05_ints/code.gleam b/src/content/chapter0_basics/lesson05_ints/code.gleam new file mode 100644 index 0000000..cb7991b --- /dev/null +++ b/src/content/chapter0_basics/lesson05_ints/code.gleam @@ -0,0 +1,25 @@ +import gleam/io +import gleam/int + +pub fn main() { + // Int arithmetic + io.debug(1 + 1) + io.debug(5 - 1) + io.debug(5 / 2) + io.debug(3 * 3) + io.debug(5 % 2) + + // Int comparisons + io.debug(2 > 1) + io.debug(2 < 1) + io.debug(2 >= 1) + io.debug(2 <= 1) + + // Equality works for any type + io.debug(1 == 1) + io.debug(2 == 1) + + // Standard library int functions + io.debug(int.max(42, 77)) + io.debug(int.clamp(5, 10, 20)) +} diff --git a/src/content/chapter0_basics/lesson05_ints/en.html b/src/content/chapter0_basics/lesson05_ints/en.html new file mode 100644 index 0000000..252496a --- /dev/null +++ b/src/content/chapter0_basics/lesson05_ints/en.html @@ -0,0 +1,17 @@ +

Gleam's Int type represents whole numbers.

+

+ There are arithmetic and comparison operators for ints, as well as the + equality operator which works on all types. +

+

+ When running on the Erlang virtual machine ints have no maximum and minimum + size. When running on JavaScript runtimes ints are represented using + JavaScript's 64 bit floating point numbers, +

+

+ The + gleam/int + standard library module contains functions for working with ints. +

diff --git a/src/content/chapter0_basics/lesson06_floats/code.gleam b/src/content/chapter0_basics/lesson06_floats/code.gleam new file mode 100644 index 0000000..4241ab4 --- /dev/null +++ b/src/content/chapter0_basics/lesson06_floats/code.gleam @@ -0,0 +1,27 @@ +import gleam/io +import gleam/float + +pub fn main() { + // Float arithmetic + io.debug(1.0 +. 1.5) + io.debug(5.0 -. 1.5) + io.debug(5.0 /. 2.5) + io.debug(3.0 *. 3.5) + + // Float comparisons + io.debug(2.2 >. 1.3) + io.debug(2.2 <. 1.3) + io.debug(2.2 >=. 1.3) + io.debug(2.2 <=. 1.3) + + // Equality works for any type + io.debug(1.1 == 1.1) + io.debug(2.1 == 1.2) + + // Division by zero is not an error + io.debug(3.14 /. 0.0) + + // Standard library float functions + io.debug(float.max(2.0, 9.5)) + io.debug(float.ceiling(5.4)) +} diff --git a/src/content/chapter0_basics/lesson06_floats/en.html b/src/content/chapter0_basics/lesson06_floats/en.html new file mode 100644 index 0000000..7175628 --- /dev/null +++ b/src/content/chapter0_basics/lesson06_floats/en.html @@ -0,0 +1,32 @@ +

Gleam's Float type represents numbers that are not integers.

+

+ Gleam's numerical operators are not overloaded, so there are dedicated + operators for working with floats. +

+

+ Floats are represented as 64 bit floating point numbers on both the Erlang and + JavaScript runtimes. The floating point behaviour is native to their + respective runtimes, so their exact behaviour will be slightly different + on the two runtimes. +

+

+ Under the JavaScript runtime, exceeding the maximum (or minimum) representable + value for a floating point value will result in Infinity (or + -Infinity). Should you try to divide two infinities you will + get NaN as a result. +

+

+ When running on the BEAM any overflow will raise an error. So there is + no NaN or Infinity float value in the Erlang + runtime. +

+

+ Division by zero will not overflow, but is instead defined to be zero. +

+

+ The + gleam/float + standard library module contains functions for working with floats. +

diff --git a/src/content/chapter0_basics/lesson06_number_formats/code.gleam b/src/content/chapter0_basics/lesson06_number_formats/code.gleam deleted file mode 100644 index 7307185..0000000 --- a/src/content/chapter0_basics/lesson06_number_formats/code.gleam +++ /dev/null @@ -1,16 +0,0 @@ -import gleam/io - -pub fn main() { - // Underscores - io.debug(1_000_000) - io.debug(10_000.01) - - // Binary, octal, and hex Int literals - io.debug(0b00001111) - io.debug(0o17) - io.debug(0xF) - - // Scientific notation Float literals - io.debug(7.0e7) - io.debug(3.0e-4) -} diff --git a/src/content/chapter0_basics/lesson06_number_formats/en.html b/src/content/chapter0_basics/lesson06_number_formats/en.html deleted file mode 100644 index 308219a..0000000 --- a/src/content/chapter0_basics/lesson06_number_formats/en.html +++ /dev/null @@ -1,13 +0,0 @@ -

- Underscores can be added to numbers for clarity. For example, - 1000000 can be tricky to read quickly, while - 1_000_000 can be easier. -

-

- Ints can be written in binary, octal, or hexadecimal formats using the - 0b, 0o, and 0x prefixes respectively. -

-

- Floats can be written in a scientific notation. -

- diff --git a/src/content/chapter0_basics/lesson07_equality/code.gleam b/src/content/chapter0_basics/lesson07_equality/code.gleam deleted file mode 100644 index 70a2b89..0000000 --- a/src/content/chapter0_basics/lesson07_equality/code.gleam +++ /dev/null @@ -1,6 +0,0 @@ -import gleam/io - -pub fn main() { - io.debug(100 == 100) - io.debug(1.5 != 0.1) -} diff --git a/src/content/chapter0_basics/lesson07_equality/en.html b/src/content/chapter0_basics/lesson07_equality/en.html deleted file mode 100644 index e8c2169..0000000 --- a/src/content/chapter0_basics/lesson07_equality/en.html +++ /dev/null @@ -1,13 +0,0 @@ -

- Gleam has the == and != operators for checking - equality. -

-

- The operators can be used with values of any type, but both sides of the - operator must be of the same type. -

-

- Equality is checked structurally, meaning that two values are equal - if they have the same structure rather than if they are at the same memory - location. -

diff --git a/src/content/chapter0_basics/lesson07_number_formats/code.gleam b/src/content/chapter0_basics/lesson07_number_formats/code.gleam new file mode 100644 index 0000000..7307185 --- /dev/null +++ b/src/content/chapter0_basics/lesson07_number_formats/code.gleam @@ -0,0 +1,16 @@ +import gleam/io + +pub fn main() { + // Underscores + io.debug(1_000_000) + io.debug(10_000.01) + + // Binary, octal, and hex Int literals + io.debug(0b00001111) + io.debug(0o17) + io.debug(0xF) + + // Scientific notation Float literals + io.debug(7.0e7) + io.debug(3.0e-4) +} diff --git a/src/content/chapter0_basics/lesson07_number_formats/en.html b/src/content/chapter0_basics/lesson07_number_formats/en.html new file mode 100644 index 0000000..308219a --- /dev/null +++ b/src/content/chapter0_basics/lesson07_number_formats/en.html @@ -0,0 +1,13 @@ +

+ Underscores can be added to numbers for clarity. For example, + 1000000 can be tricky to read quickly, while + 1_000_000 can be easier. +

+

+ Ints can be written in binary, octal, or hexadecimal formats using the + 0b, 0o, and 0x prefixes respectively. +

+

+ Floats can be written in a scientific notation. +

+ diff --git a/src/content/chapter0_basics/lesson08_equality/code.gleam b/src/content/chapter0_basics/lesson08_equality/code.gleam new file mode 100644 index 0000000..70a2b89 --- /dev/null +++ b/src/content/chapter0_basics/lesson08_equality/code.gleam @@ -0,0 +1,6 @@ +import gleam/io + +pub fn main() { + io.debug(100 == 100) + io.debug(1.5 != 0.1) +} diff --git a/src/content/chapter0_basics/lesson08_equality/en.html b/src/content/chapter0_basics/lesson08_equality/en.html new file mode 100644 index 0000000..e8c2169 --- /dev/null +++ b/src/content/chapter0_basics/lesson08_equality/en.html @@ -0,0 +1,13 @@ +

+ Gleam has the == and != operators for checking + equality. +

+

+ The operators can be used with values of any type, but both sides of the + operator must be of the same type. +

+

+ Equality is checked structurally, meaning that two values are equal + if they have the same structure rather than if they are at the same memory + location. +

diff --git a/src/content/chapter0_basics/lesson08_strings/code.gleam b/src/content/chapter0_basics/lesson08_strings/code.gleam deleted file mode 100644 index ea47e0f..0000000 --- a/src/content/chapter0_basics/lesson08_strings/code.gleam +++ /dev/null @@ -1,23 +0,0 @@ -import gleam/io -import gleam/string - -pub fn main() { - // String literals - io.debug("๐Ÿ‘ฉโ€๐Ÿ’ป ใ“ใ‚“ใซใกใฏ Gleam ๐Ÿณ๏ธโ€๐ŸŒˆ") - io.debug( - "multi - line - string", - ) - io.debug("\u{1F600}") - - // Double quote can be escaped - io.println("\"X\" marks the spot") - - // String concatenation - io.debug("One " <> "Two") - - // String functions - io.debug(string.reverse("1 2 3 4 5")) - io.debug(string.append("abc", "def")) -} diff --git a/src/content/chapter0_basics/lesson08_strings/en.html b/src/content/chapter0_basics/lesson08_strings/en.html deleted file mode 100644 index e5400ca..0000000 --- a/src/content/chapter0_basics/lesson08_strings/en.html +++ /dev/null @@ -1,23 +0,0 @@ -

- In Gleam strings are written as text surrounded by double quotes, and - can span multiple lines and contain unicode characters. -

-

- The <> operator can be used to concatenate strings. -

-

- Several escape sequences are supported: -

- -

- The gleam/string - standard library module contains functions for working with strings. -

diff --git a/src/content/chapter0_basics/lesson09_bools/code.gleam b/src/content/chapter0_basics/lesson09_bools/code.gleam deleted file mode 100644 index e5c1d98..0000000 --- a/src/content/chapter0_basics/lesson09_bools/code.gleam +++ /dev/null @@ -1,14 +0,0 @@ -import gleam/io -import gleam/bool - -pub fn main() { - // Bool operators - io.debug(True && False) - io.debug(True && True) - io.debug(False || False) - io.debug(False || True) - - // Bool functions - io.debug(bool.to_string(True)) - io.debug(bool.to_int(False)) -} diff --git a/src/content/chapter0_basics/lesson09_bools/en.html b/src/content/chapter0_basics/lesson09_bools/en.html deleted file mode 100644 index 36daf09..0000000 --- a/src/content/chapter0_basics/lesson09_bools/en.html +++ /dev/null @@ -1,17 +0,0 @@ -

- A Bool is either True or False. -

-

- The ||, &&, and ! operators can be used - to manipulate bools. -

-

- The || and && operators are short-circuiting, - meaning that if the left hand side of the operator is True for - || or False for && then the right hand - side of the operator will not be evaluated. -

-

- The gleam/bool - standard library module contains functions for working with bools. -

diff --git a/src/content/chapter0_basics/lesson09_strings/code.gleam b/src/content/chapter0_basics/lesson09_strings/code.gleam new file mode 100644 index 0000000..ea47e0f --- /dev/null +++ b/src/content/chapter0_basics/lesson09_strings/code.gleam @@ -0,0 +1,23 @@ +import gleam/io +import gleam/string + +pub fn main() { + // String literals + io.debug("๐Ÿ‘ฉโ€๐Ÿ’ป ใ“ใ‚“ใซใกใฏ Gleam ๐Ÿณ๏ธโ€๐ŸŒˆ") + io.debug( + "multi + line + string", + ) + io.debug("\u{1F600}") + + // Double quote can be escaped + io.println("\"X\" marks the spot") + + // String concatenation + io.debug("One " <> "Two") + + // String functions + io.debug(string.reverse("1 2 3 4 5")) + io.debug(string.append("abc", "def")) +} diff --git a/src/content/chapter0_basics/lesson09_strings/en.html b/src/content/chapter0_basics/lesson09_strings/en.html new file mode 100644 index 0000000..e5400ca --- /dev/null +++ b/src/content/chapter0_basics/lesson09_strings/en.html @@ -0,0 +1,23 @@ +

+ In Gleam strings are written as text surrounded by double quotes, and + can span multiple lines and contain unicode characters. +

+

+ The <> operator can be used to concatenate strings. +

+

+ Several escape sequences are supported: +

+ +

+ The gleam/string + standard library module contains functions for working with strings. +

diff --git a/src/content/chapter0_basics/lesson10_assignments/code.gleam b/src/content/chapter0_basics/lesson10_assignments/code.gleam deleted file mode 100644 index a030e43..0000000 --- a/src/content/chapter0_basics/lesson10_assignments/code.gleam +++ /dev/null @@ -1,17 +0,0 @@ -import gleam/io - -pub fn main() { - let x = "Original" - io.debug(x) - - // Assign `y` to the value of `x` - let y = x - io.debug(y) - - // Assign `x` to a new value - let x = "New" - io.debug(x) - - // The `y` still refers to the original value - io.debug(y) -} diff --git a/src/content/chapter0_basics/lesson10_assignments/en.html b/src/content/chapter0_basics/lesson10_assignments/en.html deleted file mode 100644 index d106fd9..0000000 --- a/src/content/chapter0_basics/lesson10_assignments/en.html +++ /dev/null @@ -1,9 +0,0 @@ -

A value can be assigned to a variable using let.

-

- Variable names can be reused by later let bindings, but the values they - reference are immutable, so the values themselves are not changed or mutated - in any way. -

-

- In Gleam variable and function names are written in snake_case. -

diff --git a/src/content/chapter0_basics/lesson10_bools/code.gleam b/src/content/chapter0_basics/lesson10_bools/code.gleam new file mode 100644 index 0000000..e5c1d98 --- /dev/null +++ b/src/content/chapter0_basics/lesson10_bools/code.gleam @@ -0,0 +1,14 @@ +import gleam/io +import gleam/bool + +pub fn main() { + // Bool operators + io.debug(True && False) + io.debug(True && True) + io.debug(False || False) + io.debug(False || True) + + // Bool functions + io.debug(bool.to_string(True)) + io.debug(bool.to_int(False)) +} diff --git a/src/content/chapter0_basics/lesson10_bools/en.html b/src/content/chapter0_basics/lesson10_bools/en.html new file mode 100644 index 0000000..36daf09 --- /dev/null +++ b/src/content/chapter0_basics/lesson10_bools/en.html @@ -0,0 +1,17 @@ +

+ A Bool is either True or False. +

+

+ The ||, &&, and ! operators can be used + to manipulate bools. +

+

+ The || and && operators are short-circuiting, + meaning that if the left hand side of the operator is True for + || or False for && then the right hand + side of the operator will not be evaluated. +

+

+ The gleam/bool + standard library module contains functions for working with bools. +

diff --git a/src/content/chapter0_basics/lesson11_assignments/code.gleam b/src/content/chapter0_basics/lesson11_assignments/code.gleam new file mode 100644 index 0000000..a030e43 --- /dev/null +++ b/src/content/chapter0_basics/lesson11_assignments/code.gleam @@ -0,0 +1,17 @@ +import gleam/io + +pub fn main() { + let x = "Original" + io.debug(x) + + // Assign `y` to the value of `x` + let y = x + io.debug(y) + + // Assign `x` to a new value + let x = "New" + io.debug(x) + + // The `y` still refers to the original value + io.debug(y) +} diff --git a/src/content/chapter0_basics/lesson11_assignments/en.html b/src/content/chapter0_basics/lesson11_assignments/en.html new file mode 100644 index 0000000..d106fd9 --- /dev/null +++ b/src/content/chapter0_basics/lesson11_assignments/en.html @@ -0,0 +1,9 @@ +

A value can be assigned to a variable using let.

+

+ Variable names can be reused by later let bindings, but the values they + reference are immutable, so the values themselves are not changed or mutated + in any way. +

+

+ In Gleam variable and function names are written in snake_case. +

diff --git a/src/content/chapter0_basics/lesson11_discard_patterns/code.gleam b/src/content/chapter0_basics/lesson11_discard_patterns/code.gleam deleted file mode 100644 index fa2c0e3..0000000 --- a/src/content/chapter0_basics/lesson11_discard_patterns/code.gleam +++ /dev/null @@ -1,4 +0,0 @@ -pub fn main() { - // This variable is never used - let _score = 1000 -} diff --git a/src/content/chapter0_basics/lesson11_discard_patterns/en.html b/src/content/chapter0_basics/lesson11_discard_patterns/en.html deleted file mode 100644 index 91cfb42..0000000 --- a/src/content/chapter0_basics/lesson11_discard_patterns/en.html +++ /dev/null @@ -1,10 +0,0 @@ -

- If a variable is assigned but not used then Gleam will emit a warning. -

-

- If a variable is intended to not be used, then the name can be prefixed with an - underscore, silencing the warning. -

-

- Try changing the variable name to score to see the warning. -

diff --git a/src/content/chapter0_basics/lesson12_discard_patterns/code.gleam b/src/content/chapter0_basics/lesson12_discard_patterns/code.gleam new file mode 100644 index 0000000..fa2c0e3 --- /dev/null +++ b/src/content/chapter0_basics/lesson12_discard_patterns/code.gleam @@ -0,0 +1,4 @@ +pub fn main() { + // This variable is never used + let _score = 1000 +} diff --git a/src/content/chapter0_basics/lesson12_discard_patterns/en.html b/src/content/chapter0_basics/lesson12_discard_patterns/en.html new file mode 100644 index 0000000..91cfb42 --- /dev/null +++ b/src/content/chapter0_basics/lesson12_discard_patterns/en.html @@ -0,0 +1,10 @@ +

+ If a variable is assigned but not used then Gleam will emit a warning. +

+

+ If a variable is intended to not be used, then the name can be prefixed with an + underscore, silencing the warning. +

+

+ Try changing the variable name to score to see the warning. +

diff --git a/src/content/chapter0_basics/lesson12_type_annotations/code.gleam b/src/content/chapter0_basics/lesson12_type_annotations/code.gleam deleted file mode 100644 index 1299c2f..0000000 --- a/src/content/chapter0_basics/lesson12_type_annotations/code.gleam +++ /dev/null @@ -1,7 +0,0 @@ -pub fn main() { - let _name: String = "Gleam" - - let _is_cool: Bool = True - - let _version: Int = 1 -} diff --git a/src/content/chapter0_basics/lesson12_type_annotations/en.html b/src/content/chapter0_basics/lesson12_type_annotations/en.html deleted file mode 100644 index 8738a15..0000000 --- a/src/content/chapter0_basics/lesson12_type_annotations/en.html +++ /dev/null @@ -1,15 +0,0 @@ -

- Let assignments can be written with a type annotation after the name. -

-

- Type annotations may be useful for documentation purposes, but they do not - change how Gleam type checks the code beyond ensuring that the annotation is - correct. -

-

- Typically Gleam code will not have type annotations for assignments. -

-

- Try changing a type annotation to something incorrect to see the compile - error. -

diff --git a/src/content/chapter0_basics/lesson13_type_aliases/code.gleam b/src/content/chapter0_basics/lesson13_type_aliases/code.gleam deleted file mode 100644 index 6125ffe..0000000 --- a/src/content/chapter0_basics/lesson13_type_aliases/code.gleam +++ /dev/null @@ -1,12 +0,0 @@ -import gleam/io - -pub type UserId = - Int - -pub fn main() { - let one: UserId = 1 - let two: Int = 2 - - // UserId and Int are the same type - io.debug(one == two) -} diff --git a/src/content/chapter0_basics/lesson13_type_aliases/en.html b/src/content/chapter0_basics/lesson13_type_aliases/en.html deleted file mode 100644 index 9fddd70..0000000 --- a/src/content/chapter0_basics/lesson13_type_aliases/en.html +++ /dev/null @@ -1,12 +0,0 @@ -

- A type alias can be used to refer to a type by a different name. Giving a type - an alias doesn't make a new type, it is still the same type. -

-

- A type's name always starts with a capital letter, contrasting to variables - and functions, which start with a lowercase letter. -

-

- When the pub keyword is used the type alias is public and can be - referred to by other modules. -

diff --git a/src/content/chapter0_basics/lesson13_type_annotations/code.gleam b/src/content/chapter0_basics/lesson13_type_annotations/code.gleam new file mode 100644 index 0000000..1299c2f --- /dev/null +++ b/src/content/chapter0_basics/lesson13_type_annotations/code.gleam @@ -0,0 +1,7 @@ +pub fn main() { + let _name: String = "Gleam" + + let _is_cool: Bool = True + + let _version: Int = 1 +} diff --git a/src/content/chapter0_basics/lesson13_type_annotations/en.html b/src/content/chapter0_basics/lesson13_type_annotations/en.html new file mode 100644 index 0000000..8738a15 --- /dev/null +++ b/src/content/chapter0_basics/lesson13_type_annotations/en.html @@ -0,0 +1,15 @@ +

+ Let assignments can be written with a type annotation after the name. +

+

+ Type annotations may be useful for documentation purposes, but they do not + change how Gleam type checks the code beyond ensuring that the annotation is + correct. +

+

+ Typically Gleam code will not have type annotations for assignments. +

+

+ Try changing a type annotation to something incorrect to see the compile + error. +

diff --git a/src/content/chapter0_basics/lesson14_blocks/code.gleam b/src/content/chapter0_basics/lesson14_blocks/code.gleam deleted file mode 100644 index 31e4729..0000000 --- a/src/content/chapter0_basics/lesson14_blocks/code.gleam +++ /dev/null @@ -1,13 +0,0 @@ -import gleam/io - -pub fn main() { - let fahrenheit = { - let degrees = 64 - degrees - } - // io.debug(degrees) // <- This will not compile - - // Changing order of evaluation - let celsius = { fahrenheit - 32 } * 5 / 9 - io.debug(celsius) -} diff --git a/src/content/chapter0_basics/lesson14_blocks/en.html b/src/content/chapter0_basics/lesson14_blocks/en.html deleted file mode 100644 index bc82e39..0000000 --- a/src/content/chapter0_basics/lesson14_blocks/en.html +++ /dev/null @@ -1,23 +0,0 @@ -

- Blocks are one or more expressions grouped together with curly braces. Each - expression is evaluated in order and the value of the last expression is - returned. -

-

- Any variables assigned within the block can only be used within the block. -

-

- Try uncommenting io.debug(degrees) to see the compile error from - trying to use a variable that is not in scope. -

-

- Blocks can also be used to change the order of evaluation of binary operators - expressions. -

-

- * binds more tightly than + so the expression - 1 + 2 * 3 evaluates to 7. If the 1 + 2 should be - evaluated first to make the expression evaluate to 9 then the expression can be - wrapped in a block: { 1 + 2 } * 3. This is similar to grouping - with parentheses in some other languages. -

diff --git a/src/content/chapter0_basics/lesson14_type_aliases/code.gleam b/src/content/chapter0_basics/lesson14_type_aliases/code.gleam new file mode 100644 index 0000000..6125ffe --- /dev/null +++ b/src/content/chapter0_basics/lesson14_type_aliases/code.gleam @@ -0,0 +1,12 @@ +import gleam/io + +pub type UserId = + Int + +pub fn main() { + let one: UserId = 1 + let two: Int = 2 + + // UserId and Int are the same type + io.debug(one == two) +} diff --git a/src/content/chapter0_basics/lesson14_type_aliases/en.html b/src/content/chapter0_basics/lesson14_type_aliases/en.html new file mode 100644 index 0000000..9fddd70 --- /dev/null +++ b/src/content/chapter0_basics/lesson14_type_aliases/en.html @@ -0,0 +1,12 @@ +

+ A type alias can be used to refer to a type by a different name. Giving a type + an alias doesn't make a new type, it is still the same type. +

+

+ A type's name always starts with a capital letter, contrasting to variables + and functions, which start with a lowercase letter. +

+

+ When the pub keyword is used the type alias is public and can be + referred to by other modules. +

diff --git a/src/content/chapter0_basics/lesson15_blocks/code.gleam b/src/content/chapter0_basics/lesson15_blocks/code.gleam new file mode 100644 index 0000000..31e4729 --- /dev/null +++ b/src/content/chapter0_basics/lesson15_blocks/code.gleam @@ -0,0 +1,13 @@ +import gleam/io + +pub fn main() { + let fahrenheit = { + let degrees = 64 + degrees + } + // io.debug(degrees) // <- This will not compile + + // Changing order of evaluation + let celsius = { fahrenheit - 32 } * 5 / 9 + io.debug(celsius) +} diff --git a/src/content/chapter0_basics/lesson15_blocks/en.html b/src/content/chapter0_basics/lesson15_blocks/en.html new file mode 100644 index 0000000..bc82e39 --- /dev/null +++ b/src/content/chapter0_basics/lesson15_blocks/en.html @@ -0,0 +1,23 @@ +

+ Blocks are one or more expressions grouped together with curly braces. Each + expression is evaluated in order and the value of the last expression is + returned. +

+

+ Any variables assigned within the block can only be used within the block. +

+

+ Try uncommenting io.debug(degrees) to see the compile error from + trying to use a variable that is not in scope. +

+

+ Blocks can also be used to change the order of evaluation of binary operators + expressions. +

+

+ * binds more tightly than + so the expression + 1 + 2 * 3 evaluates to 7. If the 1 + 2 should be + evaluated first to make the expression evaluate to 9 then the expression can be + wrapped in a block: { 1 + 2 } * 3. This is similar to grouping + with parentheses in some other languages. +

diff --git a/src/content/chapter0_basics/lesson15_lists/code.gleam b/src/content/chapter0_basics/lesson15_lists/code.gleam deleted file mode 100644 index 646ad6e..0000000 --- a/src/content/chapter0_basics/lesson15_lists/code.gleam +++ /dev/null @@ -1,16 +0,0 @@ -import gleam/io - -pub fn main() { - let ints = [1, 2, 3] - - io.debug(ints) - - // Immutably prepend - io.debug([-1, 0, ..ints]) - - // Uncomment this to see the error - // io.debug(["zero", ..ints]) - - // The original lists are unchanged - io.debug(ints) -} diff --git a/src/content/chapter0_basics/lesson15_lists/en.html b/src/content/chapter0_basics/lesson15_lists/en.html deleted file mode 100644 index c29758a..0000000 --- a/src/content/chapter0_basics/lesson15_lists/en.html +++ /dev/null @@ -1,19 +0,0 @@ -

- Lists are ordered collections of values. -

-

- List is a generic type, having a type parameter - for the type of values it contains. A list of ints has the type - List(Int), and a list of strings has the type - List(String). -

-

- Lists are immutable single-linked lists, meaning they are very efficient to - add and remove elements from the front of the list. -

-

- Counting the length of a list or getting elements from other positions in the - list is expensive and rarely done. It is rare to write algorithms that index - into sequences in Gleam, but when they are written a list is not the right - choice of data structure. -

diff --git a/src/content/chapter0_basics/lesson16_constants/code.gleam b/src/content/chapter0_basics/lesson16_constants/code.gleam deleted file mode 100644 index aed6fb0..0000000 --- a/src/content/chapter0_basics/lesson16_constants/code.gleam +++ /dev/null @@ -1,13 +0,0 @@ -import gleam/io - -const ints: List(Int) = [1, 2, 3] - -const floats = [1.0, 2.0, 3.0] - -pub fn main() { - io.debug(ints) - io.debug(ints == [1, 2, 3]) - - io.debug(floats) - io.debug(floats == [1.0, 2.0, 3.0]) -} diff --git a/src/content/chapter0_basics/lesson16_constants/en.html b/src/content/chapter0_basics/lesson16_constants/en.html deleted file mode 100644 index f610dcd..0000000 --- a/src/content/chapter0_basics/lesson16_constants/en.html +++ /dev/null @@ -1,18 +0,0 @@ -

- As well as let assignments Gleam also has constants, which are defined at the - top level of a module. -

-

- Constants must be literal values, functions cannot be used in their - definitions. -

-

- Constants may be useful for values that are used throughout your program, - permitting them to be named and to ensure there are no differences in the - definition between each use. -

-

- Using a constant may be more efficient than creating the same value in - multiple functions, though the exact performance characteristics will depend - on the runtime and whether compiling to Erlang or JavaScript. -

diff --git a/src/content/chapter0_basics/lesson16_lists/code.gleam b/src/content/chapter0_basics/lesson16_lists/code.gleam new file mode 100644 index 0000000..646ad6e --- /dev/null +++ b/src/content/chapter0_basics/lesson16_lists/code.gleam @@ -0,0 +1,16 @@ +import gleam/io + +pub fn main() { + let ints = [1, 2, 3] + + io.debug(ints) + + // Immutably prepend + io.debug([-1, 0, ..ints]) + + // Uncomment this to see the error + // io.debug(["zero", ..ints]) + + // The original lists are unchanged + io.debug(ints) +} diff --git a/src/content/chapter0_basics/lesson16_lists/en.html b/src/content/chapter0_basics/lesson16_lists/en.html new file mode 100644 index 0000000..c29758a --- /dev/null +++ b/src/content/chapter0_basics/lesson16_lists/en.html @@ -0,0 +1,19 @@ +

+ Lists are ordered collections of values. +

+

+ List is a generic type, having a type parameter + for the type of values it contains. A list of ints has the type + List(Int), and a list of strings has the type + List(String). +

+

+ Lists are immutable single-linked lists, meaning they are very efficient to + add and remove elements from the front of the list. +

+

+ Counting the length of a list or getting elements from other positions in the + list is expensive and rarely done. It is rare to write algorithms that index + into sequences in Gleam, but when they are written a list is not the right + choice of data structure. +

diff --git a/src/content/chapter0_basics/lesson17_constants/code.gleam b/src/content/chapter0_basics/lesson17_constants/code.gleam new file mode 100644 index 0000000..aed6fb0 --- /dev/null +++ b/src/content/chapter0_basics/lesson17_constants/code.gleam @@ -0,0 +1,13 @@ +import gleam/io + +const ints: List(Int) = [1, 2, 3] + +const floats = [1.0, 2.0, 3.0] + +pub fn main() { + io.debug(ints) + io.debug(ints == [1, 2, 3]) + + io.debug(floats) + io.debug(floats == [1.0, 2.0, 3.0]) +} diff --git a/src/content/chapter0_basics/lesson17_constants/en.html b/src/content/chapter0_basics/lesson17_constants/en.html new file mode 100644 index 0000000..f610dcd --- /dev/null +++ b/src/content/chapter0_basics/lesson17_constants/en.html @@ -0,0 +1,18 @@ +

+ As well as let assignments Gleam also has constants, which are defined at the + top level of a module. +

+

+ Constants must be literal values, functions cannot be used in their + definitions. +

+

+ Constants may be useful for values that are used throughout your program, + permitting them to be named and to ensure there are no differences in the + definition between each use. +

+

+ Using a constant may be more efficient than creating the same value in + multiple functions, though the exact performance characteristics will depend + on the runtime and whether compiling to Erlang or JavaScript. +

diff --git a/src/tour.gleam b/src/tour.gleam index e755b67..7b7272b 100644 --- a/src/tour.gleam +++ b/src/tour.gleam @@ -764,7 +764,6 @@ fn everything_page_html(chapters: List(Chapter)) -> Html { /// Renders the /everything page to a string pub fn everything_page_render(chapters: List(Chapter)) -> String { - // TODO: use proper values for location and such render_page(PageConfig( path: path_everything, title: "Everything!", -- cgit v1.2.3