aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lessons/src/lesson004_ints/code.gleam5
-rw-r--r--lessons/src/lesson004_ints/text.html13
-rw-r--r--lessons/src/lesson005_floats/code.gleam20
-rw-r--r--lessons/src/lesson005_floats/text.html19
-rw-r--r--lessons/src/lesson006_number_formats/code.gleam16
-rw-r--r--lessons/src/lesson006_number_formats/text.html13
-rw-r--r--lessons/src/lesson007_strings/code.gleam17
-rw-r--r--lessons/src/lesson007_strings/text.html22
8 files changed, 125 insertions, 0 deletions
diff --git a/lessons/src/lesson004_ints/code.gleam b/lessons/src/lesson004_ints/code.gleam
index fbead50..5076902 100644
--- a/lessons/src/lesson004_ints/code.gleam
+++ b/lessons/src/lesson004_ints/code.gleam
@@ -1,4 +1,5 @@
import gleam/io
+import gleam/int
pub fn main() {
// Int arithmetic
@@ -13,4 +14,8 @@ pub fn main() {
io.debug(2 < 1)
io.debug(2 >= 1)
io.debug(2 <= 1)
+
+ // Standard library int functions
+ io.debug(int.max(42, 77))
+ io.debug(int.clamp(5, 10, 20))
}
diff --git a/lessons/src/lesson004_ints/text.html b/lessons/src/lesson004_ints/text.html
index f5222ee..32a7aa8 100644
--- a/lessons/src/lesson004_ints/text.html
+++ b/lessons/src/lesson004_ints/text.html
@@ -1,2 +1,15 @@
<p>
+ Gleam's <code>Int</code> type represents whole numbers.
+</p>
+<p>
+ There are arithmetic and comparison operators for ints.
+</p>
+<p>
+ When running on the Erlang virtual machine ints have no maximum and minimum
+ size. When running on JavaScript runtimes ints are represented using
+ JavaScript's 64 bit floating point numbers,
+</p>
+<p>
+ The <a href="https://hexdocs.pm/gleam_stdlib/gleam/int.html"><code>gleam/int</code></a>
+ standard library module contains functions for working with ints.
</p>
diff --git a/lessons/src/lesson005_floats/code.gleam b/lessons/src/lesson005_floats/code.gleam
new file mode 100644
index 0000000..f42c608
--- /dev/null
+++ b/lessons/src/lesson005_floats/code.gleam
@@ -0,0 +1,20 @@
+import gleam/io
+import gleam/float
+
+pub fn main() {
+ // Float arithmetic
+ io.debug(1.0 +. 1.5)
+ io.debug(5.0 -. 1.5)
+ io.debug(5.0 /. 2.5)
+ io.debug(3.0 *. 3.5)
+
+ // Float comparisons
+ io.debug(2.2 >. 1.3)
+ io.debug(2.2 <. 1.3)
+ io.debug(2.2 >=. 1.3)
+ io.debug(2.2 <=. 1.3)
+
+ // Standard library float functions
+ io.debug(float.max(2.0, 9.5))
+ io.debug(float.ceiling(5.4))
+}
diff --git a/lessons/src/lesson005_floats/text.html b/lessons/src/lesson005_floats/text.html
new file mode 100644
index 0000000..497bb13
--- /dev/null
+++ b/lessons/src/lesson005_floats/text.html
@@ -0,0 +1,19 @@
+<p>
+ Gleam's <code>Float</code> type represents numbers that are not integers.
+</p>
+<p>
+ Unlike many languages Gleam does not have a `NaN` or `Infinity` float value.
+</p>
+<p>
+ Gleam's numerical operators are not overloaded, so there are dedictated
+ operators for working with floats.
+</p>
+<p>
+ Floats are represented as 64 bit floating point numbers on both Erlang and
+ JavaScript runtimes.
+</p>
+<p>
+ The <a href="https://hexdocs.pm/gleam_stdlib/gleam/float.html"><code>gleam/float</code></a>
+ standard library module contains functions for working with floats.
+</p>
+
diff --git a/lessons/src/lesson006_number_formats/code.gleam b/lessons/src/lesson006_number_formats/code.gleam
new file mode 100644
index 0000000..7307185
--- /dev/null
+++ b/lessons/src/lesson006_number_formats/code.gleam
@@ -0,0 +1,16 @@
+import gleam/io
+
+pub fn main() {
+ // Underscores
+ io.debug(1_000_000)
+ io.debug(10_000.01)
+
+ // Binary, octal, and hex Int literals
+ io.debug(0b00001111)
+ io.debug(0o17)
+ io.debug(0xF)
+
+ // Scientific notation Float literals
+ io.debug(7.0e7)
+ io.debug(3.0e-4)
+}
diff --git a/lessons/src/lesson006_number_formats/text.html b/lessons/src/lesson006_number_formats/text.html
new file mode 100644
index 0000000..308219a
--- /dev/null
+++ b/lessons/src/lesson006_number_formats/text.html
@@ -0,0 +1,13 @@
+<p>
+ Underscores can be added to numbers for clarity. For example,
+ <code>1000000</code> can be tricky to read quickly, while
+ <code>1_000_000</code> can be easier.
+</p>
+<p>
+ Ints can be written in binary, octal, or hexadecimal formats using the
+ <code>0b</code>, <code>0o</code>, and <code>0x</code> prefixes respectively.
+</p>
+<p>
+ Floats can be written in a scientific notation.
+</p>
+
diff --git a/lessons/src/lesson007_strings/code.gleam b/lessons/src/lesson007_strings/code.gleam
new file mode 100644
index 0000000..c57cf9b
--- /dev/null
+++ b/lessons/src/lesson007_strings/code.gleam
@@ -0,0 +1,17 @@
+import gleam/io
+import gleam/string
+
+pub fn main() {
+ // String literals
+ io.debug("๐Ÿ‘ฉโ€๐Ÿ’ป ใ“ใ‚“ใซใกใฏ Gleam ๐Ÿณ๏ธโ€๐ŸŒˆ")
+ io.debug(
+ "multi
+ line
+ string",
+ )
+ io.debug("\u{1F600}")
+
+ // String functions
+ io.debug(string.reverse("1 2 3 4 5"))
+ io.debug(string.append("abc", "def"))
+}
diff --git a/lessons/src/lesson007_strings/text.html b/lessons/src/lesson007_strings/text.html
new file mode 100644
index 0000000..21cfc12
--- /dev/null
+++ b/lessons/src/lesson007_strings/text.html
@@ -0,0 +1,22 @@
+<p>
+ In Gleam Strings are written as text surrounded by double quotes.
+</p>
+<p>
+ They can span multiple lines and support unicode characters.
+</p>
+<p>
+ Several escape sequences are supported:
+</p>
+<ul>
+ <li><code>\"</code> - double quote</li>
+ <li><code>\\</code> - backslash</li>
+ <li><code>\f</code> - form feed</li>
+ <li><code>\n</code> - newline</li>
+ <li><code>\r</code> - carriage return</li>
+ <li><code>\t</code> - tab</li>
+ <li><code>\u{1F600}</code> - unicode codepoint</li>
+</ul>
+<p>
+ The <a href="https://hexdocs.pm/gleam_stdlib/gleam/string.html"><code>gleam/string</code></a>
+ standard library module contains functions for working with strings.
+</p>