Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gleam v1.4.0 #122

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/download-compiler
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/content/chapter1_functions/lesson09_label_shorthand/code.gleam
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 11 additions & 0 deletions src/content/chapter1_functions/lesson09_label_shorthand/en.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p>
Gleam v1.4.0 introduced the _label shorthand_, a more concise syntax for using
a variable with a label of the same name.
</p>
<p>
To use it omit the name of the variable to the right on the `:` for the label.
</p>
<p>
For example, `document(title:, content:)` is the same as `document(title:
title, content: content)`.
</p>
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>
The label shorthand previously seen with functions can also be used with
records, both when constructing them and when pattern matching.
</p>
<p>
`Player(name:, score:)` is the same as `Player(name: name, score: score)`.
</p>
Loading