Skip to content

Commit

Permalink
add echo
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri committed Nov 21, 2024
1 parent f205e1e commit 9fa6d02
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ import gleam/io
pub fn main() {
io.println("My lucky number is:")
// io.println(4)
// 👆️ Uncomment this line
// 👆️ Uncomment this line to see the error

// echo 4
// 👆️ You can use `echo` to debug print a value of any type!
}
7 changes: 2 additions & 5 deletions src/content/chapter0_basics/lesson04_type_checking/en.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
function only works with strings, not ints.
</p>
<p>
To fix the code change the code to call the
<a href="https://hexdocs.pm/gleam_stdlib/gleam/io.html#debug" target="_blank">
<code>io.debug</code>
</a>
function instead, as it will print a value of any type.
If you need to debug print something you can use the <code>echo</code>
keyword instead, as it will print a value of any type.
</p>
<p>
Gleam has no <code>null</code>, no implicit conversions, no exceptions, and
Expand Down
7 changes: 2 additions & 5 deletions src/content/chapter0_basics/lesson16_blocks/en.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
Any variables assigned within the block can only be used within the block.
</p>
<p>
Try uncommenting
<a href="https://hexdocs.pm/gleam_stdlib/gleam/io.html#debug" target="_blank">
<code>io.debug(degrees)</code>
</a>
to see the compile error from trying to use a variable that is not in scope.
Try uncommenting <code>echo degrees</code> to see the compile error from
trying to use a variable that is not in scope.
</p>
<p>
Blocks can also be used to change the order of evaluation of binary operators
Expand Down
2 changes: 2 additions & 0 deletions src/content/chapter1_functions/lesson07_pipelines/code.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ pub fn main() {
// With the pipe operator
"Hello, Mike!"
|> string.drop_right(1)
|> echo
|> string.drop_left(7)
|> io.println

// Changing order with function capturing
"1"
|> string.append("2")
|> echo
|> string.append("3", _)
|> io.println
}
4 changes: 4 additions & 0 deletions src/content/chapter1_functions/lesson07_pipelines/en.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
position then a function capture can be used to insert the argument to the
desired position.
</p>
<p>
If you need to debug print a value in the middle of a pipeline you can use
<code>|> echo</code> to do it.
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ pub fn main() {

fn handle_fish(fish: Fish) {
case fish {
Starfish(_, favourite_color) -> io.debug(favourite_color)
Jellyfish(name, ..) -> io.debug(name)
Starfish(_, favourite_color) -> io.println(favourite_color)
Jellyfish(name, ..) -> io.println(name)
}
}

fn handle_ice_cream(ice_cream: IceCream) {
// if the custom type has a single variant you can
// destructure it using `let` instead of a case expression!
let IceCream(flavour) = ice_cream
echo flavour
io.println(flavour)
}
7 changes: 2 additions & 5 deletions src/tour.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ const home_html = "
<a href=\"https://hexdocs.pm/gleam_stdlib/gleam/io.html#print\" target=\"_blank\">
<code>io.println</code>
</a>
or
<a href=\"https://hexdocs.pm/gleam_stdlib/gleam/io.html#debug\" target=\"_blank\">
<code>io.debug</code>
</a>
will be shown in the bottom section, along with any compile errors and warnings.
or <code>echo</code> will be shown in the bottom section, along with any compile
errors and warnings.
To evaluate Gleam code the tour compiles Gleam to JavaScript and runs it,
all entirely within your browser window.
</p>
Expand Down

0 comments on commit 9fa6d02

Please sign in to comment.