aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/content/chapter0_basics/lesson12_type_aliases/code.gleam12
-rw-r--r--src/content/chapter0_basics/lesson12_type_aliases/text.html8
-rw-r--r--src/content/chapter0_basics/lesson13_blocks/code.gleam (renamed from src/content/chapter0_basics/lesson12_blocks/code.gleam)0
-rw-r--r--src/content/chapter0_basics/lesson13_blocks/text.html (renamed from src/content/chapter0_basics/lesson12_blocks/text.html)0
-rw-r--r--src/content/chapter0_basics/lesson14_lists/code.gleam (renamed from src/content/chapter0_basics/lesson13_lists/code.gleam)0
-rw-r--r--src/content/chapter0_basics/lesson14_lists/text.html (renamed from src/content/chapter0_basics/lesson13_lists/text.html)0
-rw-r--r--src/content/chapter0_basics/lesson15_constants/code.gleam13
-rw-r--r--src/content/chapter0_basics/lesson15_constants/text.html18
-rw-r--r--src/content/chapter5_advance_features/lesson00_todo/code.gleam7
-rw-r--r--src/content/chapter5_advance_features/lesson00_todo/text.html14
-rw-r--r--src/content/chapter5_advance_features/lesson01_panic/code.gleam15
-rw-r--r--src/content/chapter5_advance_features/lesson01_panic/text.html11
-rw-r--r--static/index.js3
13 files changed, 100 insertions, 1 deletions
diff --git a/src/content/chapter0_basics/lesson12_type_aliases/code.gleam b/src/content/chapter0_basics/lesson12_type_aliases/code.gleam
new file mode 100644
index 0000000..6125ffe
--- /dev/null
+++ b/src/content/chapter0_basics/lesson12_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/lesson12_type_aliases/text.html b/src/content/chapter0_basics/lesson12_type_aliases/text.html
new file mode 100644
index 0000000..9935582
--- /dev/null
+++ b/src/content/chapter0_basics/lesson12_type_aliases/text.html
@@ -0,0 +1,8 @@
+<p>
+ 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.
+</p>
+<p>
+ When the <code>pub</code> keyword is used the type alias is public and can be
+ referred to by other module.
+</p>
diff --git a/src/content/chapter0_basics/lesson12_blocks/code.gleam b/src/content/chapter0_basics/lesson13_blocks/code.gleam
index 31e4729..31e4729 100644
--- a/src/content/chapter0_basics/lesson12_blocks/code.gleam
+++ b/src/content/chapter0_basics/lesson13_blocks/code.gleam
diff --git a/src/content/chapter0_basics/lesson12_blocks/text.html b/src/content/chapter0_basics/lesson13_blocks/text.html
index bc82e39..bc82e39 100644
--- a/src/content/chapter0_basics/lesson12_blocks/text.html
+++ b/src/content/chapter0_basics/lesson13_blocks/text.html
diff --git a/src/content/chapter0_basics/lesson13_lists/code.gleam b/src/content/chapter0_basics/lesson14_lists/code.gleam
index 646ad6e..646ad6e 100644
--- a/src/content/chapter0_basics/lesson13_lists/code.gleam
+++ b/src/content/chapter0_basics/lesson14_lists/code.gleam
diff --git a/src/content/chapter0_basics/lesson13_lists/text.html b/src/content/chapter0_basics/lesson14_lists/text.html
index dd07cd7..dd07cd7 100644
--- a/src/content/chapter0_basics/lesson13_lists/text.html
+++ b/src/content/chapter0_basics/lesson14_lists/text.html
diff --git a/src/content/chapter0_basics/lesson15_constants/code.gleam b/src/content/chapter0_basics/lesson15_constants/code.gleam
new file mode 100644
index 0000000..aed6fb0
--- /dev/null
+++ b/src/content/chapter0_basics/lesson15_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/lesson15_constants/text.html b/src/content/chapter0_basics/lesson15_constants/text.html
new file mode 100644
index 0000000..f610dcd
--- /dev/null
+++ b/src/content/chapter0_basics/lesson15_constants/text.html
@@ -0,0 +1,18 @@
+<p>
+ As well as let assignments Gleam also has constants, which are defined at the
+ top level of a module.
+</p>
+<p>
+ Constants must be literal values, functions cannot be used in their
+ definitions.
+</p>
+<p>
+ 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.
+</p>
+<p>
+ 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.
+</p>
diff --git a/src/content/chapter5_advance_features/lesson00_todo/code.gleam b/src/content/chapter5_advance_features/lesson00_todo/code.gleam
new file mode 100644
index 0000000..d5abe8f
--- /dev/null
+++ b/src/content/chapter5_advance_features/lesson00_todo/code.gleam
@@ -0,0 +1,7 @@
+pub fn main() {
+ todo as "I haven't written this code yet!"
+}
+
+pub fn todo_without_reason() {
+ todo
+}
diff --git a/src/content/chapter5_advance_features/lesson00_todo/text.html b/src/content/chapter5_advance_features/lesson00_todo/text.html
new file mode 100644
index 0000000..4a2c433
--- /dev/null
+++ b/src/content/chapter5_advance_features/lesson00_todo/text.html
@@ -0,0 +1,14 @@
+<p>
+ The <code>todo</code> keyword is used to specify that some code is not yet
+ implemented.
+</p>
+<p>
+ The <code>as "some string"</code> is optional, though you may wish to include
+ the message if you have more than one code block marked as
+ <code>todo</code> in your code.
+</p>
+<p>
+ When used the Gleam compiler will print a warning to remind you the code is
+ unfinished, and if the code is run then the program will crash with the given
+ message.
+</p>
diff --git a/src/content/chapter5_advance_features/lesson01_panic/code.gleam b/src/content/chapter5_advance_features/lesson01_panic/code.gleam
new file mode 100644
index 0000000..fce9d66
--- /dev/null
+++ b/src/content/chapter5_advance_features/lesson01_panic/code.gleam
@@ -0,0 +1,15 @@
+import gleam/io
+
+pub fn main() {
+ print_score(10)
+ print_score(100_000)
+ print_score(-1)
+}
+
+pub fn print_score(score: Int) {
+ case score {
+ score if score > 1000 -> io.println("High score!")
+ score if score > 0 -> io.println("Still working on it")
+ _ -> panic as "Scores should never be negative!"
+ }
+}
diff --git a/src/content/chapter5_advance_features/lesson01_panic/text.html b/src/content/chapter5_advance_features/lesson01_panic/text.html
new file mode 100644
index 0000000..843a65b
--- /dev/null
+++ b/src/content/chapter5_advance_features/lesson01_panic/text.html
@@ -0,0 +1,11 @@
+<p>
+ The <code>panic</code> keyword is similar to <code>todo</code> keyword, but it
+ is used to crash the program when the program has reached a point that should
+ never be reached.
+</p>
+<p>
+ This keyword should almost never be used! It may be useful in initial
+ prototypes and scripts, but its use in a library or production application is
+ a sign that the design could be improved. With well designed types the type
+ system can typically be used to make these invalid states unrepresentable.
+</p>
diff --git a/static/index.js b/static/index.js
index 094011b..cfe026c 100644
--- a/static/index.js
+++ b/static/index.js
@@ -61,7 +61,8 @@ async function compileEval(project, code) {
replaceOutput(logged, "log");
} catch (error) {
console.error(error);
- replaceOutput(error.toString(), "error");
+ replaceOutput(logged, "log");
+ appendOutput(error.toString(), "error");
}
for (const warning of project.takeWarnings()) {
appendOutput(warning, "warning");