Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us
Notesclub

IO

reading/io.livemd

IO

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue StringsBooleans

IO

We can use the IO module for retrieving user input and displaying output.

We can use IO.inspect/2 and IO.puts/2 print displaying information.

We can also use IO.gets/2 to retrieve input from the user.

iex> input = IO.gets("Give me some input: ")
Give me some input: sure!
"sure!\n"
iex> input
"sure!\n"

Keep in mind, this will work when running an Elixir project or in the IEx shell, but will fail with an :enotsup (error not supported) error when we run it from Livebook.

IO.gets("I will fail!")

That’s because there is no command line or other device to retrieve user input from.

Your Turn

Run IO.gets/2 in the command line from the IEx shell and bind the return value to an input variable.

iex> input = IO.gets("Give me some input: ")

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish IO reading"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue StringsBooleans