Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/dark-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ffigiel committed Mar 5, 2024
2 parents e4de966 + e1d6c11 commit 9be1568
Show file tree
Hide file tree
Showing 67 changed files with 76 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bin/download-compiler
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

VERSION="v0.34.1"
VERSION="v1.0.0"

rm -fr wasm-compiler
mkdir wasm-compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn main() {
io.debug(twice("Hello", exclaim))
}

// The name `value` refers to the same type multiple times
fn twice(argument: value, function: fn(value) -> value) -> value {
function(function(argument))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
attribute.
</p>
<p>
If a deprecated function is reference the compiler will emit a warning,
If a deprecated function is referenced the compiler will emit a warning,
letting the programmer know they ought to update their code.
</p>
<p>
The deprecation attribute takes a message and this will be displayed to the
user in the warning. In the message explain to the user the new approach or
replacement function, or direct them on documentation on how to upgrade.
replacement function, or direct them to documentation on how to upgrade.
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn factorial_loop(x: Int, accumulator: Int) -> Int {
1 -> accumulator

// The last thing this function does is call itself
// In the previous lesson the last thing it did was multiple two ints
// In the previous lesson the last thing it did was multiply two ints
_ -> factorial_loop(x - 1, accumulator * x)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p>
Most commonly functions in the
While it is more common to use functions in the
<a href="https://hexdocs.pm/gleam_stdlib/gleam/list.html"
><code>gleam/list</code></a
>
module are used to iterate across a list, but at times you may prefer to work
module to iterate across a list, at times you may prefer to work
with the list directly.
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
and <code>#(1.4, 10, 48)</code> has the type <code>#(Float, Int, Int)</code>.
</p>
<p>
Tuples are most commonly used to return 2 or 3 values from a function. Other
times it is often is clearer to use a <em>custom type</em>, which we will
cover next.
Tuples are most commonly used to return 2 or 3 values from a function.
Often it is clearer to use a <em>custom type</em> where a tuple could
be used, We will cover custom types next.
</p>
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<p>Variants of a record can hold other data within them.</p>
<p>
These fields can be given labels, and like function argument labels they can
A variant of a custom type can hold other data within it. In this case
the variant is called a record.
</p>
<p>
The fields of a record can be given labels, and like function argument labels they can
be optionally used when calling the record constructor. Typically labels will
be used for variants that define them.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
failure.
</p>
<p>
Commonly Gleam programs and library will define custom types with a variant
Commonly a Gleam program or library will define a custom type with a variant
for each possible problem that can arise, along with any error information
that would be useful to the programmer.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
</ul>
<p>
Bit arrays have limited support when compiling to JavaScript, not all options
can be used. Full bit array support will be implemented in future.
can be used. Full bit array support will be implemented in the future.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import gleam/io

pub fn main() {
let a = unsafely_get_first_element([123])
io.debug(a)

let b = unsafely_get_first_element([])
io.debug(b)
}

pub fn unsafely_get_first_element(items: List(a)) -> a {
// This will panic if the list is empty.
// A regular `let` would not permit this partial pattern
let assert [first, ..] = items
first
}
15 changes: 15 additions & 0 deletions src/content/chapter5_advanced_features/lesson04_let_assert/en.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p>
<code>let assert</code> is the final way to intentionally crash your Gleam
program. It is similar to the <code>panic</code> keyword in that it crashes
when the program has reached a point that should never be reached.
</p>
<p>
<code>let assert</code> is similar to <code>let</code> in that it is a way to
assign values to variables, but it is different in that the pattern can be
<i>partial</i>. The pattern does not need to match every possible value of the
type being assigned.
</p>
<p>
Like <code>panic</code> this feature should be used sparingly, and likely not
at all in libraries.
</p>
20 changes: 15 additions & 5 deletions src/tour.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ const what_next_html = "
</p>
<p>
Read the <a href=\"https://gleam.run/getting-started/\">Gleam getting started
documentation</a> to learn more about the language and its tooling.
Read the <a href=\"https://gleam.run/writing-gleam\">Writing Gleam
guide</a> to learn how to create and develop a Gleam project.
</p>
<p>
Join the <a href=\"https://discord.gg/Fm8Pwmy\">the Gleam Discord server</a>
Expand Down Expand Up @@ -184,7 +184,7 @@ fn read_file(path: String) -> snag.Result(String) {

fn load_lesson(chapter_path: String, names: FileNames) -> snag.Result(Lesson) {
use code <- result.try(read_file(names.path <> "/code.gleam"))
use text <- result.try(read_file(names.path <> "/text.html"))
use text <- result.try(read_file(names.path <> "/en.html"))

Ok(Lesson(
name: names.name,
Expand Down Expand Up @@ -540,7 +540,7 @@ fn lesson_html(page: Lesson) -> String {
metaprop("twitter:title", title),
metaprop("twitter:description", description),
metaprop("twitter:image", "https://gleam.run/images/og-image.png"),
link("shortcut icon", "https://gleam.run/images/lucy-circle.svg"),
link("shortcut icon", "https://gleam.run/images/lucy/lucy.svg"),
link("stylesheet", "/common.css"),
link("stylesheet", "/style.css"),
h(
Expand All @@ -560,7 +560,17 @@ fn lesson_html(page: Lesson) -> String {
]),
h("body", [], [
h("nav", [#("class", "navbar")], [
h("a", [#("href", "/")], [text("Gleam Language Tour")]),
h("a", [#("href", "/"), #("class", "logo")], [
h(
"img",
[
#("src", "https://gleam.run/images/lucy/lucy.svg"),
#("alt", "Lucy the star, Gleam's mascot"),
],
[],
),
text("Gleam Language Tour"),
]),
h("div", [#("class", "nav-right")], [
h("div", [#("class", "theme-picker")], [
h(
Expand Down
12 changes: 12 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ a code {
color: inherit;
}

.navbar .logo {
display: flex;
align-items: center;
}

.navbar .logo img {
display: inline-block;
height: 2em;
transform: rotate(-10deg);
margin-right: 0.5em;
}

.navbar a:visited,
.navbar a {
text-decoration: none;
Expand Down
6 changes: 1 addition & 5 deletions static/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ console.log = (...args) => {
logged += args.map((e) => `${e}`).join(" ") + "\n";
};

function resetLogCapture() {
logged = "";
}

async function loadProgram(js) {
const url = new URL(import.meta.url);
url.pathname = "";
Expand All @@ -36,6 +32,7 @@ async function loadProgram(js) {
}

async function compileEval(code) {
logged = "";
const result = {
log: null,
error: null,
Expand All @@ -47,7 +44,6 @@ async function compileEval(code) {
project.compilePackage("javascript");
const js = project.readCompiledJavaScript("main");
const main = await loadProgram(js);
resetLogCapture();
if (main) main();
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 9be1568

Please sign in to comment.