User/Console Input (read, readline, input)

,

Your first code example works just fine for me (in the Julia REPL on a PC), so either you’re doing something weird that I can’t tell from your post, or there’s an issue with Atom reading from STDIN (i.e. user input in this case). To diagnose what is going on, please tell us how you are running your code:

  1. Are you entering it line by line?
  2. Are you copy-pasting several lines into the REPL at once?
  3. Are you running an external file using include(filename)?

Options 1 and 3 should always work no matter if you are in Julia’s own REPL or in Atom. But 2 can behave differently in Atom compared to Julia’s REPL - in Atom readline() may use the copy-pasted lines as input instead of what you type.

On a side note: I held an introduction to Julia for PhD students some weeks ago, and two of my students also instinctively wrote code that prompted for user input. That’s an extremely old-fashioned way of doing things that goes back to the days of BASIC in the 1960s. The Julian way, or the standard way for modern interactive languages in general, is to write a function that takes a user defined argument and then call that function interactively:

function sayhi(name)
    println("Hi $name, how are you?")
end

And then just call that function with your custom arguments:

julia> sayhi("Kent")
Hi Kent, how are you?

Side note 2: please use triple backticks ``` to include code in your posts in the future, here’s how and why.