From 2a6ae1fa5408247c95bf4a7d59e5038342a2a125 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Wed, 20 Dec 2023 20:46:44 +0000 Subject: Nil and bit arrays --- lessons/src/lesson035_nil/code.gleam | 11 +++++++++++ lessons/src/lesson035_nil/text.html | 15 +++++++++++++++ lessons/src/lesson036_bit_arrays/code.gleam | 13 +++++++++++++ lessons/src/lesson036_bit_arrays/text.html | 26 ++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 lessons/src/lesson035_nil/code.gleam create mode 100644 lessons/src/lesson035_nil/text.html create mode 100644 lessons/src/lesson036_bit_arrays/code.gleam create mode 100644 lessons/src/lesson036_bit_arrays/text.html (limited to 'lessons/src') 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 @@ +

+ Nil 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. +

+

+ Nil is not a valid value of any other types, that is values in + Gleam are not nullable. If the type of a value is Nil then it is + the value nil. If it is some other type then the value is not + Nil. +

+

+ Uncomment the line that assigns Nil to a variable with an + incompatible type annotation to see the comile time error it produces. +

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 @@ +

+ Bit arrays represent a sequence of 1s and 0s, and are a convenient syntax for + constructing and manipulating binary data. +

+

+ Each segment of a bit array can be given options to specify the representation + used for that segment. +

+ +

+ Bit arrays have limited support when compiling to JavaScript, not all options + can be used. Full bit array support will be implemented in future. +

-- cgit v1.2.3