Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia println() not printing/inconsistent behavior

This is probably a beginner question, but I could not find anything relevant in the docs or basic tutorials. I am using Julia 1.4.2 (that is the latest stable release), and, as suggested in the docs/tutorials, the Atom editor with Juno. This is on Ubuntu 18.04.

My minimum reproducible example:

function main()
    b = 300000
    println(b)
    println(b, " asdf")
end

main()

seems to sometimes output, as expected,

300000
300000 asdf

but it often outputs only

300000 asdf

The latter "wrong" output seems to occur most often when Julia is stopped, and I click "Run All", which starts Julia and runs the script. What is happening here? I apologize if this is a trivial beginner mistake. Thank you.

like image 453
MindSeeker Avatar asked Jul 13 '20 20:07

MindSeeker


People also ask

How to print the output of the program in Julia?

The most common function to print the output of the program in the console of Julia is print () and println (). To execute this command we just need to press Enter on the keyboard. The main difference is that the println () function adds a new line to the end of the output.

What is the use of printf () in Julia?

Julia also supports printf () function which is used in C language to print output on the console. Julia macro (which is used by prefacing it with the @ sign) provides the Printf package which needs to be imported in order to use. printf () is also used as a formatting tool.

What are the different methods of printing in Julia?

Julia provides many methods of printing output on the screen. The Julia program starts with an interactive REPL (Read/ Evaluate /Print / Loop) as default. It helps in outputting the result of the expression on the screen immediately.

How to print out message in different colors in Julia?

printstyled () function helps in printing out message in different colors. Julia also supports printf () function which is used in C language to print output on the console. Julia macro (which is used by prefacing it with the @ sign) provides the Printf package which needs to be imported in order to use. printf () is also used as a formatting tool.


Video Answer


1 Answers

It looks like you are using the Atom IDE.

Unfortunately Atom Juno from time to time is "eating" the first output line of a Julia script - I have seen it few times.

The workaround that seems to work is to force a flush on the standard output cache:

flush(stdout)

This cleans the cache and enforces the communication between Julia REPL and Atom.

like image 57
Przemyslaw Szufel Avatar answered Oct 18 '22 02:10

Przemyslaw Szufel