From 1aa782ae22aa55d44ba4ed01ad447915dc7802cb Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 23 Jan 2024 14:41:22 +0000 Subject: Add equality lesson --- .../chapter0_basics/lesson07_equality/code.gleam | 6 ++++++ .../chapter0_basics/lesson07_equality/text.html | 13 ++++++++++++ .../chapter0_basics/lesson07_strings/code.gleam | 23 ---------------------- .../chapter0_basics/lesson07_strings/text.html | 23 ---------------------- .../chapter0_basics/lesson08_bools/code.gleam | 14 ------------- .../chapter0_basics/lesson08_bools/text.html | 17 ---------------- .../chapter0_basics/lesson08_strings/code.gleam | 23 ++++++++++++++++++++++ .../chapter0_basics/lesson08_strings/text.html | 23 ++++++++++++++++++++++ .../lesson09_assignments/code.gleam | 17 ---------------- .../chapter0_basics/lesson09_assignments/text.html | 8 -------- .../chapter0_basics/lesson09_bools/code.gleam | 14 +++++++++++++ .../chapter0_basics/lesson09_bools/text.html | 17 ++++++++++++++++ .../lesson10_assignments/code.gleam | 17 ++++++++++++++++ .../chapter0_basics/lesson10_assignments/text.html | 8 ++++++++ .../lesson10_discard_patterns/code.gleam | 4 ---- .../lesson10_discard_patterns/text.html | 10 ---------- .../lesson11_discard_patterns/code.gleam | 4 ++++ .../lesson11_discard_patterns/text.html | 10 ++++++++++ .../lesson11_type_annotations/code.gleam | 7 ------- .../lesson11_type_annotations/text.html | 15 -------------- .../lesson12_type_aliases/code.gleam | 12 ----------- .../lesson12_type_aliases/text.html | 8 -------- .../lesson12_type_annotations/code.gleam | 7 +++++++ .../lesson12_type_annotations/text.html | 15 ++++++++++++++ .../chapter0_basics/lesson13_blocks/code.gleam | 13 ------------ .../chapter0_basics/lesson13_blocks/text.html | 23 ---------------------- .../lesson13_type_aliases/code.gleam | 12 +++++++++++ .../lesson13_type_aliases/text.html | 8 ++++++++ .../chapter0_basics/lesson14_blocks/code.gleam | 13 ++++++++++++ .../chapter0_basics/lesson14_blocks/text.html | 23 ++++++++++++++++++++++ .../chapter0_basics/lesson14_lists/code.gleam | 16 --------------- .../chapter0_basics/lesson14_lists/text.html | 19 ------------------ .../chapter0_basics/lesson15_constants/code.gleam | 13 ------------ .../chapter0_basics/lesson15_constants/text.html | 18 ----------------- .../chapter0_basics/lesson15_lists/code.gleam | 16 +++++++++++++++ .../chapter0_basics/lesson15_lists/text.html | 19 ++++++++++++++++++ .../chapter0_basics/lesson16_constants/code.gleam | 13 ++++++++++++ .../chapter0_basics/lesson16_constants/text.html | 18 +++++++++++++++++ 38 files changed, 279 insertions(+), 260 deletions(-) create mode 100644 src/content/chapter0_basics/lesson07_equality/code.gleam create mode 100644 src/content/chapter0_basics/lesson07_equality/text.html delete mode 100644 src/content/chapter0_basics/lesson07_strings/code.gleam delete mode 100644 src/content/chapter0_basics/lesson07_strings/text.html delete mode 100644 src/content/chapter0_basics/lesson08_bools/code.gleam delete mode 100644 src/content/chapter0_basics/lesson08_bools/text.html create mode 100644 src/content/chapter0_basics/lesson08_strings/code.gleam create mode 100644 src/content/chapter0_basics/lesson08_strings/text.html delete mode 100644 src/content/chapter0_basics/lesson09_assignments/code.gleam delete mode 100644 src/content/chapter0_basics/lesson09_assignments/text.html create mode 100644 src/content/chapter0_basics/lesson09_bools/code.gleam create mode 100644 src/content/chapter0_basics/lesson09_bools/text.html create mode 100644 src/content/chapter0_basics/lesson10_assignments/code.gleam create mode 100644 src/content/chapter0_basics/lesson10_assignments/text.html delete mode 100644 src/content/chapter0_basics/lesson10_discard_patterns/code.gleam delete mode 100644 src/content/chapter0_basics/lesson10_discard_patterns/text.html create mode 100644 src/content/chapter0_basics/lesson11_discard_patterns/code.gleam create mode 100644 src/content/chapter0_basics/lesson11_discard_patterns/text.html delete mode 100644 src/content/chapter0_basics/lesson11_type_annotations/code.gleam delete mode 100644 src/content/chapter0_basics/lesson11_type_annotations/text.html delete mode 100644 src/content/chapter0_basics/lesson12_type_aliases/code.gleam delete mode 100644 src/content/chapter0_basics/lesson12_type_aliases/text.html create mode 100644 src/content/chapter0_basics/lesson12_type_annotations/code.gleam create mode 100644 src/content/chapter0_basics/lesson12_type_annotations/text.html delete mode 100644 src/content/chapter0_basics/lesson13_blocks/code.gleam delete mode 100644 src/content/chapter0_basics/lesson13_blocks/text.html create mode 100644 src/content/chapter0_basics/lesson13_type_aliases/code.gleam create mode 100644 src/content/chapter0_basics/lesson13_type_aliases/text.html create mode 100644 src/content/chapter0_basics/lesson14_blocks/code.gleam create mode 100644 src/content/chapter0_basics/lesson14_blocks/text.html delete mode 100644 src/content/chapter0_basics/lesson14_lists/code.gleam delete mode 100644 src/content/chapter0_basics/lesson14_lists/text.html delete mode 100644 src/content/chapter0_basics/lesson15_constants/code.gleam delete mode 100644 src/content/chapter0_basics/lesson15_constants/text.html create mode 100644 src/content/chapter0_basics/lesson15_lists/code.gleam create mode 100644 src/content/chapter0_basics/lesson15_lists/text.html create mode 100644 src/content/chapter0_basics/lesson16_constants/code.gleam create mode 100644 src/content/chapter0_basics/lesson16_constants/text.html (limited to 'src') diff --git a/src/content/chapter0_basics/lesson07_equality/code.gleam b/src/content/chapter0_basics/lesson07_equality/code.gleam new file mode 100644 index 0000000..70a2b89 --- /dev/null +++ b/src/content/chapter0_basics/lesson07_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/lesson07_equality/text.html b/src/content/chapter0_basics/lesson07_equality/text.html new file mode 100644 index 0000000..e8c2169 --- /dev/null +++ b/src/content/chapter0_basics/lesson07_equality/text.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/lesson07_strings/code.gleam b/src/content/chapter0_basics/lesson07_strings/code.gleam deleted file mode 100644 index ea47e0f..0000000 --- a/src/content/chapter0_basics/lesson07_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/lesson07_strings/text.html b/src/content/chapter0_basics/lesson07_strings/text.html deleted file mode 100644 index e5400ca..0000000 --- a/src/content/chapter0_basics/lesson07_strings/text.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/lesson08_bools/code.gleam b/src/content/chapter0_basics/lesson08_bools/code.gleam deleted file mode 100644 index e5c1d98..0000000 --- a/src/content/chapter0_basics/lesson08_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/lesson08_bools/text.html b/src/content/chapter0_basics/lesson08_bools/text.html deleted file mode 100644 index 3f60743..0000000 --- a/src/content/chapter0_basics/lesson08_bools/text.html +++ /dev/null @@ -1,17 +0,0 @@ -

- A Bool is a 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/lesson08_strings/code.gleam b/src/content/chapter0_basics/lesson08_strings/code.gleam new file mode 100644 index 0000000..ea47e0f --- /dev/null +++ b/src/content/chapter0_basics/lesson08_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/lesson08_strings/text.html b/src/content/chapter0_basics/lesson08_strings/text.html new file mode 100644 index 0000000..e5400ca --- /dev/null +++ b/src/content/chapter0_basics/lesson08_strings/text.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/lesson09_assignments/code.gleam b/src/content/chapter0_basics/lesson09_assignments/code.gleam deleted file mode 100644 index a030e43..0000000 --- a/src/content/chapter0_basics/lesson09_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/lesson09_assignments/text.html b/src/content/chapter0_basics/lesson09_assignments/text.html deleted file mode 100644 index 6d535de..0000000 --- a/src/content/chapter0_basics/lesson09_assignments/text.html +++ /dev/null @@ -1,8 +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. -

diff --git a/src/content/chapter0_basics/lesson09_bools/code.gleam b/src/content/chapter0_basics/lesson09_bools/code.gleam new file mode 100644 index 0000000..e5c1d98 --- /dev/null +++ b/src/content/chapter0_basics/lesson09_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/lesson09_bools/text.html b/src/content/chapter0_basics/lesson09_bools/text.html new file mode 100644 index 0000000..3f60743 --- /dev/null +++ b/src/content/chapter0_basics/lesson09_bools/text.html @@ -0,0 +1,17 @@ +

+ A Bool is a 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/lesson10_assignments/code.gleam b/src/content/chapter0_basics/lesson10_assignments/code.gleam new file mode 100644 index 0000000..a030e43 --- /dev/null +++ b/src/content/chapter0_basics/lesson10_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/lesson10_assignments/text.html b/src/content/chapter0_basics/lesson10_assignments/text.html new file mode 100644 index 0000000..6d535de --- /dev/null +++ b/src/content/chapter0_basics/lesson10_assignments/text.html @@ -0,0 +1,8 @@ +

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

diff --git a/src/content/chapter0_basics/lesson10_discard_patterns/code.gleam b/src/content/chapter0_basics/lesson10_discard_patterns/code.gleam deleted file mode 100644 index fa2c0e3..0000000 --- a/src/content/chapter0_basics/lesson10_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/lesson10_discard_patterns/text.html b/src/content/chapter0_basics/lesson10_discard_patterns/text.html deleted file mode 100644 index 46dc79b..0000000 --- a/src/content/chapter0_basics/lesson10_discard_patterns/text.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 not to be use 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/lesson11_discard_patterns/code.gleam b/src/content/chapter0_basics/lesson11_discard_patterns/code.gleam new file mode 100644 index 0000000..fa2c0e3 --- /dev/null +++ b/src/content/chapter0_basics/lesson11_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/lesson11_discard_patterns/text.html b/src/content/chapter0_basics/lesson11_discard_patterns/text.html new file mode 100644 index 0000000..46dc79b --- /dev/null +++ b/src/content/chapter0_basics/lesson11_discard_patterns/text.html @@ -0,0 +1,10 @@ +

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

+

+ If a variable is intended not to be use 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/lesson11_type_annotations/code.gleam b/src/content/chapter0_basics/lesson11_type_annotations/code.gleam deleted file mode 100644 index 1299c2f..0000000 --- a/src/content/chapter0_basics/lesson11_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/lesson11_type_annotations/text.html b/src/content/chapter0_basics/lesson11_type_annotations/text.html deleted file mode 100644 index 8738a15..0000000 --- a/src/content/chapter0_basics/lesson11_type_annotations/text.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/lesson12_type_aliases/code.gleam b/src/content/chapter0_basics/lesson12_type_aliases/code.gleam deleted file mode 100644 index 6125ffe..0000000 --- a/src/content/chapter0_basics/lesson12_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/lesson12_type_aliases/text.html b/src/content/chapter0_basics/lesson12_type_aliases/text.html deleted file mode 100644 index 6767faf..0000000 --- a/src/content/chapter0_basics/lesson12_type_aliases/text.html +++ /dev/null @@ -1,8 +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. -

-

- 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/lesson12_type_annotations/code.gleam b/src/content/chapter0_basics/lesson12_type_annotations/code.gleam new file mode 100644 index 0000000..1299c2f --- /dev/null +++ b/src/content/chapter0_basics/lesson12_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/lesson12_type_annotations/text.html b/src/content/chapter0_basics/lesson12_type_annotations/text.html new file mode 100644 index 0000000..8738a15 --- /dev/null +++ b/src/content/chapter0_basics/lesson12_type_annotations/text.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/lesson13_blocks/code.gleam b/src/content/chapter0_basics/lesson13_blocks/code.gleam deleted file mode 100644 index 31e4729..0000000 --- a/src/content/chapter0_basics/lesson13_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/lesson13_blocks/text.html b/src/content/chapter0_basics/lesson13_blocks/text.html deleted file mode 100644 index bc82e39..0000000 --- a/src/content/chapter0_basics/lesson13_blocks/text.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/lesson13_type_aliases/code.gleam b/src/content/chapter0_basics/lesson13_type_aliases/code.gleam new file mode 100644 index 0000000..6125ffe --- /dev/null +++ b/src/content/chapter0_basics/lesson13_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/lesson13_type_aliases/text.html b/src/content/chapter0_basics/lesson13_type_aliases/text.html new file mode 100644 index 0000000..6767faf --- /dev/null +++ b/src/content/chapter0_basics/lesson13_type_aliases/text.html @@ -0,0 +1,8 @@ +

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

+

+ 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/lesson14_blocks/code.gleam b/src/content/chapter0_basics/lesson14_blocks/code.gleam new file mode 100644 index 0000000..31e4729 --- /dev/null +++ b/src/content/chapter0_basics/lesson14_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/lesson14_blocks/text.html b/src/content/chapter0_basics/lesson14_blocks/text.html new file mode 100644 index 0000000..bc82e39 --- /dev/null +++ b/src/content/chapter0_basics/lesson14_blocks/text.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/lesson14_lists/code.gleam b/src/content/chapter0_basics/lesson14_lists/code.gleam deleted file mode 100644 index 646ad6e..0000000 --- a/src/content/chapter0_basics/lesson14_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/lesson14_lists/text.html b/src/content/chapter0_basics/lesson14_lists/text.html deleted file mode 100644 index c29758a..0000000 --- a/src/content/chapter0_basics/lesson14_lists/text.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/lesson15_constants/code.gleam b/src/content/chapter0_basics/lesson15_constants/code.gleam deleted file mode 100644 index aed6fb0..0000000 --- a/src/content/chapter0_basics/lesson15_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/lesson15_constants/text.html b/src/content/chapter0_basics/lesson15_constants/text.html deleted file mode 100644 index f610dcd..0000000 --- a/src/content/chapter0_basics/lesson15_constants/text.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/lesson15_lists/code.gleam b/src/content/chapter0_basics/lesson15_lists/code.gleam new file mode 100644 index 0000000..646ad6e --- /dev/null +++ b/src/content/chapter0_basics/lesson15_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/lesson15_lists/text.html b/src/content/chapter0_basics/lesson15_lists/text.html new file mode 100644 index 0000000..c29758a --- /dev/null +++ b/src/content/chapter0_basics/lesson15_lists/text.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/lesson16_constants/code.gleam b/src/content/chapter0_basics/lesson16_constants/code.gleam new file mode 100644 index 0000000..aed6fb0 --- /dev/null +++ b/src/content/chapter0_basics/lesson16_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/lesson16_constants/text.html b/src/content/chapter0_basics/lesson16_constants/text.html new file mode 100644 index 0000000..f610dcd --- /dev/null +++ b/src/content/chapter0_basics/lesson16_constants/text.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. +

-- cgit v1.2.3