From e66db486ffa57a1ce68a85ab6cb7bfbb05e260b8 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Mon, 4 Dec 2023 17:05:51 +0000 Subject: Start content --- lessons/src/lesson000_hello_world/text.html | 4 ++-- lessons/src/lesson001_basics/code.gleam | 4 +++- lessons/src/lesson001_basics/text.html | 16 +++++++++++++++- lessons/src/lesson002_another/code.gleam | 5 ----- lessons/src/lesson002_another/text.html | 8 -------- lessons/src/lesson002_unqualified_imports/code.gleam | 10 ++++++++++ lessons/src/lesson002_unqualified_imports/text.html | 15 +++++++++++++++ lessons/src/lesson003_type_checking/code.gleam | 7 +++++++ lessons/src/lesson003_type_checking/text.html | 19 +++++++++++++++++++ lessons/src/lesson004_ints/code.gleam | 16 ++++++++++++++++ lessons/src/lesson004_ints/text.html | 2 ++ 11 files changed, 89 insertions(+), 17 deletions(-) delete mode 100644 lessons/src/lesson002_another/code.gleam delete mode 100644 lessons/src/lesson002_another/text.html create mode 100644 lessons/src/lesson002_unqualified_imports/code.gleam create mode 100644 lessons/src/lesson002_unqualified_imports/text.html create mode 100644 lessons/src/lesson003_type_checking/code.gleam create mode 100644 lessons/src/lesson003_type_checking/text.html create mode 100644 lessons/src/lesson004_ints/code.gleam create mode 100644 lessons/src/lesson004_ints/text.html (limited to 'lessons/src') diff --git a/lessons/src/lesson000_hello_world/text.html b/lessons/src/lesson000_hello_world/text.html index 46e3fc2..cb41be9 100644 --- a/lessons/src/lesson000_hello_world/text.html +++ b/lessons/src/lesson000_hello_world/text.html @@ -10,8 +10,8 @@

The tour is interactive! The code shown is editable and will be compiled and evaluated as you type. Anything you print using io.println or - io.debug will be shown in the lower right, along with any compile - errors and warnings. To evaluate Gleam code the tour compiles Gleam to + io.debug will be shown in the bottom section, along with any + compile errors and warnings. To evaluate Gleam code the tour compiles Gleam to JavaScript and runs it, all entirely within your browser window.

diff --git a/lessons/src/lesson001_basics/code.gleam b/lessons/src/lesson001_basics/code.gleam index 440dc98..67cc6b4 100644 --- a/lessons/src/lesson001_basics/code.gleam +++ b/lessons/src/lesson001_basics/code.gleam @@ -1,5 +1,7 @@ +// Import a Gleam module from the standard library import gleam/io pub fn main() { - io.println("Hello, Mike!") + // Print to the console + io.println("Hello, Joe!") } diff --git a/lessons/src/lesson001_basics/text.html b/lessons/src/lesson001_basics/text.html index 53bd3d3..8e2033a 100644 --- a/lessons/src/lesson001_basics/text.html +++ b/lessons/src/lesson001_basics/text.html @@ -1,3 +1,17 @@

- Hey look, cool stuff! + Here is a program that prints out the text "Hello, Joe!". +

+

+ It does this by using the `println` function which has been imported from the + gleam/io + module, which is part of the Gleam standard library. +

+

+ In a normal Gleam program this program would be run use the command + gleam run on the command line, but here in this tutorial the + program is automatically compiled and run as the code is edited. +

+

+ Try changing the text being printed to Hello, Mike! and see what + happens.

diff --git a/lessons/src/lesson002_another/code.gleam b/lessons/src/lesson002_another/code.gleam deleted file mode 100644 index 440dc98..0000000 --- a/lessons/src/lesson002_another/code.gleam +++ /dev/null @@ -1,5 +0,0 @@ -import gleam/io - -pub fn main() { - io.println("Hello, Mike!") -} diff --git a/lessons/src/lesson002_another/text.html b/lessons/src/lesson002_another/text.html deleted file mode 100644 index 850d151..0000000 --- a/lessons/src/lesson002_another/text.html +++ /dev/null @@ -1,8 +0,0 @@ -

- Lorem ipsum dolor sit amet consectetur, adipisicing elit. Magnam ab fuga, - placeat hic possimus harum tempore voluptatem, id nulla nihil laboriosam - suscipit quis obcaecati beatae blanditiis sint. Suscipit, voluptas officia. -

-

- Very exciting. -

diff --git a/lessons/src/lesson002_unqualified_imports/code.gleam b/lessons/src/lesson002_unqualified_imports/code.gleam new file mode 100644 index 0000000..2708f25 --- /dev/null +++ b/lessons/src/lesson002_unqualified_imports/code.gleam @@ -0,0 +1,10 @@ +// Import the module and one of its functions +import gleam/io.{println} + +pub fn main() { + // Use the function in a qualified fashion + io.println("This is qualified") + + // Or an unqualified fashion + println("This is unqualified") +} diff --git a/lessons/src/lesson002_unqualified_imports/text.html b/lessons/src/lesson002_unqualified_imports/text.html new file mode 100644 index 0000000..8fda45e --- /dev/null +++ b/lessons/src/lesson002_unqualified_imports/text.html @@ -0,0 +1,15 @@ +

+ Normally functions from other modules are used in a qualified fashion, with + the module qualifier before function name. For example, + io.println("Hello!"). +

+

+ It is also possible to specify a list of functions to import from a module in + an unqualified fashion, such as the println function in the code + editor. Because it has been imported like this it can be referred to as just + println. +

+

+ Generally it is best to use qualified imports, as this makes it clear where + the function is defined, making the code easier to read. +

diff --git a/lessons/src/lesson003_type_checking/code.gleam b/lessons/src/lesson003_type_checking/code.gleam new file mode 100644 index 0000000..e068f31 --- /dev/null +++ b/lessons/src/lesson003_type_checking/code.gleam @@ -0,0 +1,7 @@ +import gleam/io + +pub fn main() { + io.println("My lucky number is:") + // io.println(4) + // 👆️ Uncomment this line +} diff --git a/lessons/src/lesson003_type_checking/text.html b/lessons/src/lesson003_type_checking/text.html new file mode 100644 index 0000000..fadfe64 --- /dev/null +++ b/lessons/src/lesson003_type_checking/text.html @@ -0,0 +1,19 @@ +

+ Gleam has a robust static type system that is help you as you write and edit + code, catching mistakes and showing you where to make changes. +

+

+ Uncomment the line io.println(4) and see how a compile time error + is reported as the io.println function only works with strings, + not ints. +

+

+ To fix the code change the code to call the io.debug + function instead, as it will print a value of any type. +

+

+ Gleam has no null, no implicit conversions, no exceptions, and + always performs full type checking. If the code compiles you can be reasonably + confident it does not have any inconsistencies that may cause bugs or + crashes. +

diff --git a/lessons/src/lesson004_ints/code.gleam b/lessons/src/lesson004_ints/code.gleam new file mode 100644 index 0000000..fbead50 --- /dev/null +++ b/lessons/src/lesson004_ints/code.gleam @@ -0,0 +1,16 @@ +import gleam/io + +pub fn main() { + // Int arithmetic + io.debug(1 + 1) + io.debug(5 - 1) + io.debug(5 / 2) + io.debug(3 * 3) + io.debug(5 % 2) + + // Int comparisons + io.debug(2 > 1) + io.debug(2 < 1) + io.debug(2 >= 1) + io.debug(2 <= 1) +} diff --git a/lessons/src/lesson004_ints/text.html b/lessons/src/lesson004_ints/text.html new file mode 100644 index 0000000..f5222ee --- /dev/null +++ b/lessons/src/lesson004_ints/text.html @@ -0,0 +1,2 @@ +

+

-- cgit v1.2.3