From b892cf1523908b2d94348b32038ab87865b70541 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Mon, 29 Jul 2024 15:34:19 +0100 Subject: [PATCH 1/3] Label shorthand --- .../lesson09_label_shorthand/code.gleam | 19 +++++++++++++++++++ .../lesson09_label_shorthand/en.html | 11 +++++++++++ .../code.gleam | 0 .../en.html | 0 .../code.gleam | 0 .../en.html | 0 6 files changed, 30 insertions(+) create mode 100644 src/content/chapter1_functions/lesson09_label_shorthand/code.gleam create mode 100644 src/content/chapter1_functions/lesson09_label_shorthand/en.html rename src/content/chapter1_functions/{lesson09_documentation_comments => lesson10_documentation_comments}/code.gleam (100%) rename src/content/chapter1_functions/{lesson09_documentation_comments => lesson10_documentation_comments}/en.html (100%) rename src/content/chapter1_functions/{lesson10_deprecations => lesson11_deprecations}/code.gleam (100%) rename src/content/chapter1_functions/{lesson10_deprecations => lesson11_deprecations}/en.html (100%) diff --git a/src/content/chapter1_functions/lesson09_label_shorthand/code.gleam b/src/content/chapter1_functions/lesson09_label_shorthand/code.gleam new file mode 100644 index 0000000..a2eb730 --- /dev/null +++ b/src/content/chapter1_functions/lesson09_label_shorthand/code.gleam @@ -0,0 +1,19 @@ +import gleam/io + +pub fn main() { + let title = "Chapter 1" + let content = + "Brownie caramels pastry danish candy lollipop soufflé dragée bonbon." + + // Using labels + print(title: title, content: content) + + // Using the labels shorthand + print(title:, content:) +} + +fn print(title title: String, content content: String) -> Nil { + io.println("# " <> title) + io.println("") + io.println(content) +} diff --git a/src/content/chapter1_functions/lesson09_label_shorthand/en.html b/src/content/chapter1_functions/lesson09_label_shorthand/en.html new file mode 100644 index 0000000..9c2afc8 --- /dev/null +++ b/src/content/chapter1_functions/lesson09_label_shorthand/en.html @@ -0,0 +1,11 @@ +

+ Gleam v1.4.0 introduced the _label shorthand_, a more concise syntax for using + a variable with a label of the same name. +

+

+ To use it omit the name of the variable to the right on the `:` for the label. +

+

+ For example, `document(title:, content:)` is the same as `document(title: + title, content: content)`. +

diff --git a/src/content/chapter1_functions/lesson09_documentation_comments/code.gleam b/src/content/chapter1_functions/lesson10_documentation_comments/code.gleam similarity index 100% rename from src/content/chapter1_functions/lesson09_documentation_comments/code.gleam rename to src/content/chapter1_functions/lesson10_documentation_comments/code.gleam diff --git a/src/content/chapter1_functions/lesson09_documentation_comments/en.html b/src/content/chapter1_functions/lesson10_documentation_comments/en.html similarity index 100% rename from src/content/chapter1_functions/lesson09_documentation_comments/en.html rename to src/content/chapter1_functions/lesson10_documentation_comments/en.html diff --git a/src/content/chapter1_functions/lesson10_deprecations/code.gleam b/src/content/chapter1_functions/lesson11_deprecations/code.gleam similarity index 100% rename from src/content/chapter1_functions/lesson10_deprecations/code.gleam rename to src/content/chapter1_functions/lesson11_deprecations/code.gleam diff --git a/src/content/chapter1_functions/lesson10_deprecations/en.html b/src/content/chapter1_functions/lesson11_deprecations/en.html similarity index 100% rename from src/content/chapter1_functions/lesson10_deprecations/en.html rename to src/content/chapter1_functions/lesson11_deprecations/en.html From 2b7e4357005fdf2033f1867967093cdf639eacab Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Mon, 29 Jul 2024 15:36:22 +0100 Subject: [PATCH 2/3] Update CI version --- .github/workflows/deploy.yml | 2 +- .github/workflows/test.yml | 2 +- bin/download-compiler | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 69570e0..50a6b6a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,7 +27,7 @@ jobs: - uses: erlef/setup-beam@v1 with: otp-version: "26.0.2" - gleam-version: "1.3.2" + gleam-version: "1.4.0-rc1" rebar3-version: "3" - name: Download WASM version of Gleam compiler diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aca746d..5a40a9b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: with: otp-version: "26.0.2" # Ensure you update the bin/download-compiler Gleam version to match this - gleam-version: "1.3.2" + gleam-version: "1.4.0-rc1" rebar3-version: "3" - run: ./bin/download-compiler - run: gleam deps download diff --git a/bin/download-compiler b/bin/download-compiler index 58a81c7..d757a4d 100755 --- a/bin/download-compiler +++ b/bin/download-compiler @@ -3,7 +3,7 @@ set -eu # Ensure you update the CI Gleam version to match this -VERSION="v1.3.2" +VERSION="v1.4.0-rc1" rm -fr wasm-compiler mkdir wasm-compiler From 1255696b3868333927d83636fb970bd1006bfdf5 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Mon, 29 Jul 2024 15:43:18 +0100 Subject: [PATCH 3/3] Record label shorthand --- .../code.gleam | 21 +++++++++++++++++++ .../lesson05_record_label_shorthand/en.html | 7 +++++++ .../code.gleam | 0 .../en.html | 0 .../code.gleam | 0 .../en.html | 0 .../{lesson07_nil => lesson08_nil}/code.gleam | 0 .../{lesson07_nil => lesson08_nil}/en.html | 0 .../code.gleam | 0 .../en.html | 0 .../code.gleam | 0 .../en.html | 0 12 files changed, 28 insertions(+) create mode 100644 src/content/chapter3_data_types/lesson05_record_label_shorthand/code.gleam create mode 100644 src/content/chapter3_data_types/lesson05_record_label_shorthand/en.html rename src/content/chapter3_data_types/{lesson05_record_updates => lesson06_record_updates}/code.gleam (100%) rename src/content/chapter3_data_types/{lesson05_record_updates => lesson06_record_updates}/en.html (100%) rename src/content/chapter3_data_types/{lesson06_generic_custom_types => lesson07_generic_custom_types}/code.gleam (100%) rename src/content/chapter3_data_types/{lesson06_generic_custom_types => lesson07_generic_custom_types}/en.html (100%) rename src/content/chapter3_data_types/{lesson07_nil => lesson08_nil}/code.gleam (100%) rename src/content/chapter3_data_types/{lesson07_nil => lesson08_nil}/en.html (100%) rename src/content/chapter3_data_types/{lesson08_results => lesson09_results}/code.gleam (100%) rename src/content/chapter3_data_types/{lesson08_results => lesson09_results}/en.html (100%) rename src/content/chapter3_data_types/{lesson09_bit_arrays => lesson10_bit_arrays}/code.gleam (100%) rename src/content/chapter3_data_types/{lesson09_bit_arrays => lesson10_bit_arrays}/en.html (100%) diff --git a/src/content/chapter3_data_types/lesson05_record_label_shorthand/code.gleam b/src/content/chapter3_data_types/lesson05_record_label_shorthand/code.gleam new file mode 100644 index 0000000..5cff265 --- /dev/null +++ b/src/content/chapter3_data_types/lesson05_record_label_shorthand/code.gleam @@ -0,0 +1,21 @@ +import gleam/io + +pub type Trainer { + Trainer(name: String, badges: Int) +} + +fn new_trainer(name: String) -> Trainer { + Trainer(name:, badges: 0) +} + +fn greet(trainer: Trainer) -> String { + case trainer { + Trainer(badges: 8, ..) -> "Wow, you've got all the badges!" + Trainer(name:, ..) -> "Hello " <> name <> "!" + } +} + +pub fn main() { + let trainer = new_trainer("Sarah") + io.println(greet(trainer)) +} diff --git a/src/content/chapter3_data_types/lesson05_record_label_shorthand/en.html b/src/content/chapter3_data_types/lesson05_record_label_shorthand/en.html new file mode 100644 index 0000000..3a0f4f8 --- /dev/null +++ b/src/content/chapter3_data_types/lesson05_record_label_shorthand/en.html @@ -0,0 +1,7 @@ +

+ The label shorthand previously seen with functions can also be used with + records, both when constructing them and when pattern matching. +

+

+ `Player(name:, score:)` is the same as `Player(name: name, score: score)`. +

diff --git a/src/content/chapter3_data_types/lesson05_record_updates/code.gleam b/src/content/chapter3_data_types/lesson06_record_updates/code.gleam similarity index 100% rename from src/content/chapter3_data_types/lesson05_record_updates/code.gleam rename to src/content/chapter3_data_types/lesson06_record_updates/code.gleam diff --git a/src/content/chapter3_data_types/lesson05_record_updates/en.html b/src/content/chapter3_data_types/lesson06_record_updates/en.html similarity index 100% rename from src/content/chapter3_data_types/lesson05_record_updates/en.html rename to src/content/chapter3_data_types/lesson06_record_updates/en.html diff --git a/src/content/chapter3_data_types/lesson06_generic_custom_types/code.gleam b/src/content/chapter3_data_types/lesson07_generic_custom_types/code.gleam similarity index 100% rename from src/content/chapter3_data_types/lesson06_generic_custom_types/code.gleam rename to src/content/chapter3_data_types/lesson07_generic_custom_types/code.gleam diff --git a/src/content/chapter3_data_types/lesson06_generic_custom_types/en.html b/src/content/chapter3_data_types/lesson07_generic_custom_types/en.html similarity index 100% rename from src/content/chapter3_data_types/lesson06_generic_custom_types/en.html rename to src/content/chapter3_data_types/lesson07_generic_custom_types/en.html diff --git a/src/content/chapter3_data_types/lesson07_nil/code.gleam b/src/content/chapter3_data_types/lesson08_nil/code.gleam similarity index 100% rename from src/content/chapter3_data_types/lesson07_nil/code.gleam rename to src/content/chapter3_data_types/lesson08_nil/code.gleam diff --git a/src/content/chapter3_data_types/lesson07_nil/en.html b/src/content/chapter3_data_types/lesson08_nil/en.html similarity index 100% rename from src/content/chapter3_data_types/lesson07_nil/en.html rename to src/content/chapter3_data_types/lesson08_nil/en.html diff --git a/src/content/chapter3_data_types/lesson08_results/code.gleam b/src/content/chapter3_data_types/lesson09_results/code.gleam similarity index 100% rename from src/content/chapter3_data_types/lesson08_results/code.gleam rename to src/content/chapter3_data_types/lesson09_results/code.gleam diff --git a/src/content/chapter3_data_types/lesson08_results/en.html b/src/content/chapter3_data_types/lesson09_results/en.html similarity index 100% rename from src/content/chapter3_data_types/lesson08_results/en.html rename to src/content/chapter3_data_types/lesson09_results/en.html diff --git a/src/content/chapter3_data_types/lesson09_bit_arrays/code.gleam b/src/content/chapter3_data_types/lesson10_bit_arrays/code.gleam similarity index 100% rename from src/content/chapter3_data_types/lesson09_bit_arrays/code.gleam rename to src/content/chapter3_data_types/lesson10_bit_arrays/code.gleam diff --git a/src/content/chapter3_data_types/lesson09_bit_arrays/en.html b/src/content/chapter3_data_types/lesson10_bit_arrays/en.html similarity index 100% rename from src/content/chapter3_data_types/lesson09_bit_arrays/en.html rename to src/content/chapter3_data_types/lesson10_bit_arrays/en.html