Skip to content

Commit

Permalink
replace io.debug with echo
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri committed Oct 21, 2024
1 parent 880a669 commit b00e0ae
Show file tree
Hide file tree
Showing 48 changed files with 152 additions and 220 deletions.
27 changes: 13 additions & 14 deletions src/content/chapter0_basics/lesson05_ints/code.gleam
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)
}
27 changes: 13 additions & 14 deletions src/content/chapter0_basics/lesson06_floats/code.gleam
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 src/content/chapter0_basics/lesson07_number_formats/code.gleam
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
}
6 changes: 2 additions & 4 deletions src/content/chapter0_basics/lesson08_equality/code.gleam
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 }
}
12 changes: 6 additions & 6 deletions src/content/chapter0_basics/lesson09_strings/code.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import gleam/string

pub fn main() {
// String literals
io.debug("👩‍💻 こんにちは Gleam 🏳️‍🌈")
io.debug(
io.println("👩‍💻 こんにちは Gleam 🏳️‍🌈")
io.println(
"multi
line
string",
)
io.debug("\u{1F600}")
io.println("\u{1F600}")

// Double quote can be escaped
io.println("\"X\" marks the spot")

// String concatenation
io.debug("One " <> "Two")
io.println("One " <> "Two")

// String functions
io.debug(string.reverse("1 2 3 4 5"))
io.debug(string.append("abc", "def"))
io.println(string.reverse("1 2 3 4 5"))
io.println(string.append("abc", "def"))
}
13 changes: 6 additions & 7 deletions src/content/chapter0_basics/lesson10_bools/code.gleam
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)
}
8 changes: 4 additions & 4 deletions src/content/chapter0_basics/lesson11_assignments/code.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import gleam/io

pub fn main() {
let x = "Original"
io.debug(x)
io.println(x)

// Assign `y` to the value of `x`
let y = x
io.debug(y)
io.println(y)

// Assign `x` to a new value
let x = "New"
io.debug(x)
io.println(x)

// The `y` still refers to the original value
io.debug(y)
io.println(y)
}
4 changes: 1 addition & 3 deletions src/content/chapter0_basics/lesson15_type_aliases/code.gleam
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import gleam/io

pub type UserId =
Int

Expand All @@ -8,5 +6,5 @@ pub fn main() {
let two: Int = 2

// UserId and Int are the same type
io.debug(one == two)
echo { one == two }
}
6 changes: 2 additions & 4 deletions src/content/chapter0_basics/lesson16_blocks/code.gleam
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
}
10 changes: 4 additions & 6 deletions src/content/chapter0_basics/lesson17_lists/code.gleam
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
}
10 changes: 4 additions & 6 deletions src/content/chapter0_basics/lesson18_constants/code.gleam
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] }
}
4 changes: 1 addition & 3 deletions src/content/chapter1_functions/lesson00_functions/code.gleam
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import gleam/io

pub fn main() {
// Call a function with another function
io.debug(twice(1, add_one))
echo twice(1, add_one)

// Functions can be assigned to variables
let my_function = add_one
io.debug(my_function(100))
echo my_function(100)
}

fn twice(argument: Int, passed_function: fn(Int) -> Int) -> Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import gleam/io

pub fn main() {
// Assign an anonymous function to a variable
let add_one = fn(a) { a + 1 }
io.debug(twice(1, add_one))
echo twice(1, add_one)

// Pass an anonymous function as an argument
io.debug(twice(1, fn(a) { a * 2 }))
echo twice(1, fn(a) { a * 2 })

let secret_number = 42
// This anonymous function always returns 42
let secret = fn() { secret_number }
io.debug(secret())
echo secret()
}

fn twice(argument: Int, my_function: fn(Int) -> Int) -> Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import gleam/io

pub fn main() {
// These two statements are equivalent
let add_one_v1 = fn(x) { add(1, x) }
let add_one_v2 = add(1, _)

io.debug(add_one_v1(10))
io.debug(add_one_v2(10))
echo add_one_v1(10)
echo add_one_v2(10)
}

fn add(a: Int, b: Int) -> Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import gleam/io

pub fn main() {
let add_one = fn(x) { x + 1 }
let exclaim = fn(x) { x <> "!" }
Expand All @@ -8,10 +6,10 @@ pub fn main() {
// twice(10, exclaim)

// Here the type variable is replaced by the type Int
io.debug(twice(10, add_one))
echo twice(10, add_one)

// Here the type variable is replaced by the type String
io.debug(twice("Hello", exclaim))
echo twice("Hello", exclaim)
}

// The name `value` refers to the same type multiple times
Expand Down
6 changes: 3 additions & 3 deletions src/content/chapter1_functions/lesson07_pipelines/code.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import gleam/string

pub fn main() {
// Without the pipe operator
io.debug(string.drop_left(string.drop_right("Hello, Joe!", 1), 7))
io.println(string.drop_left(string.drop_right("Hello, Joe!", 1), 7))

// With the pipe operator
"Hello, Mike!"
|> string.drop_right(1)
|> string.drop_left(7)
|> io.debug
|> io.println

// Changing order with function capturing
"1"
|> string.append("2")
|> string.append("3", _)
|> io.debug
|> io.println
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import gleam/io

pub fn main() {
// Without using labels
io.debug(calculate(1, 2, 3))
echo calculate(1, 2, 3)

// Using the labels
io.debug(calculate(1, add: 2, multiply: 3))
echo calculate(1, add: 2, multiply: 3)

// Using the labels in a different order
io.debug(calculate(1, multiply: 3, add: 2))
echo calculate(1, multiply: 3, add: 2)
}

fn calculate(value: Int, add addend: Int, multiply multiplier: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import gleam/int
import gleam/io

pub fn main() {
let x = int.random(5)
io.debug(x)
echo x

let result = case x {
// Match specific values
Expand All @@ -13,5 +12,5 @@ pub fn main() {
// Match any other value
_ -> "Other"
}
io.debug(result)
echo result
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import gleam/int
import gleam/io

pub fn main() {
let result = case int.random(5) {
Expand All @@ -10,5 +9,5 @@ pub fn main() {
// Match any other value and assign it to a variable
other -> "It is " <> int.to_string(other)
}
io.debug(result)
echo result
}
Loading

0 comments on commit b00e0ae

Please sign in to comment.