-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
880a669
commit b00e0ae
Showing
48 changed files
with
152 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
import gleam/int | ||
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) | ||
echo { 1 + 1 } | ||
echo { 5 - 1 } | ||
echo { 5 / 2 } | ||
echo { 3 * 3 } | ||
echo { 5 % 2 } | ||
|
||
// Int comparisons | ||
io.debug(2 > 1) | ||
io.debug(2 < 1) | ||
io.debug(2 >= 1) | ||
io.debug(2 <= 1) | ||
echo { 2 > 1 } | ||
echo { 2 < 1 } | ||
echo { 2 >= 1 } | ||
echo { 2 <= 1 } | ||
|
||
// Equality works for any type | ||
io.debug(1 == 1) | ||
io.debug(2 == 1) | ||
echo { 1 == 1 } | ||
echo { 2 == 1 } | ||
|
||
// Standard library int functions | ||
io.debug(int.max(42, 77)) | ||
io.debug(int.clamp(5, 10, 20)) | ||
echo int.max(42, 77) | ||
echo int.clamp(5, 10, 20) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
import gleam/float | ||
import gleam/io | ||
|
||
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) | ||
echo { 1.0 +. 1.5 } | ||
echo { 5.0 -. 1.5 } | ||
echo { 5.0 /. 2.5 } | ||
echo { 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) | ||
echo { 2.2 >. 1.3 } | ||
echo { 2.2 <. 1.3 } | ||
echo { 2.2 >=. 1.3 } | ||
echo { 2.2 <=. 1.3 } | ||
|
||
// Equality works for any type | ||
io.debug(1.1 == 1.1) | ||
io.debug(2.1 == 1.2) | ||
echo { 1.1 == 1.1 } | ||
echo { 2.1 == 1.2 } | ||
|
||
// Division by zero is not an error | ||
io.debug(3.14 /. 0.0) | ||
echo { 3.14 /. 0.0 } | ||
|
||
// Standard library float functions | ||
io.debug(float.max(2.0, 9.5)) | ||
io.debug(float.ceiling(5.4)) | ||
echo float.max(2.0, 9.5) | ||
echo float.ceiling(5.4) | ||
} |
16 changes: 7 additions & 9 deletions
16
src/content/chapter0_basics/lesson07_number_formats/code.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import gleam/io | ||
|
||
pub fn main() { | ||
// Underscores | ||
io.debug(1_000_000) | ||
io.debug(10_000.01) | ||
echo 1_000_000 | ||
echo 10_000.01 | ||
|
||
// Binary, octal, and hex Int literals | ||
io.debug(0b00001111) | ||
io.debug(0o17) | ||
io.debug(0xF) | ||
echo 0b00001111 | ||
echo 0o17 | ||
echo 0xF | ||
|
||
// Scientific notation Float literals | ||
io.debug(7.0e7) | ||
io.debug(3.0e-4) | ||
echo 7.0e7 | ||
echo 3.0e-4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import gleam/io | ||
|
||
pub fn main() { | ||
io.debug(100 == 100) | ||
io.debug(1.5 != 0.1) | ||
echo { 100 == 100 } | ||
echo { 1.5 != 0.1 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
import gleam/bool | ||
import gleam/io | ||
|
||
pub fn main() { | ||
// Bool operators | ||
io.debug(True && False) | ||
io.debug(True && True) | ||
io.debug(False || False) | ||
io.debug(False || True) | ||
echo { True && False } | ||
echo { True && True } | ||
echo { False || False } | ||
echo { False || True } | ||
|
||
// Bool functions | ||
io.debug(bool.to_string(True)) | ||
io.debug(bool.to_int(False)) | ||
echo bool.to_string(True) | ||
echo bool.to_int(False) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import gleam/io | ||
|
||
pub fn main() { | ||
let fahrenheit = { | ||
let degrees = 64 | ||
degrees | ||
} | ||
// io.debug(degrees) // <- This will not compile | ||
// echo degrees // <- This will not compile | ||
|
||
// Changing order of evaluation | ||
let celsius = { fahrenheit - 32 } * 5 / 9 | ||
io.debug(celsius) | ||
echo celsius | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import gleam/io | ||
|
||
pub fn main() { | ||
let ints = [1, 2, 3] | ||
|
||
io.debug(ints) | ||
echo ints | ||
|
||
// Immutably prepend | ||
io.debug([-1, 0, ..ints]) | ||
echo [-1, 0, ..ints] | ||
|
||
// Uncomment this to see the error | ||
// io.debug(["zero", ..ints]) | ||
// echo ["zero", ..ints] | ||
|
||
// The original lists are unchanged | ||
io.debug(ints) | ||
echo ints | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
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]) | ||
echo ints | ||
echo { ints == [1, 2, 3] } | ||
|
||
io.debug(floats) | ||
io.debug(floats == [1.0, 2.0, 3.0]) | ||
echo floats | ||
echo { floats == [1.0, 2.0, 3.0] } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import gleam/io | ||
|
||
pub fn main() { | ||
io.debug(double(10)) | ||
echo double(10) | ||
} | ||
|
||
fn double(a: Int) -> Int { | ||
|
6 changes: 2 additions & 4 deletions
6
src/content/chapter1_functions/lesson03_higher_order_functions/code.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
src/content/chapter1_functions/lesson04_anonymous_functions/code.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
src/content/chapter1_functions/lesson05_function_captures/code.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
src/content/chapter1_functions/lesson08_labelled_arguments/code.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.