Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 2.33 KB

io.livemd

File metadata and controls

72 lines (48 loc) · 2.33 KB

IO

Mix.install([
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"},
  {:tested_cell, github: "brooklinjazz/tested_cell"},
  {:utils, path: "#{__DIR__}/../utils"}
])

Navigation

Return Home Report An Issue

Setup

Ensure you type the ea keyboard shortcut to evaluate all Elixir cells before starting. Alternatively you can evaluate the Elixir cells as you read.

IO

When building command line applications, we can use the IO module for retrieving user input and displaying output in the command line.

We've can use IO.inspect/2 and IO.puts/2 for displaying information in the command line.

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 in a Mix project, or 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

Run the following in your command line from the beta_curriculum folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish io section"

Up Next

Previous Next
Mix Games Setup