aboutsummaryrefslogtreecommitdiff
path: root/lessons/src
diff options
context:
space:
mode:
Diffstat (limited to 'lessons/src')
-rw-r--r--lessons/src/lesson035_nil/code.gleam11
-rw-r--r--lessons/src/lesson035_nil/text.html15
-rw-r--r--lessons/src/lesson036_bit_arrays/code.gleam13
-rw-r--r--lessons/src/lesson036_bit_arrays/text.html26
4 files changed, 65 insertions, 0 deletions
diff --git a/lessons/src/lesson035_nil/code.gleam b/lessons/src/lesson035_nil/code.gleam
new file mode 100644
index 0000000..c28080b
--- /dev/null
+++ b/lessons/src/lesson035_nil/code.gleam
@@ -0,0 +1,11 @@
+import gleam/io
+
+pub fn main() {
+ let x = Nil
+ io.debug(x)
+
+ // let y: List(String) = Nil
+
+ let result = io.println("Hello!")
+ io.debug(result == Nil)
+}
diff --git a/lessons/src/lesson035_nil/text.html b/lessons/src/lesson035_nil/text.html
new file mode 100644
index 0000000..3416643
--- /dev/null
+++ b/lessons/src/lesson035_nil/text.html
@@ -0,0 +1,15 @@
+<p>
+ <code>Nil</code> is Gleam's unit type. It is a value that is returned by
+ functions that have nothing else to return, as all functions much return
+ something.
+</p>
+<p>
+ <code>Nil</code> is not a valid value of any other types, that is values in
+ Gleam are not nullable. If the type of a value is <code>Nil</code> then it is
+ the value <code>nil</code>. If it is some other type then the value is not
+ <code>Nil</code>.
+</p>
+<p>
+ Uncomment the line that assigns <code>Nil</code> to a variable with an
+ incompatible type annotation to see the comile time error it produces.
+</p>
diff --git a/lessons/src/lesson036_bit_arrays/code.gleam b/lessons/src/lesson036_bit_arrays/code.gleam
new file mode 100644
index 0000000..dc772ca
--- /dev/null
+++ b/lessons/src/lesson036_bit_arrays/code.gleam
@@ -0,0 +1,13 @@
+import gleam/io
+
+pub fn main() {
+ // 8 bit int. In binary: 00000011
+ io.debug(<<3>>)
+ io.debug(<<3>> == <<3:size(8)>>)
+
+ // 16 bit int. In binary: 0001100000000011
+ io.debug(<<6147:size(16)>>)
+
+ // A bit array of UTF8 data
+ io.debug(<<"Hello, Joe!":utf8>>)
+}
diff --git a/lessons/src/lesson036_bit_arrays/text.html b/lessons/src/lesson036_bit_arrays/text.html
new file mode 100644
index 0000000..3214db1
--- /dev/null
+++ b/lessons/src/lesson036_bit_arrays/text.html
@@ -0,0 +1,26 @@
+<p>
+ Bit arrays represent a sequence of 1s and 0s, and are a convenient syntax for
+ constructing and manipulating binary data.
+</p>
+<p>
+ Each segment of a bit array can be given options to specify the representation
+ used for that segment.
+</p>
+<ul>
+ <li><code>size</code>: the size of the segment in bits.</li>
+ <li><code>unit</code>: how many times to repeat the segment.</li>
+ <li><code>bits</code>: a nested bit array of any size.</li>
+ <li><code>bytes</code>: a nested byte-aligned bit array.</li>
+ <li><code>float</code>: a 64 bits floating point number.</li>
+ <li><code>int</code>: an int with a default size of 8 bits.</li>
+ <li><code>big</code>: big endian.</li>
+ <li><code>little</code>: little endian.</li>
+ <li><code>native</code>: the endianness of the processor.</li>
+ <li><code>utf8</code>: utf8 encoded text.</li>
+ <li><code>utf16</code>: utf16 encoded text.</li>
+ <li><code>utf32</code>: utf32 encoded text.</li>
+</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.
+</p>